Fix for change in EntityTypes fields

This commit is contained in:
fullwall 2018-09-26 18:57:34 +08:00
parent 1dc0edd7b0
commit d9a0481a7e
2 changed files with 23 additions and 5 deletions

View File

@ -66,6 +66,10 @@ public class NMS {
}
public static Field getField(Class<?> clazz, String field) {
return getField(clazz, field, true);
}
public static Field getField(Class<?> clazz, String field, boolean log) {
if (clazz == null)
return null;
Field f = null;
@ -73,20 +77,28 @@ public class NMS {
f = clazz.getDeclaredField(field);
f.setAccessible(true);
} catch (Exception e) {
if (log) {
Messaging.logTr(Messages.ERROR_GETTING_FIELD, field, e.getLocalizedMessage());
}
}
return f;
}
public static Field getFinalField(Class<?> clazz, String field) {
Field f = getField(clazz, field);
return getFinalField(clazz, field, true);
}
public static Field getFinalField(Class<?> clazz, String field, boolean log) {
Field f = getField(clazz, field, log);
if (f == null) {
return null;
}
try {
MODIFIERS_FIELD.setInt(f, f.getModifiers() & ~Modifier.FINAL);
} catch (Exception e) {
if (log) {
Messaging.logTr(Messages.ERROR_GETTING_FIELD, field, e.getLocalizedMessage());
}
return null;
}
return f;

View File

@ -1017,7 +1017,10 @@ public class NMSImpl implements NMSBridge {
public void shutdown() {
if (ENTITY_REGISTRY == null)
return;
Field field = NMS.getFinalField(EntityTypes.class, "REGISTRY");
Field field = NMS.getFinalField(EntityTypes.class, "REGISTRY", false);
if (field == null) {
field = NMS.getFinalField(IRegistry.class, "ENTITY_TYPE");
}
try {
field.set(null, ENTITY_REGISTRY.getWrapped());
} catch (Exception e) {
@ -1592,7 +1595,10 @@ public class NMSImpl implements NMSBridge {
static {
try {
Field field = NMS.getFinalField(EntityTypes.class, "REGISTRY");
Field field = NMS.getFinalField(EntityTypes.class, "REGISTRY", false);
if (field == null) {
field = NMS.getFinalField(IRegistry.class, "ENTITY_TYPE");
}
ENTITY_REGISTRY = new CustomEntityRegistry((RegistryMaterials<EntityTypes<?>>) field.get(null));
field.set(null, ENTITY_REGISTRY);
} catch (Exception e) {