makeo / Gadomancy

An ad-on for Thaumcraft
GNU Lesser General Public License v3.0
16 stars 29 forks source link

Null pointer exception during tooltip handling with NEI, Sanguimancy, and Gadomancy #74

Closed theJ8910 closed 7 years ago

theJ8910 commented 7 years ago

To reproduce: Minecraft 1.7.10 Gadomancy 1.0.7.2 Sanguimancy 1.1.9-35 NEI 1.0.5.120

I've spent the better part of a day tracking down the origin of this mysterious error spamming my console:

[15:00:50] [NEI Item Filtering/ERROR]: Exception caught during firing event net.minecraftforge.event.entity.player.ItemTooltipEvent@1a760016:
java.lang.NullPointerException
        at cpw.mods.fml.common.registry.GameRegistry$UniqueIdentifier.<init>(GameRegistry.java:389) ~[GameRegistry$UniqueIdentifier.class:?]
        at cpw.mods.fml.common.registry.GameData.getUniqueName(GameData.java:239) ~[GameData.class:?]
        at cpw.mods.fml.common.registry.GameRegistry.findUniqueIdentifierFor(GameRegistry.java:462) ~[GameRegistry.class:?]
        at tombenpotter.sanguimancy.util.EventHandler$ClientEventHandler.onSanguimancyItemTooltip(EventHandler.java:402) ~[EventHandler$ClientEventHandler.class:1.7.10-1.1.9-35]
        at cpw.mods.fml.common.eventhandler.ASMEventHandler_1928_ClientEventHandler_onSanguimancyItemTooltip_ItemTooltipEvent.invoke(.dynamic) ~[?:?]
        at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54) ~[ASMEventHandler.class:?]
        at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:140) [EventBus.class:?]
        at net.minecraftforge.event.ForgeEventFactory.onItemTooltip(ForgeEventFactory.java:169) [ForgeEventFactory.class:?]
        at net.minecraft.item.ItemStack.func_82840_a(ItemStack.java:626) [add.class:?]
        at codechicken.nei.guihook.GuiContainerManager.itemDisplayNameMultiline(GuiContainerManager.java:119) [GuiContainerManager.class:?]
        at codechicken.nei.guihook.GuiContainerManager.concatenatedDisplayName(GuiContainerManager.java:162) [GuiContainerManager.class:?]
        at codechicken.nei.api.ItemInfo.getSearchName(ItemInfo.java:529) [ItemInfo.class:?]
        at codechicken.nei.ItemList$PatternItemFilter.matches(ItemList.java:65) [ItemList$PatternItemFilter.class:?]
        at codechicken.nei.ItemList$AnyMultiItemFilter.matches(ItemList.java:110) [ItemList$AnyMultiItemFilter.class:?]
        at codechicken.nei.ItemList$AllMultiItemFilter.matches(ItemList.java:85) [ItemList$AllMultiItemFilter.class:?]
        at codechicken.nei.ItemList$2.execute(ItemList.java:239) [ItemList$2.class:?]
        at codechicken.nei.RestartableTask$1.run(RestartableTask.java:24) [RestartableTask$1.class:?]

After much debugging I've found the cause.

ItemFakeGolemShield#getSubItems() calls ItemFakeGolemPlacer#getSubItems(). You pass item (an ItemFakeGolemShield instance) to it, expecting the method to add ItemFakeGolemShield ItemStacks to list.

However, in ItemFakeGolemPlacer's getSubItems(), you use the this instead of item to create the ItemStacks. In other words, the ItemStacks being added to the list are ItemFakeGolemPlacer, not ItemFakeGolemShield.

When you first join a world, NEI goes through the list of registered items, generating a large list of ItemStacks, calling getSubItems() on Items that have several permutations like ItemFakeGolemShield. When you type something into NEI's search box, it goes through the list of ItemStacks it generated previously and generates a tooltip for each one to match against the filter you typed. This invokes tooltip handlers registered by other mods as well.

Sanguimancy has a tooltip handler that calls GameRegistry.findUniqueIdentifierFor(stack.getItem()) to get the item ID for the stack whose tooltip is being generated. When it does this on the incorrect ItemStacks created by ItemFakeGolemShield#getSubItems(), this causes a null pointer exception in FML because it isn't able to locate ItemFakeGolemPlacer in the item registry.

Wait, what? This doesn't make any sense. ItemFakeGolemPlacer is registered in RegisteredItems.java, so why is it saying it's not? It turns out it's because the ItemFakeGolemPlacer instance you register with Forge is a different instance from the one you create in ItemFakeGolemShield! Even though they're both ItemFakeGolemPlacer, because they're different instances, so they're seen as different Items entirely.

HellFirePvP commented 7 years ago

Now that would explain multiple issues... Thank you very much for pointing that out with great detail.

@makeoo golems were your thing :V

theJ8910 commented 7 years ago

By the way, how do I build your mod? I downloaded the source and made some changes to it, and threw in a few jars on the build path to satisfy the missing dependencies, but I'm still getting compile errors like this:

G:\The Repository\projects\third-party\Gadomancy\build\sources\java\makeo\gadomancy\common\blocks\tiles\TileEssentiaCompressor.java:136: error: cannot find symbol
                te.setInventorySlotContents(0, null);
                  ^
  symbol:   method setInventorySlotContents(int,<null>)
  location: variable te of type TilePedestal

...

G:\The Repository\projects\third-party\Gadomancy\build\sources\java\makeo\gadomancy\client\renderers\tile\RenderTileCapEldritch.java:30: error: abstract method renderTileEntityAt(TileEntity,double,double,double,float) in TileEntitySpecia
lRenderer cannot be accessed directly
            super.renderTileEntityAt(te, x, y, z, f);
                 ^

I made a lib/ folder and put Baubles-1.7.10-1.0.1.10.jar, mystcraft-1.7.10-0.12.3.03.jar, Thaumcraft-1.7.10-4.2.3.5.jar, thaumichorizons-1.7.10-1.1.9.jar, and Waila-1.5.10_1.7.10.jar in it. Most of the errors seem to be coming from Thaumcraft dependencies though.

HellFirePvP commented 7 years ago

you need to add the deobf version of Thaumcraft 4.2.3.5 to your dev environment, not the obfuscated one.

theJ8910 commented 7 years ago

Got it, thanks for the heads up.

makeo commented 7 years ago

I could not stop myself from laughing after reading the error description :D. I never expected someone to actually dig that deep into our source good job (but there are more abyssal part within gadomancy :D)! I'll talk to hellfire if he already resolved that issue or not but don't expect me to be fast