More cleanup, fix mistranslated field breaking head yaw for players

This commit is contained in:
fullwall 2013-07-03 14:21:30 +08:00
parent 9c4b0f41d2
commit a064a28aab
3 changed files with 29 additions and 52 deletions

View File

@ -1,7 +1,6 @@
package net.citizensnpcs.trait;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.Map;
import net.citizensnpcs.Settings.Setting;
@ -227,16 +226,9 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
}
public class GroundController implements MovementController {
private int jumpTicks;
private int jumpTicks = 0;
private double speed = 0.07D;
private void jump() {
boolean allowed = getHandle().onGround;
if (!allowed)
return;
getHandle().motY = JUMP_VELOCITY;
}
@Override
public void leftClick(PlayerInteractEvent event) {
}
@ -280,18 +272,10 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
newSpeed = 0.35D;
}
boolean shouldJump = false;
try {
if (JUMP_FIELD != null)
shouldJump = JUMP_FIELD.getBoolean(handle.passenger);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
boolean shouldJump = NMS.shouldJump(handle.passenger);
if (shouldJump) {
if (handle.onGround && jumpTicks == 0) {
jump();
getHandle().motY = JUMP_VELOCITY;
jumpTicks = 10;
}
} else {
@ -323,7 +307,6 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
private static final Map<EntityType, Class<? extends MovementController>> controllerTypes = Maps
.newEnumMap(EntityType.class);
private static final Field JUMP_FIELD = NMS.getField(EntityLiving.class, "bd");
static {
controllerTypes.put(EntityType.BAT, AirController.class);

View File

@ -107,7 +107,7 @@ public class NMS {
List<?> list = (List<?>) NMS.GOAL_FIELD.get(selector);
list.clear();
} catch (Exception e) {
Messaging.logTr(Messages.ERROR_CLEARING_GOALS, e.getMessage());
Messaging.logTr(Messages.ERROR_CLEARING_GOALS, e.getLocalizedMessage());
}
}
}
@ -130,7 +130,7 @@ public class NMS {
f = clazz.getDeclaredField(field);
f.setAccessible(true);
} catch (Exception e) {
Messaging.logTr(Messages.ERROR_GETTING_FIELD, field, e.getMessage());
Messaging.logTr(Messages.ERROR_GETTING_FIELD, field, e.getLocalizedMessage());
}
return f;
}
@ -140,7 +140,7 @@ public class NMS {
}
public static float getHeadYaw(EntityLiving handle) {
return handle.aA;
return handle.aP;
}
public static float getSpeedFor(NPC npc) {
@ -300,6 +300,19 @@ public class NMS {
}
}
public static boolean shouldJump(net.minecraft.server.v1_6_R1.Entity entity) {
if (JUMP_FIELD == null || !(entity instanceof EntityLiving))
return false;
try {
return JUMP_FIELD.getBoolean(entity);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return false;
}
public static org.bukkit.entity.Entity spawnCustomEntity(org.bukkit.World world, Location at,
Class<? extends Entity> clazz, EntityType type) {
World handle = ((CraftWorld) world).getHandle();
@ -381,44 +394,25 @@ public class NMS {
}
private static final float DEFAULT_SPEED = 1F;
private static Map<Class<?>, Integer> ENTITY_CLASS_TO_INT;
private static final Map<Class<?>, Constructor<?>> ENTITY_CONSTRUCTOR_CACHE = new WeakHashMap<Class<?>, Constructor<?>>();
private static Map<Integer, Class<?>> ENTITY_INT_TO_CLASS;
private static Field GOAL_FIELD;
private static Field LAND_SPEED_MODIFIER_FIELD;
private static Field GOAL_FIELD = getField(PathfinderGoalSelector.class, "a");
private static final Field JUMP_FIELD = getField(EntityLiving.class, "bd");
private static Field LAND_SPEED_MODIFIER_FIELD = getField(EntityLiving.class, "bs");
private static final Map<EntityType, Float> MOVEMENT_SPEEDS = Maps.newEnumMap(EntityType.class);
private static Field NAVIGATION_WORLD_FIELD;
private static Field NAVIGATION_WORLD_FIELD = getField(Navigation.class, "b");
private static final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0);
private static Field PATHFINDING_RANGE;
private static Field PATHFINDING_RANGE = getField(Navigation.class, "d");
private static final Random RANDOM = Util.getFastRandom();
private static Field SPEED_FIELD;
private static Field THREAD_STOPPER;
private static Field SPEED_FIELD = getField(EntityLiving.class, "bI");
private static Field THREAD_STOPPER = getField(NetworkManager.class, "n");
// true field above false and three synchronised lists
static {
// TODO: speed fields are all wrong - need to use attributes
// true field above false and three synchronised lists
THREAD_STOPPER = getField(NetworkManager.class, "n");
// constants taken from source code
MOVEMENT_SPEEDS.put(EntityType.CHICKEN, 1F);
MOVEMENT_SPEEDS.put(EntityType.COW, 1F);
MOVEMENT_SPEEDS.put(EntityType.CREEPER, 1F);
MOVEMENT_SPEEDS.put(EntityType.IRON_GOLEM, 1F);
MOVEMENT_SPEEDS.put(EntityType.MUSHROOM_COW, 1F);
MOVEMENT_SPEEDS.put(EntityType.OCELOT, 1F);
MOVEMENT_SPEEDS.put(EntityType.SHEEP, 1F);
MOVEMENT_SPEEDS.put(EntityType.SNOWMAN, 1F);
MOVEMENT_SPEEDS.put(EntityType.PIG, 1F);
MOVEMENT_SPEEDS.put(EntityType.PLAYER, 1F);
MOVEMENT_SPEEDS.put(EntityType.VILLAGER, 1F);
LAND_SPEED_MODIFIER_FIELD = getField(EntityLiving.class, "bs");
SPEED_FIELD = getField(EntityLiving.class, "bI");
NAVIGATION_WORLD_FIELD = getField(Navigation.class, "b");
PATHFINDING_RANGE = getField(Navigation.class, "d");
GOAL_FIELD = getField(PathfinderGoalSelector.class, "a");
try {
Field field = getField(EntityTypes.class, "d");
ENTITY_INT_TO_CLASS = (Map<Integer, Class<?>>) field.get(null);

View File

@ -182,7 +182,7 @@ citizens.limits.over-npc-limt=Over the NPC limit of {0}.
citizens.load-task-error=NPC load task couldn''t be scheduled, disabling...
citizens.nms-errors.clearing-goals=Could not clear goals: {0}.
citizens.nms-errors.error-setting-persistent=Could not set NPC as persistent: {0}. NPC entity may despawn.
citizens.nms-errors.getting-field=Could not fetch field {0}: {1}.
citizens.nms-errors.getting-field=Could not fetch NMS field {0}: {1}.
citizens.nms-errors.getting-id-mapping=Could not fetch entity id mapping fields: {0}.
citizens.nms-errors.spawning-custom-entity=Could not spawn custom entity: {0}.
citizens.nms-errors.stopping-network-threads=Could not stop network threads: {0}.