Ms_Raven Posted November 29, 2015 Posted November 29, 2015 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? Quote
jeffryfisher Posted November 30, 2015 Posted November 30, 2015 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. Quote 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.
Recommended Posts
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.