mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 19:15:11 +00:00
Added a declared field reflection cache, improving render times for NPC models that have many fields.
This commit is contained in:
1 parent
cb143be559
commit
f504424fd2
2 files changed
+31
-11
No files matched your search
@@ -14,6 +14,7 @@ import noppes.npcs.constants.EnumAnimationPart;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -24,10 +25,12 @@ public class ClientEventHandler {
|
||||
public static float partialHandTicks;
|
||||
|
||||
public static float partialRenderTick;
|
||||
public static RendererLivingEntity renderer;
|
||||
|
||||
public static EntityNPCInterface renderingNpc;
|
||||
public static EntityPlayer renderingPlayer;
|
||||
public static HashMap<EnumAnimationPart,String[]> partNames = new HashMap<>();
|
||||
public static RendererLivingEntity renderer;
|
||||
public static HashMap<Class<?>,Field[]> declaredFieldCache = new HashMap<>();
|
||||
|
||||
@SubscribeEvent
|
||||
public void onMouse(MouseEvent event) {
|
||||
|
||||
@@ -258,15 +258,26 @@ public abstract class MixinModelRenderer {
|
||||
|
||||
try {
|
||||
Class<?> ModelBipedBody = Class.forName("JinRyuu.JRMCore.entity.ModelBipedBody");
|
||||
Object m = renderer.baseModel;
|
||||
Set<Map.Entry<EnumAnimationPart,String[]>> entrySet = ClientEventHandler.partNames.entrySet();
|
||||
for (Map.Entry<EnumAnimationPart,String[]> entry : entrySet) {
|
||||
for (String s : entry.getValue()) {
|
||||
try {
|
||||
if (renderer == ModelBipedBody.getField(s).get(m)) {
|
||||
return entry.getKey();
|
||||
}
|
||||
} catch (NoSuchFieldException | SecurityException | IllegalAccessException ignored) {}
|
||||
Object model = renderer.baseModel;
|
||||
Field[] declared;
|
||||
if (ClientEventHandler.declaredFieldCache.containsKey(ModelBipedBody)) {
|
||||
declared = ClientEventHandler.declaredFieldCache.get(ModelBipedBody);
|
||||
} else {
|
||||
declared = ModelBipedBody.getDeclaredFields();
|
||||
ClientEventHandler.declaredFieldCache.put(ModelBipedBody,declared);
|
||||
}
|
||||
Set<Map.Entry<EnumAnimationPart, String[]>> entrySet = ClientEventHandler.partNames.entrySet();
|
||||
for (Field f : declared) {
|
||||
f.setAccessible(true);
|
||||
for (Map.Entry<EnumAnimationPart, String[]> entry : entrySet) {
|
||||
String[] names = entry.getValue();
|
||||
for (String partName : names) {
|
||||
try {
|
||||
if (partName.equals(f.getName()) && renderer == f.get(model)) {
|
||||
return entry.getKey();
|
||||
}
|
||||
} catch (IllegalAccessException ignored) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException ignored) {}
|
||||
@@ -314,7 +325,13 @@ public abstract class MixinModelRenderer {
|
||||
|
||||
Set<Map.Entry<EnumAnimationPart, String[]>> entrySet = ClientEventHandler.partNames.entrySet();
|
||||
while (RenderClass != Object.class) {
|
||||
Field[] declared = RenderClass.getDeclaredFields();
|
||||
Field[] declared;
|
||||
if (ClientEventHandler.declaredFieldCache.containsKey(RenderClass)) {
|
||||
declared = ClientEventHandler.declaredFieldCache.get(RenderClass);
|
||||
} else {
|
||||
declared = RenderClass.getDeclaredFields();
|
||||
ClientEventHandler.declaredFieldCache.put(RenderClass,declared);
|
||||
}
|
||||
for (Field f : declared) {
|
||||
f.setAccessible(true);
|
||||
for (Map.Entry<EnumAnimationPart, String[]> entry : entrySet) {
|
||||
|
||||
Reference in new issue
Block a user