1

I'm trying to render a block with a custom model in my 1.9 mod but it gives me a error at .getItemModelMesher

Code:

public class ModBlocks extends Blocks {
    public static Block wooden_table;
    public static void init() {
        // Create Block
        wooden_table = new Block(Material.wood).setUnlocalizedName("wooden_table").setCreativeTab(CreativeTabs.tabMisc);
        // Register
        GameRegistry.registerBlock(wooden_table, wooden_table.getUnlocalizedName().substring(5));
    }
    public static void registerRenders() {
        registerRender(wooden_table);
    }
    public static void registerRender(Block block) {
        Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), 0,
                new ModelResourceLocation(
                        Main.MODID + ":" + Item.getItemFromBlock(block).getUnlocalizedName().substring(5),
                        "inventory"));
    }
}

Crash report:

---- Minecraft Crash Report ----
Description: Initializing game

java.lang.NullPointerException: Initializing game
    at mcrafterzzfurnituremod.blocks.ModBlocks.registerRender(ModBlocks.java:29)
    at mcrafterzzfurnituremod.blocks.ModBlocks.registerRenders(ModBlocks.java:25)

Please help I can't find any solution for this problem. If you need more code then just ask.

MCrafterzz
  • 51
  • 1
  • 7
  • thanks Pokechu22 wanted to use the code function but did not get it to work – MCrafterzz Apr 02 '16 at 06:30
  • 1
    Possible duplicate of [What is a NullPointerException, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) –  Mar 09 '17 at 16:38

1 Answers1

-1
Minecraft.getMinecraft().getRenderItem()

that part only exists in the INIT phase, and not the PreInit phase. there it's still null.

Register variants in preinit,

then register meshes in init

besure to call this via your clientproxy and not the commonproxy

ps, read the tutorial on http://bedrockminer.jimdo.com/modding-tutorials/basic-modding-1-8/blockstates-and-metadata/ and download the example zip to understand where goes where normally

Tschallacka
  • 27,901
  • 14
  • 88
  • 133