Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements and additions #1

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea/
*.iml
*.iml
/src/main/resources/rebel.xml
out/
9 changes: 9 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
checkout:
post:
- mvn clean
- mvn package
- cp -R ./target/actaeon-1.0-SNAPSHOT.jar $CIRCLE_ARTIFACTS

machine:
java:
version: oraclejdk8
13 changes: 10 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

<groupId>me.onebone</groupId>
<artifactId>actaeon</artifactId>
<version>1.0</version>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<repositories>
<repository>
<id>regularbox</id>
<url>http://ci.regularbox.com/plugin/repository/everything/</url>
<id>nukkitx-repo</id>
<url>http://repo.nukkitx.com/main/</url>
</repository>
</repositories>

Expand All @@ -29,6 +29,13 @@
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.2</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
119 changes: 72 additions & 47 deletions src/main/java/me/onebone/actaeon/Actaeon.java
Original file line number Diff line number Diff line change
@@ -1,64 +1,89 @@
package me.onebone.actaeon;

import cn.nukkit.block.Block;
import cn.nukkit.entity.Entity;
import cn.nukkit.event.EventHandler;
import cn.nukkit.event.Listener;
import cn.nukkit.event.player.PlayerInteractEvent;
import cn.nukkit.item.Item;
import cn.nukkit.level.Location;
import cn.nukkit.level.Position;
import cn.nukkit.level.format.FullChunk;
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.nbt.tag.DoubleTag;
import cn.nukkit.nbt.tag.FloatTag;
import cn.nukkit.nbt.tag.ListTag;
import cn.nukkit.plugin.PluginBase;
import me.onebone.actaeon.entity.MovingEntity;
import me.onebone.actaeon.entity.animal.Chicken;
import me.onebone.actaeon.entity.animal.Cow;
import me.onebone.actaeon.entity.animal.Pig;
import me.onebone.actaeon.entity.animal.Sheep;
import me.onebone.actaeon.entity.animal.*;
import me.onebone.actaeon.entity.monster.Zombie;
import me.onebone.actaeon.runnable.TaskWatchDog;
import me.onebone.actaeon.task.SpawnTask;

public class Actaeon extends PluginBase implements Listener{
public class Actaeon extends PluginBase {

private static Actaeon instance;
private static Actaeon instance;

public static Actaeon getInstance() {
return instance;
}
public static Actaeon getInstance() {
return instance;
}

@Override
public void onLoad() {
if (instance == null) instance = this;
}
@Override
public void onLoad() {
if (instance == null) instance = this;
}

public void onEnable(){
this.saveDefaultConfig();
public void onEnable() {
this.saveDefaultConfig();

this.registerEntity("Sheep", Sheep.class);
this.registerEntity("Cow", Cow.class);
this.registerEntity("Chicken", Chicken.class);
this.registerEntity("Pig", Pig.class);
this.registerEntity("Zombie", Zombie.class);
new TaskWatchDog().start();

Item.addCreativeItem(Item.get(Item.SPAWN_EGG, Zombie.NETWORK_ID));
this.registerEntity("Sheep", Sheep.class);
this.registerEntity("Cow", Cow.class);
this.registerEntity("Chicken", Chicken.class);
this.registerEntity("Pig", Pig.class);
this.registerEntity("Zombie", Zombie.class);
this.registerEntity("Wolf", Wolf.class);

Item.addCreativeItem(Item.get(Item.SPAWN_EGG, 10));
Item.addCreativeItem(Item.get(Item.SPAWN_EGG, 11));
Item.addCreativeItem(Item.get(Item.SPAWN_EGG, 12));
Item.addCreativeItem(Item.get(Item.SPAWN_EGG, 13));
Item.addCreativeItem(Item.get(Item.SPAWN_EGG, 14));
Item.addCreativeItem(Item.get(Item.SPAWN_EGG, 18));
Item.addCreativeItem(Item.get(Item.SPAWN_EGG, 22));
Item.addCreativeItem(Item.get(Item.SPAWN_EGG, 23));
Item.addCreativeItem(Item.get(Item.SPAWN_EGG, 24));
Item.addCreativeItem(Item.get(Item.SPAWN_EGG, 25));
Item.addCreativeItem(Item.get(Item.SPAWN_EGG, 28));
//this.getServer().getPluginManager().registerEvents(this, this);
}
/*Item.addCreativeItem(Item.get(Item.SPAWN_EGG, Zombie.NETWORK_ID));
Item.addCreativeItem(Item.get(Item.SPAWN_EGG, 10));
Item.addCreativeItem(Item.get(Item.SPAWN_EGG, 11));
Item.addCreativeItem(Item.get(Item.SPAWN_EGG, 12));
Item.addCreativeItem(Item.get(Item.SPAWN_EGG, 13));
Item.addCreativeItem(Item.get(Item.SPAWN_EGG, 14));
Item.addCreativeItem(Item.get(Item.SPAWN_EGG, 18));
Item.addCreativeItem(Item.get(Item.SPAWN_EGG, 22));
Item.addCreativeItem(Item.get(Item.SPAWN_EGG, 23));
Item.addCreativeItem(Item.get(Item.SPAWN_EGG, 24));
Item.addCreativeItem(Item.get(Item.SPAWN_EGG, 25));
Item.addCreativeItem(Item.get(Item.SPAWN_EGG, 28));*/

private void registerEntity(String name, Class<? extends MovingEntity> clazz){
Entity.registerEntity(name, clazz, true);
}
int tick = getConfig().getInt("spawn-tick");

@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Block block = event.getBlock();
event.getPlayer().sendMessage("XYZ=" + block.getX() + "," + block.getY() + "," + block.getZ() + " ID=" + block.getId() + " META=" + block.getDamage());
}
if (tick > 0) {
this.getServer().getScheduler().scheduleDelayedRepeatingTask(this, new SpawnTask(this), tick, tick);
}
}

private void registerEntity(String name, Class<? extends MovingEntity> clazz) {
Entity.registerEntity(name, clazz, true);
}

/**
* @param type
* @param source
* @param args
* @return
*/
public static Entity create(Object type, Position source, Object... args) {
FullChunk chunk = source.getLevel().getChunk((int) source.x >> 4, (int) source.z >> 4, true);
if (!chunk.isGenerated()) {
chunk.setGenerated();
}
if (!chunk.isPopulated()) {
chunk.setPopulated();
}

CompoundTag nbt = new CompoundTag().putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("", source.x)).add(new DoubleTag("", source.y)).add(new DoubleTag("", source.z)))
.putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("", 0)).add(new DoubleTag("", 0)).add(new DoubleTag("", 0)))
.putList(new ListTag<FloatTag>("Rotation").add(new FloatTag("", source instanceof Location ? (float) ((Location) source).yaw : 0))
.add(new FloatTag("", source instanceof Location ? (float) ((Location) source).pitch : 0)));

