mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-27 13:15:33 +01:00
Set speed modifier
This commit is contained in:
parent
4a2106d354
commit
efc6b8375c
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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();
|
||||||
|
@ -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();
|
||||||
|
@ -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();
|
||||||
|
@ -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
|
||||||
|
@ -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();
|
||||||
|
Loading…
Reference in New Issue
Block a user