Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[1.7.10] Icon registry NullPointerException when inheriting from BlockOldLeaf

Featured Replies

Posted

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.

I am having a hard time replicating your problem. Is there anything else that you can tell us that may lead us to your problem?

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

  • Author

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.

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.

  • Author

This should be the mod code in its entirety.

 

BlockReplaceHelper

(using

ReflectionHelper

) is what I am currently doing to replace

Blocks.leaves

.

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.

  • Author

I am not registering the block, just replacing the vanilla block.

 

I figure I need to call

setBlockTextureName("minecraft:leaves")

, but doing so yields exactly the same result.

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.

  • Author

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 :)

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.