return Entity.createEntity(type.toString(), chunk, nbt, args);
}
}
2 changes: 1 addition & 1 deletion src/main/java/me/onebone/actaeon/entity/Climbable.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.onebone.actaeon.entity;

public interface Climbable{
public interface Climbable {
}
129 changes: 129 additions & 0 deletions src/main/java/me/onebone/actaeon/entity/EntityAgeable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package me.onebone.actaeon.entity;

import cn.nukkit.entity.Entity;
import cn.nukkit.entity.data.FloatEntityData;
import cn.nukkit.level.format.FullChunk;
import cn.nukkit.nbt.tag.CompoundTag;
import me.onebone.actaeon.Actaeon;

/**
* @author CreeperFace
*/
public abstract class EntityAgeable extends MovingEntity implements cn.nukkit.entity.EntityAgeable {

protected int growingAge;
protected int forcedAge;
protected int forcedAgeTimer;

public EntityAgeable(FullChunk chunk, CompoundTag nbt) {
super(chunk, nbt);

this.setGrowingAge(namedTag.getInt("Age"));
this.forcedAge = namedTag.getInt("ForcedAge");
}

@Override
public boolean entityBaseTick(int tickDiff) {
boolean hasUpdate = super.entityBaseTick(tickDiff);

int growingAge = this.getGrowingAge();

if (growingAge < 0) {
this.setGrowingAge(++growingAge);

if (growingAge == 0) {
this.onGrowingAdult();
}
} else if (growingAge > 0) {
--growingAge;
this.setGrowingAge(growingAge);
}

return hasUpdate;
}

@Override
public boolean isBaby() {
return getDataFlag(DATA_FLAGS, DATA_FLAG_BABY);
}

public int getGrowingAge() {
return this.growingAge;
}

public void ageUp(int amount, boolean forceAge) {
int growingAge = this.getGrowingAge();
int oldAge = growingAge;
growingAge = growingAge + amount * 20;

if (growingAge > 0) {
growingAge = 0;

if (oldAge < 0) {
this.onGrowingAdult();
}
}

int diff = growingAge - oldAge;
this.setGrowingAge(growingAge);

if (forceAge) {
this.forcedAge += diff;

if (this.forcedAgeTimer == 0) {
this.forcedAgeTimer = 40;
}
}

if (this.getGrowingAge() == 0) {
this.setGrowingAge(this.forcedAge);
}
}

public void addGrowth(int growth) {
this.ageUp(growth, false);
}

public void setGrowingAge(int age) {
this.setDataFlag(DATA_FLAGS, DATA_FLAG_BABY, age < 0);
this.growingAge = age;
this.updateScale(age);
}

protected void onGrowingAdult() {
}

public void updateScale(int age) {
float scale = 1;

if (age < 0) {
scale = Math.max(0.5f, (float) ((age + 24000)) / 24000);
}

this.setDataProperty(new FloatEntityData(DATA_SCALE, scale));
}

public EntityAgeable createBaby(EntityAgeable mother) {
Entity baby = Actaeon.create(getNetworkId(), this);
return baby instanceof EntityAgeable ? (EntityAgeable) baby : null;
}

@Override
public void saveNBT() {
super.saveNBT();

this.namedTag.putInt("Age", getGrowingAge());
this.namedTag.putInt("ForcedAge", forcedAge);
}

@Override
public float getMovementSpeed() {
float speed = super.getMovementSpeed();

if (this.isBaby()) {
speed /= 0.5f;
}

return speed;
}
}
Loading