forked from Chicken-Bones/NotEnoughItems
-
Notifications
You must be signed in to change notification settings - Fork 105
Added checks for abstract classes when retrieving entities #833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NealDeal34
wants to merge
6
commits into
GTNewHorizons:master
Choose a base branch
from
NealDeal34:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
|
please usе |
Justxs
reviewed
Jan 6, 2026
| } | ||
| } | ||
|
|
||
| public static EntityLiving getEntity(int ID) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could reduce nesting for this method to improve code readability
public static EntityLiving getEntity(int ID) {
EntityLiving cached = entityHashMap.get(ID);
if (cached != null) {
return cached;
}
loadSpawners();
Class<?> clazz = (Class<?>) EntityList.IDtoClassMapping.get(ID);
World world = NEIClientUtils.mc() != null ? NEIClientUtils.mc().theWorld : null;
if (isInvalidEntityClass(clazz)) {
return cacheFallback(ID);
}
EntityLiving entity = createEntityInstance(clazz, world, ID);
if (entity != null) {
entityHashMap.put(ID, entity);
}
return entity;
}
private static boolean isInvalidEntityClass(Class<?> clazz) {
if (clazz == null) {
return false;
}
int modifiers = clazz.getModifiers();
if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers)) {
NEIClientConfig.logger.warn(
"Skipping abstract entity class: " + clazz.getName()
);
return true;
}
return false;
}
private static EntityLiving createEntityInstance(Class<?> clazz, World world, int id) {
if (clazz == null || world == null) {
return getEntity(idPig);
}
try {
return (EntityLiving) clazz
.getConstructor(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
);
}
return getEntity(idPig);
}
}
private static EntityLiving cacheFallback(int id) {
EntityLiving fallback = getEntity(idPig);
if (fallback != null) {
entityHashMap.put(id, fallback);
}
return fallback;
}
Member
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Try to fixes persistent java.lang.InstantiationExceptionerrors in the console when mods like BetterQuesting and Hardcore Questing Mode attempt to retrieve spawn egg entity information through NEI.
The following error in logs:
[Client thread/ERROR]: Error creating instance of entity: net.minecraft.entity.EntityLiving
java.lang.InstantiationException
at java.base/jdk.internal.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48) ~[?:?]
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502) ~[?:?]
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486) ~[?:?]
at Launch//codechicken.nei.ItemMobSpawner.getEntity(ItemMobSpawner.java:91) ~[ItemMobSpawner.class:?]
at Launch//codechicken.nei.ItemMobSpawner.func_77624_a(ItemMobSpawner.java:78) ~[ItemMobSpawner.class:?]
at Launch//net.minecraft.item.ItemStack.func_82840_a(ItemStack.java:525) ~[add.class:?]
at Launch//betterquesting.api2.client.gui.panels.content.PanelItemSlot.setStoredValue(PanelItemSlot.java:82) ~[PanelItemSlot.class:?]
at Launch//betterquesting.api2.client.gui.panels.content.PanelItemSlot.setStoredValue(PanelItemSlot.java:24) ~[PanelItemSlot.class:?]
at Launch//betterquesting.api2.client.gui.controls.PanelButtonStorage.(PanelButtonStorage.java:13) ~[PanelButtonStorage.class:?]
at Launch//betterquesting.api2.client.gui.panels.content.PanelItemSlot.(PanelItemSlot.java:45) ~[PanelItemSlot.class:?]
at Launch//betterquesting.api2.client.gui.panels.content.PanelItemSlot.(PanelItemSlot.java:40) ~[PanelItemSlot.class:?]
at Launch//betterquesting.api2.client.gui.panels.content.PanelItemSlot.(PanelItemSlot.java:32) ~[PanelItemSlot.class:?]
at Launch//betterquesting.api2.client.gui.panels.lists.CanvasItemDatabase.addResult(CanvasItemDatabase.java:112) ~[CanvasItemDatabase.class:?]
at Launch//betterquesting.api2.client.gui.panels.lists.CanvasItemDatabase.addResult(CanvasItemDatabase.java:22) ~[CanvasItemDatabase.class:?]
at Launch//betterquesting.api2.client.gui.panels.lists.CanvasSearch.updateResults(CanvasSearch.java:94) ~[CanvasSearch.class:?]
at Launch//betterquesting.api2.client.gui.panels.lists.CanvasSearch.drawPanel(CanvasSearch.java:45) ~[CanvasSearch.class:?]
at Launch//betterquesting.api2.client.gui.panels.CanvasEmpty.drawPanel(CanvasEmpty.java:52) ~[CanvasEmpty.class:?]
at Launch//betterquesting.api2.client.gui.panels.CanvasEmpty.drawPanel(CanvasEmpty.java:52) ~[CanvasEmpty.class:?]
at Launch//betterquesting.api2.client.gui.panels.CanvasTextured.drawPanel(CanvasTextured.java:26) ~[CanvasTextured.class:?]
at Launch//betterquesting.api2.client.gui.GuiScreenCanvas.drawPanel(GuiScreenCanvas.java:271) ~[GuiScreenCanvas.class:?]
at Launch//betterquesting.api2.client.gui.GuiScreenCanvas.func_73863_a(GuiScreenCanvas.java:190) ~[GuiScreenCanvas.class:?]
at Launch//net.minecraft.client.renderer.EntityRenderer.func_78480_b(EntityRenderer.java:1061) ~[blt.class:?]
at Launch//net.minecraft.client.Minecraft.func_71411_J(Minecraft.java:1001) ~[bao.class:?]
at Launch//net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:7505) ~[bao.class:?]
at Launch//net.minecraft.client.main.Main.main(SourceFile:148) ~[MercuryLanding.jar:?]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[?:?]
at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[?:?]
at System//net.minecraft.launchwrapper.Launch.rfb$realLaunch(Launch.java:250) ~[lwjgl3ify-3.0.0-beta.7-forgePatches.jar:?]
at System//net.minecraft.launchwrapper.Launch.launch(Launch.java:35) ~[lwjgl3ify-3.0.0-beta.7-forgePatches.jar:?]
at System//net.minecraft.launchwrapper.Launch.main(Launch.java:60) ~[lwjgl3ify-3.0.0-beta.7-forgePatches.jar:?]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[?:?]
at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[?:?]
at com.gtnewhorizons.retrofuturabootstrap.Main.main(Main.java:207) ~[lwjgl3ify-3.0.0-beta.7-forgePatches.jar:?]
at com.gtnewhorizons.retrofuturabootstrap.MainStartOnFirstThread.lambda$main$1(MainStartOnFirstThread.java:41) ~[lwjgl3ify-3.0.0-beta.7-forgePatches.jar:?]
at java.base/java.lang.Thread.run(Thread.java:1583) [?:?]
[01:28:00] [Client thread/ERROR]: Error creating instance of entity: net.minecraft.entity.monster.EntityMob
java.lang.InstantiationException
at java.base/jdk.internal.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48) ~[?:?]
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502) ~[?:?]
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486) ~[?:?]
at Launch//codechicken.nei.ItemMobSpawner.getEntity(ItemMobSpawner.java:91) ~[ItemMobSpawner.class:?]
at Launch//codechicken.nei.ItemMobSpawner.func_77624_a(ItemMobSpawner.java:78) ~[ItemMobSpawner.class:?]
at Launch//net.minecraft.item.ItemStack.func_82840_a(ItemStack.java:525) ~[add.class:?]
at Launch//betterquesting.api2.client.gui.panels.content.PanelItemSlot.setStoredValue(PanelItemSlot.java:82) ~[PanelItemSlot.class:?]
at Launch//betterquesting.api2.client.gui.panels.content.PanelItemSlot.setStoredValue(PanelItemSlot.java:24) ~[PanelItemSlot.class:?]
at Launch//betterquesting.api2.client.gui.controls.PanelButtonStorage.(PanelButtonStorage.java:13) ~[PanelButtonStorage.class:?]
at Launch//betterquesting.api2.client.gui.panels.content.PanelItemSlot.(PanelItemSlot.java:45) ~[PanelItemSlot.class:?]
at Launch//betterquesting.api2.client.gui.panels.content.PanelItemSlot.(PanelItemSlot.java:40) ~[PanelItemSlot.class:?]
at Launch//betterquesting.api2.client.gui.panels.content.PanelItemSlot.(PanelItemSlot.java:32) ~[PanelItemSlot.class:?]
at Launch//betterquesting.api2.client.gui.panels.lists.CanvasItemDatabase.addResult(CanvasItemDatabase.java:112) ~[CanvasItemDatabase.class:?]
at Launch//betterquesting.api2.client.gui.panels.lists.CanvasItemDatabase.addResult(CanvasItemDatabase.java:22) ~[CanvasItemDatabase.class:?]
at Launch//betterquesting.api2.client.gui.panels.lists.CanvasSearch.updateResults(CanvasSearch.java:94) ~[CanvasSearch.class:?]
at Launch//betterquesting.api2.client.gui.panels.lists.CanvasSearch.drawPanel(CanvasSearch.java:45) ~[CanvasSearch.class:?]
at Launch//betterquesting.api2.client.gui.panels.CanvasEmpty.drawPanel(CanvasEmpty.java:52) ~[CanvasEmpty.class:?]
at Launch//betterquesting.api2.client.gui.panels.CanvasEmpty.drawPanel(CanvasEmpty.java:52) ~[CanvasEmpty.class:?]
at Launch//betterquesting.api2.client.gui.panels.CanvasTextured.drawPanel(CanvasTextured.java:26) ~[CanvasTextured.class:?]
at Launch//betterquesting.api2.client.gui.GuiScreenCanvas.drawPanel(GuiScreenCanvas.java:271) ~[GuiScreenCanvas.class:?]
at Launch//betterquesting.api2.client.gui.GuiScreenCanvas.func_73863_a(GuiScreenCanvas.java:190) ~[GuiScreenCanvas.class:?]
at Launch//net.minecraft.client.renderer.EntityRenderer.func_78480_b(EntityRenderer.java:1061) ~[blt.class:?]
at Launch//net.minecraft.client.Minecraft.func_71411_J(Minecraft.java:1001) ~[bao.class:?]
at Launch//net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:7505) ~[bao.class:?]
at Launch//net.minecraft.client.main.Main.main(SourceFile:148) ~[MercuryLanding.jar:?]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[?:?]
at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[?:?]
at System//net.minecraft.launchwrapper.Launch.rfb$realLaunch(Launch.java:250) ~[lwjgl3ify-3.0.0-beta.7-forgePatches.jar:?]
at System//net.minecraft.launchwrapper.Launch.launch(Launch.java:35) ~[lwjgl3ify-3.0.0-beta.7-forgePatches.jar:?]
at System//net.minecraft.launchwrapper.Launch.main(Launch.java:60) ~[lwjgl3ify-3.0.0-beta.7-forgePatches.jar:?]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[?:?]
at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[?:?]
at com.gtnewhorizons.retrofuturabootstrap.Main.main(Main.java:207) ~[lwjgl3ify-3.0.0-beta.7-forgePatches.jar:?]
at com.gtnewhorizons.retrofuturabootstrap.MainStartOnFirstThread.lambda$main$1(MainStartOnFirstThread.java:41) ~[lwjgl3ify-3.0.0-beta.7-forgePatches.jar:?]
at java.base/java.lang.Thread.run(Thread.java:1583) [?:?]