diff --git a/src/main/java/net/citizensnpcs/npc/AbstractEntityController.java b/src/main/java/net/citizensnpcs/npc/AbstractEntityController.java index 1962a5971..62113e5aa 100644 --- a/src/main/java/net/citizensnpcs/npc/AbstractEntityController.java +++ b/src/main/java/net/citizensnpcs/npc/AbstractEntityController.java @@ -1,6 +1,7 @@ package net.citizensnpcs.npc; import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.util.NMS; import org.bukkit.Location; import org.bukkit.entity.Entity; @@ -8,6 +9,13 @@ import org.bukkit.entity.Entity; public abstract class AbstractEntityController implements EntityController { private Entity bukkitEntity; + public AbstractEntityController() { + } + + public AbstractEntityController(Class clazz) { + NMS.registerEntityClass(clazz); + } + protected abstract Entity createEntity(Location at, NPC npc); @Override diff --git a/src/main/java/net/citizensnpcs/npc/MobEntityController.java b/src/main/java/net/citizensnpcs/npc/MobEntityController.java index f6a2b0df7..3b34da68e 100644 --- a/src/main/java/net/citizensnpcs/npc/MobEntityController.java +++ b/src/main/java/net/citizensnpcs/npc/MobEntityController.java @@ -4,7 +4,6 @@ import java.lang.reflect.Constructor; import java.util.Map; import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.util.NMS; import net.minecraft.server.v1_7_R1.World; import org.bukkit.Location; @@ -18,8 +17,8 @@ public abstract class MobEntityController extends AbstractEntityController { private final Constructor constructor; protected MobEntityController(Class clazz) { + super(clazz); this.constructor = getConstructor(clazz); - NMS.registerEntityClass(clazz); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java index c4cc6921b..5ae295b11 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java +++ b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java @@ -107,8 +107,10 @@ public class CitizensNavigator implements Navigator, Runnable { } public void onSpawn() { - if (defaultParams.baseSpeed() == UNINITIALISED_SPEED) + if (defaultParams.baseSpeed() == UNINITIALISED_SPEED) { defaultParams.baseSpeed(NMS.getSpeedFor(npc)); + } + NMS.setSpeed(npc.getEntity(), defaultParams.speedModifier()); updatePathfindingRange(); } diff --git a/src/main/java/net/citizensnpcs/npc/entity/HumanController.java b/src/main/java/net/citizensnpcs/npc/entity/HumanController.java index 8642a4299..6d38ced5a 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/HumanController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/HumanController.java @@ -19,6 +19,10 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; public class HumanController extends AbstractEntityController { + public HumanController() { + super(); + } + @Override protected Entity createEntity(final Location at, final NPC npc) { WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/nonliving/EggController.java b/src/main/java/net/citizensnpcs/npc/entity/nonliving/EggController.java index 09503ac8d..8a7fdb984 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/nonliving/EggController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/nonliving/EggController.java @@ -21,6 +21,10 @@ import org.bukkit.entity.Entity; import org.bukkit.util.Vector; public class EggController extends AbstractEntityController { + public EggController() { + super(EntityEggNPC.class); + } + @Override protected Entity createEntity(Location at, NPC npc) { WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/nonliving/FallingBlockController.java b/src/main/java/net/citizensnpcs/npc/entity/nonliving/FallingBlockController.java index 07ce17cdb..1f6ed928c 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/nonliving/FallingBlockController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/nonliving/FallingBlockController.java @@ -25,6 +25,10 @@ import org.bukkit.entity.FallingBlock; import org.bukkit.util.Vector; public class FallingBlockController extends AbstractEntityController { + public FallingBlockController() { + super(EntityFallingBlockNPC.class); + } + @Override protected Entity createEntity(Location at, NPC npc) { WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/nonliving/ItemController.java b/src/main/java/net/citizensnpcs/npc/entity/nonliving/ItemController.java index bfb52fd1d..4fb8555aa 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/nonliving/ItemController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/nonliving/ItemController.java @@ -26,6 +26,7 @@ import org.bukkit.util.Vector; public class ItemController extends AbstractEntityController { public ItemController() { + super(EntityItemNPC.class); } @Override diff --git a/src/main/java/net/citizensnpcs/util/NMS.java b/src/main/java/net/citizensnpcs/util/NMS.java index 295eed014..1beff34e0 100644 --- a/src/main/java/net/citizensnpcs/util/NMS.java +++ b/src/main/java/net/citizensnpcs/util/NMS.java @@ -381,6 +381,13 @@ public class NMS { } } + public static void setSpeed(org.bukkit.entity.Entity entity, float speedModifier) { + if (!(entity instanceof LivingEntity)) + return; + EntityLiving handle = NMS.getHandle((LivingEntity) entity); + handle.getAttributeInstance(GenericAttributes.d).setValue(speedModifier); + } + public static void setStepHeight(EntityLiving entity, float height) { entity.X = height; } @@ -505,6 +512,7 @@ public class NMS { private static Field NETWORK_ADDRESS = getField(NetworkManager.class, "l"); private static Field NETWORK_CHANNEL = getField(NetworkManager.class, "k"); private static final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0); + private static Field PATHFINDING_RANGE = getField(Navigation.class, "e"); private static final Random RANDOM = Util.getFastRandom();