From b89734f3e6e60e275c84cf57e1df15db060f7c85 Mon Sep 17 00:00:00 2001 From: NealDeal34 <130116696+NealDeal34@users.noreply.github.com> Date: Tue, 30 Dec 2025 03:19:36 +0800 Subject: [PATCH] Added checks for abstract classes when retrieving entities --- .../java/codechicken/nei/ItemMobSpawner.java | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/src/main/java/codechicken/nei/ItemMobSpawner.java b/src/main/java/codechicken/nei/ItemMobSpawner.java index 4b5433c3..e124201b 100644 --- a/src/main/java/codechicken/nei/ItemMobSpawner.java +++ b/src/main/java/codechicken/nei/ItemMobSpawner.java @@ -4,6 +4,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.lang.reflect.Modifier; + import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; @@ -81,24 +83,36 @@ public class ItemMobSpawner extends ItemBlock { + IDtoNameMap.get(meta)); } - public static EntityLiving getEntity(int ID) { - EntityLiving e = entityHashMap.get(ID); - if (e == null) { - loadSpawners(); - Class clazz = EntityList.IDtoClassMapping.get(ID); - World world = NEIClientUtils.mc().theWorld; - try { - e = (EntityLiving) clazz.getConstructor(new Class[] { World.class }).newInstance(world); - } catch (Throwable t) { - if (clazz == null) - NEIClientConfig.logger.error("Null class for entity (" + ID + ", " + IDtoNameMap.get(ID)); - else NEIClientConfig.logger.error("Error creating instance of entity: " + clazz.getName(), t); +public static EntityLiving getEntity(int ID) { + EntityLiving e = entityHashMap.get(ID); + if (e == null) { + loadSpawners(); + Class clazz = EntityList.IDtoClassMapping.get(ID); + World world = NEIClientUtils.mc().theWorld; + if (clazz != null) { + int modifiers = clazz.getModifiers(); + if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers)) { + NEIClientConfig.logger.warn("Skipping abstract entity class: " + clazz.getName()); e = getEntity(idPig); + if (e != null) { + entityHashMap.put(ID, e); + } + return e; } - entityHashMap.put(ID, e); } - return e; + + try { + e = (EntityLiving) clazz.getConstructor(new Class[] { World.class }).newInstance(world); + } catch (Throwable t) { + if (clazz == null) + NEIClientConfig.logger.error("Null class for entity (" + ID + ", " + IDtoNameMap.get(ID)); + else NEIClientConfig.logger.error("Error creating instance of entity: " + clazz.getName(), t); + e = getEntity(idPig); + } + entityHashMap.put(ID, e); } + return e; +} public static void clearEntityReferences() { entityHashMap.clear();