Skip to content

Commit

Permalink
Try to use backing MC id-mapping - may help with MCPC/Forge
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Aug 5, 2013
1 parent fd21956 commit 8906ca3
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/net/citizensnpcs/util/NMS.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ private static Constructor<?> getCustomEntityConstructor(Class<?> clazz, EntityT
}

public static Field getField(Class<?> clazz, String field) {
if (clazz == null)
return null;
Field f = null;
try {
f = clazz.getDeclaredField(field);
Expand Down Expand Up @@ -216,6 +218,10 @@ public static void openHorseScreen(Horse horse, Player equipper) {
}

public static void registerEntityClass(Class<?> clazz) {
if (ENTITY_CLASS_TO_INT == null) {
ENTITY_CLASS_TO_INT = MC_ENTITY_CLASS_TO_INT;
ENTITY_INT_TO_CLASS = MC_ENTITY_INT_TO_CLASS;
}
if (ENTITY_CLASS_TO_INT == null || ENTITY_CLASS_TO_INT.containsKey(clazz))
return;
Class<?> search = clazz;
Expand Down Expand Up @@ -426,9 +432,13 @@ public static void updatePathfindingRange(NPC npc, float pathfindingRange) {
}

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 Map<Class<?>, Integer> MC_ENTITY_CLASS_TO_INT = null;
private static Map<Integer, Class<?>> MC_ENTITY_INT_TO_CLASS = null;
private static Field GOAL_FIELD = getField(PathfinderGoalSelector.class, "a");
private static final Field JUMP_FIELD = getField(EntityLiving.class, "bd");
private static Field NAVIGATION_WORLD_FIELD = getField(Navigation.class, "b");
Expand All @@ -447,6 +457,13 @@ public static void updatePathfindingRange(NPC npc, float pathfindingRange) {
ENTITY_CLASS_TO_INT = (Map<Class<?>, Integer>) field.get(null);
} catch (Exception e) {
Messaging.logTr(Messages.ERROR_GETTING_ID_MAPPING, e.getMessage());
try {
Field field = getField(Class.forName("ns"), "d");
MC_ENTITY_INT_TO_CLASS = (Map<Integer, Class<?>>) field.get(null);
field = getField(Class.forName("ns"), "e");
MC_ENTITY_CLASS_TO_INT = (Map<Class<?>, Integer>) field.get(null);
} catch (Exception e2) {
}
}
}
}

0 comments on commit 8906ca3

Please sign in to comment.