kitsushadow Posted February 12, 2017 Posted February 12, 2017 I have a block with multiple states, when i change the state of the block and it is rendered as an item by Minecraft, either as an entity or in gui or etc. i get the null model and texture. I know that there is something about register blocks / items with subtypes to get their models to render correctly. Could someone point me to some source code that shows how to register a block that has subtypes so that the Item Models register correctly as well? Or perhaps i'm registering my blocks right and the blockstate / item model json is wrong? Regardless some source code that highlights doing the above will let me debug and find out for myself. Thanks in advance. Quote
kitsushadow Posted February 12, 2017 Author Posted February 12, 2017 @diesieben07 The source code can be found here https://github.com/kitsushadow/forgecraft/tree/master/1.11/src/main Specifically related to the IngotBall class and the ironball block. Thanks for the help Quote
kitsushadow Posted February 13, 2017 Author Posted February 13, 2017 (edited) 17 minutes ago, diesieben07 said: Which Block are we talking about? https://github.com/kitsushadow/forgecraft/blob/master/1.11/src/main/java/nmd/primal/forgecraft/blocks/IngotBall.java @diesieben07 Edited February 13, 2017 by kitsushadow Quote
kitsushadow Posted February 13, 2017 Author Posted February 13, 2017 Does that mean I need a basic item that does nothing other than be the subtype place holder item??? So a furnaceLit and furnaceOff would need two separate items? Just want to make sure I understand right. Quote
kitsushadow Posted February 13, 2017 Author Posted February 13, 2017 @diesieben07 I'm looking through the source code, only thing I see is that I need to have the subtypes as a list and call getSubBlocks in the block class. I found that in the Block class BlockColored I know this is something relatively simple but I could really use a mod source code example cuz i'm having difficulty following your suggestions. @SideOnly(Side.CLIENT) public void getSubBlocks(Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list) { for (EnumDyeColor enumdyecolor : EnumDyeColor.values()) { list.add(new ItemStack(itemIn, 1, enumdyecolor.getMetadata())); } } Quote
kitsushadow Posted February 13, 2017 Author Posted February 13, 2017 (edited) Ahh! So should my IngotBall class which is a block extend ItemBlock instead of Block? Or do I need both the Block class and an ItemBlock Class? thanks Edited February 13, 2017 by kitsushadow Quote
kitsushadow Posted February 13, 2017 Author Posted February 13, 2017 Just now, diesieben07 said: You need both. Block handles when placed in the world, Item handles when in inventories. Got it, thanks for your help. Quote
kitsushadow Posted February 13, 2017 Author Posted February 13, 2017 I'm looking at source code examples and getting lost how to register the the block and item now. How and where do i register the ItemBlock i've made? Quote
Draco18s Posted February 13, 2017 Posted February 13, 2017 Same way you register anything else. ItemBlock itemBl = new ItemBlock(yourBlock).setRegistryName(yourBlock.getRegistryName()); GameRegistry.Register(itemBl); Or via the registry events. 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.
kitsushadow Posted February 13, 2017 Author Posted February 13, 2017 getting a null pointer exception with that Error: net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Kitsu's Forgecraft (forgecraft) Caused by: java.lang.NullPointerException at net.minecraftforge.fml.common.registry.GameData$ItemCallbacks.onAdd(GameData.java:367) at net.minecraftforge.fml.common.registry.GameData$ItemCallbacks.onAdd(GameData.java:356) at net.minecraftforge.fml.common.registry.FMLControlledNamespacedRegistry.addObjectRaw(FMLControlledNamespacedRegistry.java:601) at net.minecraftforge.fml.common.registry.FMLControlledNamespacedRegistry.add(FMLControlledNamespacedRegistry.java:499) at net.minecraftforge.fml.common.registry.FMLControlledNamespacedRegistry.register(FMLControlledNamespacedRegistry.java:852) at net.minecraftforge.fml.common.registry.GameData.register_impl(GameData.java:225) at net.minecraftforge.fml.common.registry.GameRegistry.register(GameRegistry.java:155) at nmd.primal.forgecraft.init.ModItems.register(ModItems.java:45) at nmd.primal.forgecraft.ForgeCraft.preInit(ForgeCraft.java:47) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) Registry Class: public class ModItems { public static Item pistonbellows; public static Item softcrucible; public static Item stonetongs; public static ItemBlock ironingotball; //public static Item forgingmanual; public static void init() { OBJLoader.INSTANCE.addDomain(ModInfo.MOD_ID); pistonbellows = new ItemBellowsHandle(); softcrucible = new ItemSoftCrucible(); stonetongs = new ItemStoneTongs("stonetongs"); ironingotball = new ItemBlockIngotBall(ModBlocks.ironball, "ironingotball"); //forgingmanual = new ItemForgingManual(); } public static void register() { GameRegistry.register(pistonbellows); GameRegistry.register(softcrucible); GameRegistry.register(stonetongs); GameRegistry.register(ironingotball); //GameRegistry.register(forgingmanual); } public static void registerRenders() { registerRender(pistonbellows); registerRender(softcrucible); registerRenderItemBlock(ironingotball); //registerRender(forgingmanual); } public static void registerCustomRenders(){ ModelBakery.registerItemVariants(ModItems.stonetongs, ModItems.stonetongs.getRegistryName(), new ResourceLocation(ModInfo.MOD_ID, "stonetongs"), new ResourceLocation(ModInfo.MOD_ID, "stonetongs_default"), new ResourceLocation(ModInfo.MOD_ID, "stonetongs_emptyhot"), new ResourceLocation(ModInfo.MOD_ID, "stonetongs_emptyhotcracked"), new ResourceLocation(ModInfo.MOD_ID, "stonetongs_hotiron"), new ResourceLocation(ModInfo.MOD_ID, "stonetongs_hotironcooked"), new ResourceLocation(ModInfo.MOD_ID, "stonetongs_hotironfailed") ); ModelLoader.setCustomMeshDefinition(ModItems.stonetongs, new ItemMeshDefinition() { @Override public ModelResourceLocation getModelLocation(ItemStack stack) { if (stack.hasTagCompound()) { if (stack.getTagCompound().getInteger("type") == 0 ){ return new ModelResourceLocation(stack.getItem().getRegistryName() + "_default", "inventory"); } else if (stack.getTagCompound().getInteger("type") == 1 ) { return new ModelResourceLocation(stack.getItem().getRegistryName() + "_emptyhot", "inventory"); } else if (stack.getTagCompound().getInteger("type") == 2 ) { return new ModelResourceLocation(stack.getItem().getRegistryName() + "_emptyhotcracked", "inventory"); } else if (stack.getTagCompound().getInteger("type") == 3 ) { return new ModelResourceLocation(stack.getItem().getRegistryName() + "_hotiron", "inventory"); } else if (stack.getTagCompound().getInteger("type") == 4 ) { return new ModelResourceLocation(stack.getItem().getRegistryName() + "_hotironcooked", "inventory"); } else if (stack.getTagCompound().getInteger("type") == 5 ) { return new ModelResourceLocation(stack.getItem().getRegistryName() + "_hotironfailed", "inventory"); } else return new ModelResourceLocation(stack.getItem().getRegistryName(), "inventory"); } return new ModelResourceLocation(stack.getItem().getRegistryName(), "inventory"); } }); } private static void registerRender(Item item) { Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory")); } private static void registerRenderItemBlock(ItemBlock item){ Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory")); } /*public static void registerRender(Item item, int meta, String fileName) { ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(new ResourceLocation(fileName), "inventory")); } public static void registerRender(Item item, int meta, String fileName) { Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, meta, new ModelResourceLocation(fileName, "inventory")); }*/ } Quote
Leomelonseeds Posted February 13, 2017 Posted February 13, 2017 No you must set a registry name for the item ironball as Draco18s told you. Quote Apparently I'm addicted to these forums and can't help but read all the posts. So if I somehow help you, please click the "Like This" button, it helps.
kitsushadow Posted February 13, 2017 Author Posted February 13, 2017 (edited) Thank for the help guys getting a new error now Seems like the Block Registry Name and the ItemBlock registry name are conflicting? net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Kitsu's Forgecraft (forgecraft) Caused by: java.lang.IllegalStateException: Attempted to set registry name with existing registry name! New: forgecraft:ironball Old: forgecraft:ironball at net.minecraftforge.fml.common.registry.IForgeRegistryEntry$Impl.setRegistryName(IForgeRegistryEntry.java:73) at net.minecraftforge.fml.common.registry.IForgeRegistryEntry$Impl.setRegistryName(IForgeRegistryEntry.java:90) at nmd.primal.forgecraft.init.ModItems.init(ModItems.java:40) at nmd.primal.forgecraft.ForgeCraft.preInit(ForgeCraft.java:48) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) New Registry Code public static Item pistonbellows; public static Item softcrucible; public static Item stonetongs; public static ItemBlock ironingotball; //public static Item forgingmanual; public static void init() { OBJLoader.INSTANCE.addDomain(ModInfo.MOD_ID); pistonbellows = new ItemBellowsHandle(); softcrucible = new ItemSoftCrucible(); stonetongs = new ItemStoneTongs("stonetongs"); ironingotball = new ItemBlockIngotBall(ModBlocks.ironball.setRegistryName(ModBlocks.ironball.getRegistryName())); //forgingmanual = new ItemForgingManual(); } public static void register() { GameRegistry.register(pistonbellows); GameRegistry.register(softcrucible); GameRegistry.register(stonetongs); GameRegistry.register(ironingotball); //GameRegistry.register(forgingmanual); } Edited February 13, 2017 by kitsushadow Quote
Animefan8888 Posted February 13, 2017 Posted February 13, 2017 I believe you are registering a normal ItemBlock stil in your ModBlocks class or where ever you register your Blocks and there ItemBlocks. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
kitsushadow Posted February 13, 2017 Author Posted February 13, 2017 20 minutes ago, Animefan8888 said: I believe you are registering a normal ItemBlock stil in your ModBlocks class or where ever you register your Blocks and there ItemBlocks. Can u say that again? I am registering my ItemBlock in my Item Class. Is that wrong? Quote
Animefan8888 Posted February 13, 2017 Posted February 13, 2017 No that is not wrong, could you post where you do the rest of your ItemBlocks. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
kitsushadow Posted February 13, 2017 Author Posted February 13, 2017 I dont have any other ItemBlocks, this is my first ItemBlock https://github.com/kitsushadow/forgecraft/blob/master/1.11/src/main/java/nmd/primal/forgecraft/init/ModItems.java Quote
Animefan8888 Posted February 13, 2017 Posted February 13, 2017 This is your registerBlock Method private static void registerBlock(Block block) { GameRegistry.register(block); ItemBlock item = new ItemBlock(block); item.setRegistryName(block.getRegistryName()); GameRegistry.register(item); } Which also registers an ItemBlock for the block you have a custom one so you cannot do that. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
kitsushadow Posted February 13, 2017 Author Posted February 13, 2017 Ok, so what do i do about registering the subTypes? All i see in the UI is the default state of the item. Quote
kitsushadow Posted February 13, 2017 Author Posted February 13, 2017 @Animefan8888 I think i see what u mean i updated my Block class but getting a null pointer again package nmd.primal.forgecraft.init; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraftforge.fml.common.registry.GameRegistry; import nmd.primal.forgecraft.blocks.*; /** * Created by kitsu on 11/26/2016. */ public class ModBlocks { public static Block firebox; public static Block bloomery; public static Block pistonbellowsoak; public static Block pistonbellowsjungle; public static Block pistonbellowsbirch; public static Block pistonbellowsspruce; public static Block pistonbellowsdarkoak; public static Block pistonbellowsacacia; public static Block emptycrucible; public static Block emptycruciblehot; public static Block emptycruciblecracked; public static Block emptycruciblecrackedhot; public static Block rawironcrucible; public static Block hotironcrucible; public static Block hotcookedironcrucible; public static Block coolironcrucible; public static Block failedironcrucible; public static Block failedironcruciblehot; public static Block ironball; public static ItemBlock ironballitem; public static void init() { firebox = new Forge(Material.ROCK); bloomery = new Bloomery(Material.ROCK, "bloomery"); pistonbellowsoak = new PistonBellows(Material.WOOD, "pistonbellowsoak"); pistonbellowsjungle = new PistonBellows(Material.WOOD, "pistonbellowsjungle"); pistonbellowsbirch = new PistonBellows(Material.WOOD, "pistonbellowsbirch"); pistonbellowsspruce = new PistonBellows(Material.WOOD, "pistonbellowsspruce"); pistonbellowsdarkoak = new PistonBellows(Material.WOOD, "pistonbellowsdarkoak"); pistonbellowsacacia = new PistonBellows(Material.WOOD, "pistonbellowsacacia"); emptycrucible = new Crucible(Material.ROCK, "emptycrucible"); emptycruciblehot = new CrucibleHot(Material.ROCK, "emptycruciblehot"); emptycruciblecracked = new Crucible(Material.ROCK, "emptycruciblecracked"); emptycruciblecrackedhot = new CrucibleHot(Material.ROCK, "emptycruciblecrackedhot"); rawironcrucible = new Crucible(Material.ROCK, "rawironcrucible"); hotironcrucible = new CrucibleHot(Material.ROCK, "hotironcrucible"); hotcookedironcrucible = new CrucibleHot(Material.ROCK, "hotcookedironcrucible"); coolironcrucible = new Crucible(Material.ROCK, "coolironcrucible"); failedironcrucible = new Crucible(Material.ROCK, "failedironcrucible"); failedironcruciblehot = new CrucibleHot(Material.ROCK, "failedironcruciblehot"); ironball = new IngotBall(Material.IRON, "ironball", 5.0F); } public static void register() { registerBlock(firebox); registerBlock(bloomery); registerBlock(pistonbellowsoak); registerBlock(pistonbellowsjungle); registerBlock(pistonbellowsbirch); registerBlock(pistonbellowsspruce); registerBlock(pistonbellowsdarkoak); registerBlock(pistonbellowsacacia); registerBlock(emptycrucible); registerBlock(emptycruciblehot); registerBlock(emptycruciblecracked); registerBlock(emptycruciblecrackedhot); registerBlock(rawironcrucible); registerBlock(hotironcrucible); registerBlock(hotcookedironcrucible); registerBlock(coolironcrucible); registerBlock(failedironcrucible); registerBlock(failedironcruciblehot); registerBlockSubType(ironball, ironballitem); } public static void registerRenders() { registerRender(firebox); registerRender(pistonbellowsoak); registerRender(pistonbellowsjungle); registerRender(pistonbellowsbirch); registerRender(pistonbellowsspruce); registerRender(pistonbellowsdarkoak); registerRender(pistonbellowsacacia); registerRender(bloomery); registerRender(emptycrucible); registerRender(emptycruciblehot); registerRender(emptycruciblecracked); registerRender(emptycruciblecrackedhot); registerRender(rawironcrucible); registerRender(hotironcrucible); registerRender(hotcookedironcrucible); registerRender(coolironcrucible); registerRender(failedironcrucible); registerRender(failedironcruciblehot); registerRender(ironball); } private static void registerBlock(Block block) { GameRegistry.register(block); ItemBlock item = new ItemBlock(block); item.setRegistryName(block.getRegistryName()); GameRegistry.register(item); } private static void registerBlockSubType(Block block, ItemBlock itemBlock){ GameRegistry.register(block); ItemBlock item = itemBlock; item.setRegistryName(block.getRegistryName()); GameRegistry.register(item); } private static void registerRender(Block block) { Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(), "inventory")); } } Quote
Draco18s Posted February 13, 2017 Posted February 13, 2017 Quote but getting a null pointer again Where? 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.
kitsushadow Posted February 13, 2017 Author Posted February 13, 2017 (edited) @Draco18s sorry thought i had included it Caused by: java.lang.NullPointerException at nmd.primal.forgecraft.init.ModBlocks.registerBlockSubType(ModBlocks.java:131) at nmd.primal.forgecraft.init.ModBlocks.register(ModBlocks.java:93) at nmd.primal.forgecraft.ForgeCraft.preInit(ForgeCraft.java:47) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) Line 131 item.setRegistryName(block.getRegistryName()); Line 93 registerBlockSubType(ironball, ironballitem); Edited February 13, 2017 by kitsushadow Quote
Draco18s Posted February 13, 2017 Posted February 13, 2017 You never set ironballitem to anything. 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.
kitsushadow Posted February 13, 2017 Author Posted February 13, 2017 (edited) Ok, so now i was able to launch successfully and no registration warnings in the console so thats good but I see only the defaults state of the Item in the UI https://github.com/kitsushadow/forgecraft/blob/master/1.11/src/main/java/nmd/primal/forgecraft/init/ModBlocks.java Edited February 13, 2017 by kitsushadow Quote
kitsushadow Posted February 14, 2017 Author Posted February 14, 2017 (edited) Is it just the rendering at this point??? private static void registerRender(Block block) { Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(), "inventory")); } } That probably is not enough to register the itemSubtypes but if that was the case wouldn't the itemSubtype at least show up in the creative tab? Edited February 14, 2017 by kitsushadow Quote
Draco18s Posted February 14, 2017 Posted February 14, 2017 Don't use the model mesher, use ModelLoader.setCustomModelResourceLocation 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.
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.