Jump to content

[1.7.10] Icon registry NullPointerException when inheriting from BlockOldLeaf


Elyon

Recommended Posts

I have a barebones descendant of

BlockOldLeaf

. As with my descendant of

BlockFurnace

, I have left the icon registry (and much everything else) up to the parent class.

 

This does not work for

BlockOldLeaf

, however.

 

While the block works well within the game world, as soon as I try rendering it as an item (by opening the Decorations Creative tab or "picking" the leaves), the game crashes from a

NullPointerException

:

 

BlockChocolateOldLeaf.java

package net.elyon.chocolate;

import net.minecraft.block.BlockOldLeaf;

public class BlockChocolateOldLeaf extends BlockOldLeaf {
public BlockChocolateOldLeaf() {
	super();
}
}

 

Relevant stacktrace

[07:53:09] [Client thread/FATAL]: Reported exception thrown!

net.minecraft.util.ReportedException: Rendering item

at net.minecraft.client.renderer.entity.RenderItem.renderItemAndEffectIntoGUI(RenderItem.java:624) ~[RenderItem.class:?]

at net.minecraft.client.gui.GuiIngame.renderInventorySlot(GuiIngame.java:973) ~[GuiIngame.class:?]

at net.minecraftforge.client.GuiIngameForge.renderHotbar(GuiIngameForge.java:209) ~[GuiIngameForge.class:?]

at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:144) ~[GuiIngameForge.class:?]

at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1122) ~[EntityRenderer.class:?]

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1066) ~[Minecraft.class:?]

at net.minecraft.client.Minecraft.run(Minecraft.java:961) [Minecraft.class:?]

at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_60]

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_60]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_60]

at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_60]

at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) [launchwrapper-1.9.jar:?]

at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.9.jar:?]

Caused by: java.lang.NullPointerException

at net.minecraft.block.BlockOldLeaf.getIcon(BlockOldLeaf.java:68) ~[blockOldLeaf.class:?]

at net.minecraft.item.ItemLeaves.getIconFromDamage(ItemLeaves.java:51) ~[itemLeaves.class:?]

at net.minecraft.item.Item.getIconIndex(Item.java:457) ~[item.class:?]

at net.minecraft.item.ItemStack.getIconIndex(ItemStack.java:134) ~[itemStack.class:?]

at net.minecraft.client.renderer.entity.RenderItem.renderItemIntoGUI(RenderItem.java:420) ~[RenderItem.class:?]

at net.minecraft.client.renderer.entity.RenderItem.renderItemAndEffectIntoGUI(RenderItem.java:585) ~[RenderItem.class:?]

 

Digging through BlockOldLeaf.java, specifically the

getIcon

method, I see it relies on the static field

field_150130_N

, which is declared and initialised in the same class.

 

I cannot figure out why my barebones BlockOldLeaf replacement throws a

NullReferenceException

in the

getIcon

method.

Link to comment
Share on other sites

I replace

Blocks.leaves

through reflection.

 

When simply registering the block through the

GameRegistry

, it works - I guess there is an issue with the way I reflect, then?

 

The very same approach worked for the furnace, though, so I don't know. I initialise the new block statically in my main mod class, but perhaps the

registerBlockIcons

method of

BlockOldLeaf

is called after the replacement has taken place?

 

This still doesn't explain why it would work with the furnace ... but they are very different blocks indeed.

Link to comment
Share on other sites

Going off that, I would assume that something is going wrong with your reflection yes... Could you please post all the relevant code? My Magical Code Viewing Device (or MCVD) is kinda broken permanently. Sorry.

 

:P

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

After quickly browsing your code... I can only think of one thing that could be causing problems. Are you registering the block with a special ItemBlock class? (Is that even needed?? Could be worth looking into).

 

That's all I got, sorry.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

Maybe if you copied all the chained methods that the leaves block uses normally? (the ones used when Minecraft first registers it in the Block class?) I am not sure if you have already done so, but it could be worth a try.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

I did that. This is my new initialisation:

 

public static Block chocolateOldLeafBlock = new BlockChocolateOldLeaf().setBlockName("leaves").setBlockTextureName("minecraft:leaves");

 

Thank you for the input, though :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.