Compare commits

...
Author SHA1 Message Date
Martin Robertz 4ecac151f5 Merge remote-tracking branch 'NealDeal34/master' into dev 2026-01-02 09:00:15 +01:00
Martin Robertz d6d50a968d sa 2026-01-02 08:59:20 +01:00
NealDeal34 43459d4b41 Update ItemMobSpawner.java 2025-12-30 15:57:58 +08:00
NealDeal34 9b84ea7804 Update ItemMobSpawner.java 2025-12-30 15:32:57 +08:00
NealDeal34 de42a43b2c update 2025-12-30 03:50:49 +08:00
NealDeal34 b89734f3e6 Added checks for abstract classes when retrieving entities 2025-12-30 03:19:36 +08:00
@@ -1,5 +1,6 @@
package codechicken.nei;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -76,26 +77,49 @@ public class ItemMobSpawner extends ItemBlock {
meta = idPig;
}
Entity e = getEntity(meta);
list.add(
(e instanceof IMob ? EnumChatFormatting.DARK_RED : EnumChatFormatting.DARK_AQUA)
+ IDtoNameMap.get(meta));
if (e != null) {
list.add(
(e instanceof IMob ? EnumChatFormatting.DARK_RED : EnumChatFormatting.DARK_AQUA)
+ 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;
Class<?> clazz = (Class<?>) EntityList.IDtoClassMapping.get(ID);
World world = NEIClientUtils.mc() != null ? NEIClientUtils.mc().theWorld : null;
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;
}
}
try {
e = (EntityLiving) clazz.getConstructor(new Class[] { World.class }).newInstance(world);
if (clazz != null && world != null) {
e = (EntityLiving) clazz.getConstructor(new Class[] { World.class }).newInstance(world);
} else {
e = getEntity(idPig);
}
} catch (Throwable t) {
if (clazz == null)
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);
} else {
NEIClientConfig.logger.error("Error creating instance of entity: " + clazz.getName(), t);
}
e = getEntity(idPig);
}
entityHashMap.put(ID, e);
if (e != null) {
entityHashMap.put(ID, e);
}
}
return e;
}
@@ -111,12 +135,13 @@ public class ItemMobSpawner extends ItemBlock {
public static void loadSpawners() {
if (loaded) return;
loaded = true;
for (Map.Entry<Class<? extends Entity>, String> entry : EntityList.classToStringMapping.entrySet()) {
final Class<? extends Entity> clazz = entry.getKey();
for (Object entry : EntityList.classToStringMapping.entrySet()) {
Map.Entry<Class<? extends Entity>, String> mapEntry = (Map.Entry<Class<? extends Entity>, String>) entry;
final Class<? extends Entity> clazz = mapEntry.getKey();
if (EntityLiving.class.isAssignableFrom(clazz)) {
Integer id = (Integer) EntityList.classToIDMapping.get(clazz);
if (id == null) continue;
String name = entry.getValue();
String name = mapEntry.getValue();
if (name == null) continue;
if (name.equals("EnderDragon")) continue;
if (name.equals("Pig")) idPig = id;