Reputation: 51
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.
Upvotes: 1
Views: 849
Reputation: 28742
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
Upvotes: -1