Set speed modifier

This commit is contained in:
fullwall 2013-12-24 18:55:01 +08:00
parent 4a2106d354
commit efc6b8375c
8 changed files with 33 additions and 3 deletions

View File

@ -1,6 +1,7 @@
package net.citizensnpcs.npc; package net.citizensnpcs.npc;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.util.NMS;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -8,6 +9,13 @@ import org.bukkit.entity.Entity;
public abstract class AbstractEntityController implements EntityController { public abstract class AbstractEntityController implements EntityController {
private Entity bukkitEntity; private Entity bukkitEntity;
public AbstractEntityController() {
}
public AbstractEntityController(Class<?> clazz) {
NMS.registerEntityClass(clazz);
}
protected abstract Entity createEntity(Location at, NPC npc); protected abstract Entity createEntity(Location at, NPC npc);
@Override @Override

View File

@ -4,7 +4,6 @@ import java.lang.reflect.Constructor;
import java.util.Map; import java.util.Map;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.util.NMS;
import net.minecraft.server.v1_7_R1.World; import net.minecraft.server.v1_7_R1.World;
import org.bukkit.Location; import org.bukkit.Location;
@ -18,8 +17,8 @@ public abstract class MobEntityController extends AbstractEntityController {
private final Constructor<?> constructor; private final Constructor<?> constructor;
protected MobEntityController(Class<?> clazz) { protected MobEntityController(Class<?> clazz) {
super(clazz);
this.constructor = getConstructor(clazz); this.constructor = getConstructor(clazz);
NMS.registerEntityClass(clazz);
} }
@Override @Override

View File

@ -107,8 +107,10 @@ public class CitizensNavigator implements Navigator, Runnable {
} }
public void onSpawn() { public void onSpawn() {
if (defaultParams.baseSpeed() == UNINITIALISED_SPEED) if (defaultParams.baseSpeed() == UNINITIALISED_SPEED) {
defaultParams.baseSpeed(NMS.getSpeedFor(npc)); defaultParams.baseSpeed(NMS.getSpeedFor(npc));
}
NMS.setSpeed(npc.getEntity(), defaultParams.speedModifier());
updatePathfindingRange(); updatePathfindingRange();
} }

View File

@ -19,6 +19,10 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class HumanController extends AbstractEntityController { public class HumanController extends AbstractEntityController {
public HumanController() {
super();
}
@Override @Override
protected Entity createEntity(final Location at, final NPC npc) { protected Entity createEntity(final Location at, final NPC npc) {
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); WorldServer ws = ((CraftWorld) at.getWorld()).getHandle();

View File

@ -21,6 +21,10 @@ import org.bukkit.entity.Entity;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
public class EggController extends AbstractEntityController { public class EggController extends AbstractEntityController {
public EggController() {
super(EntityEggNPC.class);
}
@Override @Override
protected Entity createEntity(Location at, NPC npc) { protected Entity createEntity(Location at, NPC npc) {
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); WorldServer ws = ((CraftWorld) at.getWorld()).getHandle();

View File

@ -25,6 +25,10 @@ import org.bukkit.entity.FallingBlock;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
public class FallingBlockController extends AbstractEntityController { public class FallingBlockController extends AbstractEntityController {
public FallingBlockController() {
super(EntityFallingBlockNPC.class);
}
@Override @Override
protected Entity createEntity(Location at, NPC npc) { protected Entity createEntity(Location at, NPC npc) {
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); WorldServer ws = ((CraftWorld) at.getWorld()).getHandle();

View File

@ -26,6 +26,7 @@ import org.bukkit.util.Vector;
public class ItemController extends AbstractEntityController { public class ItemController extends AbstractEntityController {
public ItemController() { public ItemController() {
super(EntityItemNPC.class);
} }
@Override @Override

View File

@ -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) { public static void setStepHeight(EntityLiving entity, float height) {
entity.X = height; entity.X = height;
} }
@ -505,6 +512,7 @@ public class NMS {
private static Field NETWORK_ADDRESS = getField(NetworkManager.class, "l"); private static Field NETWORK_ADDRESS = getField(NetworkManager.class, "l");
private static Field NETWORK_CHANNEL = getField(NetworkManager.class, "k"); private static Field NETWORK_CHANNEL = getField(NetworkManager.class, "k");
private static final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0); private static final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0);
private static Field PATHFINDING_RANGE = getField(Navigation.class, "e"); private static Field PATHFINDING_RANGE = getField(Navigation.class, "e");
private static final Random RANDOM = Util.getFastRandom(); private static final Random RANDOM = Util.getFastRandom();