blinky000 Posted March 16, 2017 Posted March 16, 2017 This code works fine public class ModBlocksInit { public static ArrayList<Block> blockList = new ArrayList<Block>(); public static ModBlockPlanksEW planksEW; public static ItemBlock planksEWItem; public static void init(){ blockList.add(new ModBlock("brick_ew",Material.ROCK,"ModBlockBrick_ew",Main.CREATIVE_TAB)); blockList.add(new ModBlock("blueMarble",Material.ROCK,"ModBlockBlueMarble",Main.CREATIVE_TAB)); blockList.add(new ModBlock("blocktudor1",Material.CLAY,"BlockTudor1",Main.CREATIVE_TAB)); blockList.add(new ModBlockTudorSet1()); } public static void register(){ Iterator<Block> it = blockList.iterator(); while(it.hasNext()){ Block block = it.next(); GameRegistry.register(block);// registers the block // creates item from the block and registers it ItemBlock item = new ItemBlock(block); item.setRegistryName(block.getRegistryName()); GameRegistry.register(item); } } public static void registerRenders(){ Iterator<Block> it = blockList.iterator(); while(it.hasNext()){ Block block = it.next(); Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block),0,new ModelResourceLocation(block.getRegistryName(),"inventory")); //ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(),"inventory")); } } } but when i try to use the ModelLoader line, i get no textures in the inventory Quote
blinky000 Posted March 17, 2017 Author Posted March 17, 2017 The registerRenders is being called in init public class CommonProxy { public void preInit(FMLPreInitializationEvent e) { ModItemsInit.init(); ModItemsInit.register(); ModBlocksInit.init(); ModBlocksInit.register(); //System.out.println("++++++++++++++++++++++++++++++++++++++++++++++pre-init()"); } public void init(FMLInitializationEvent e) { ModItemsInit.registerRenders(); } public void postInit(FMLPostInitializationEvent e) { } } Putting it in preInit() crashes. So am i using ModelLoder in the wrong method ? Everything i read, said render is in Init(). Quote
Draco18s Posted March 17, 2017 Posted March 17, 2017 (edited) On 3/16/2017 at 5:32 PM, diesieben07 said: ModelLoader must be used in preInit. Expand And after your item and block creation. I.e. last. Also, if it crashes post the fucking crash log and the code that actually crashes. Edited March 17, 2017 by Draco18s Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
blinky000 Posted March 17, 2017 Author Posted March 17, 2017 in preInit() i put all ModItemsInit.init(); ModItemsInit.register(); ModBlocksInit.init(); ModBlocksInit.register(); ModBlocksInit.registerRenders(); everything is now working, after you strong reminder, i was prompted to READ THE DAMN CRASH LOG! it was crashing in the item render, so left that call out till i fix it. Now on to registering a block with varients. Thank you for your help. Quote
Draco18s Posted March 17, 2017 Posted March 17, 2017 (edited) On 3/17/2017 at 5:28 AM, blinky000 said: Now on to registering a block with varients. Thank you for your help. Expand Basically this: https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/hardlib/client/ClientEasyRegistry.java#L45-L54 You need to know all the valid states the block can be in (as an item) and then register an item variant model for it: https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/hardlib/client/ClientEasyRegistry.java#L161-L168 Be aware that that class is effectively a ClientProxy class and I did stuff the way I did so that I had main class syntax similar to 1.7's GameRegistry.RegisterBlock(...) (And it was written before the registry events were added) The important bits are to determine the variant string for the blockstate variant and register an item model (the usual way) with that string. Edited March 17, 2017 by Draco18s 1 Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
blinky000 Posted March 17, 2017 Author Posted March 17, 2017 package com.steveT.yabm.init; import java.util.ArrayList; import java.util.Iterator; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.block.model.ModelBakery; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.renderer.block.statemap.DefaultStateMapper; import net.minecraft.client.renderer.block.statemap.StateMapperBase; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.client.model.ModelLoader; import com.google.common.collect.ImmutableList; import com.steveT.yabm.Main; import com.steveT.yabm.blocks.ModBlock; import com.steveT.yabm.blocks.ModBlockPlanksEW; import com.steveT.yabm.blocks.ModBlockTudorSet1; public class ModBlocksInit { public static ArrayList<Block> blockList = new ArrayList<Block>(); public static ModBlockPlanksEW planksEW; public static void init(){ blockList.add(new ModBlock("brick_ew",Material.ROCK,"ModBlockBrick_ew",Main.CREATIVE_TAB)); blockList.add(new ModBlock("blueMarble",Material.ROCK,"ModBlockBlueMarble",Main.CREATIVE_TAB)); blockList.add(new ModBlock("blocktudor1",Material.CLAY,"BlockTudor1",Main.CREATIVE_TAB)); blockList.add(new ModBlockTudorSet1()); } public static void register(){ Iterator<Block> it = blockList.iterator(); while(it.hasNext()){ Block block = it.next(); GameRegistry.register(block);// registers the block // creates item from the block and registers it ItemBlock item = new ItemBlock(block); item.setRegistryName(block.getRegistryName()); GameRegistry.register(item); } planksEW = new ModBlockPlanksEW(); //GameRegistry.register(planksEW); ItemBlock item = new ItemBlock(planksEW); item.setRegistryName(planksEW.getRegistryName()); GameRegistry.register(item); GameRegistry.register(planksEW); StateMapperBase b = new DefaultStateMapper(); BlockStateContainer bsc = planksEW.getBlockState(); ImmutableList<IBlockState> values = bsc.getValidStates(); for(IBlockState state : values) { String str = b.getPropertyString(state.getProperties()); _registerBlockItemModelForMeta(planksEW, planksEW.getMetaFromState(state), str); } } private static void _registerBlockItemModelForMeta(Block block, int metadata, String variant) { final Item item = Item.getItemFromBlock(block); if (item != null) { _registerItemModelForMeta(item, metadata, variant); } } private static void _registerItemModelForMeta(Item item, int metadata, String variant) { ModelResourceLocation res = new ModelResourceLocation(item.getRegistryName(), variant); _registerItemModelForMeta(item, metadata, res); } private static void _registerItemModelForMeta(Item item, int metadata, ModelResourceLocation modelResourceLocation) { ModelLoader.setCustomModelResourceLocation(item, metadata, modelResourceLocation); } public static void registerRenders(){ Iterator<Block> it = blockList.iterator(); while(it.hasNext()){ Block block = it.next(); //Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block),0,new ModelResourceLocation(block.getRegistryName(),"inventory")); ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(),"inventory")); } } } using your code(hope that's ok) i was able to get all the different states in the inventory, but the all have the same name , and only place the meta 0 block. I must not be registering my block (planksEW) correctly ( i remember in a different post of yours ; 1 block 1 item) and i only have one block Quote
Draco18s Posted March 17, 2017 Posted March 17, 2017 That's because you're using ItemBlock. The base ItemBlock class doesn't give a shit about metadata. You want ItemMultiTexture or create your own (look at ItemCloth as an example). 1 Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
blinky000 Posted March 18, 2017 Author Posted March 18, 2017 Changed the ItemBlock to ItemMultiTexture item = new ItemMultiTexture(planksEW, planksEW, ModBlockPlanksEW.subTypes); added the subTypes string array to the ModBlockPlanksEW And now all is good , thank you. Quote
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.