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.

Featured Replies

Posted

The way I write my item/block registry is in an array so I can cycle through and register them without using triple the amount of code.

 

It works perfectly fine in 1.7.10 but in 1.8 it crashes at this line:

public void registerItemRenderer()
{
        Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0,                    // <----- This line
			new ModelResourceLocation(CC.MODID + ":" + item.getUnlocalizedName()));
}

with a NullPointerException.

 

This is my registry method:

public static void register()
{
	CC.logger.entry("Registering items...");
	for (int i = 0; i < items.length; i++)
	{
		GameRegistry.registerItem(items[i], items[i].getUnlocalizedName());
		registerItemRenderer(items[i]);

		CC.logger.info("-----> Registered " + items[i].getUnlocalizedName());
		if (items[i].getCreativeTab() == null)
		{
			CC.logger.error("No creative tab is set for " + items[i].getUnlocalizedName() + ". Fix it.");
		}
	}
	CC.logger.entry("Registering blocks...");
	for (int i = 0; i < blocks.length; i++)
	{
		GameRegistry.registerBlock(blocks[i], blocks[i].getUnlocalizedName());
		registerBlockRenderer(blocks[i]);

		CC.logger.info("-----> Registered " + blocks[i].getUnlocalizedName());
		if (blocks[i].getCreativeTabToDisplayOn() == null)
		{
			CC.logger.error("No creative tab is set for " + blocks[i].getUnlocalizedName() + ". Fix it.");
		}
	}
}

 

All my jsons are correct and in the right places and the items/blocks are absolutely registered.

So why does it successfully register everything to the GameRegistry but give a NullPointerException on the renderers?

You're almost certainly calling the mesher at the wrong time/place. It is client-only and not available during pre-init, so put it in client proxy's init method.

 

As a general rule, everything pertaining to graphic and sound rendering is client-only.

 

Also, many null-pointer errors come from misplaced calls (trying to use something before it exists, or trying to use something from a pointer that was initialized before the object existed). Whenever asking for help with a null-pointer, always provide the stack trace inside a code or spoiler element in your OP, and always include enough source code that all relevant fields' initializations can be seen.

 

Finally, search for problems like your own before posting. The site's own search produces haystacks, so try Google or your own favorite to search from outside. You'll find many examples of mesher null-pointers and d7's advice.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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.