Posted May 22, 20169 yr I am using a book that I got from a summer camp to make a mod step-by-step. I do have a basic knowledge of Java before attending this camp, but not of minecraft's source code. so, I have a class in my mod package that is supposed to register and render custom items. However, the import for ModelResourceLocation will not work correctly for me, as it is put into the code exactly as it is in the book. here is the class's code: package wes.firstmod; import wes.firstmod.FirstMod; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.item.Item; import net.minecraftforge.fml.common.registry.GameRegistry; public class MyItems { public static Item cheese; public static void init() { cheese = new Item().setUnlocalizedName("cheese"); } public static void register() { GameRegistry.registerItem(cheese, cheese.getUnlocalizedName().substring(5)); } public static void registerRender(Item item) { Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(FirstMod.MODID + ":" + item.getUnlocalizedName().substring(5), "inventory")); } public static void registerRenders() { registerRender(cheese); } } The import line for ModelResourceLocation has an error. import net.minecraft.client.resources.model.ModelResourceLocation; which causes this line to error as well: Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(FirstMod.MODID + ":" + item.getUnlocalizedName().substring(5), "inventory")); however, in the import line, the only part that seems to error is this part: "net.minecraft.client.resources.model" How would I be able to fix this? I am willing to give more information if required. Thanks! "I'm not afraid of computers taking over the world. They're just sitting there. I can hit them with a two by four." - Thom Yorke
May 22, 20169 yr Which Minecraft version are you using? Always specify this in your thread title. In 1.9, ModelResourceLocation was moved to net.minecraft.client.renderer.block.model . Don't use unlocalised names for registry names or model locations. Registry names are IDs and must not change, unlocalised names can change at any time. If the registry and unlocalised names of an Item are the same, set the registry name and then set the unlocalised name to the full registry name. This will include your mod ID in the unlocalised name, which prevents conflicts with other mods. The default model loaded for every Item is the one with its registry name, so use this as the default model location for your Item s. Don't use ItemModelMesher#register , use ModelLoader.setCustomModelResourceLocation / setCustomMeshDefinition in preInit. I recommend creating a separate client-only class to handle your model registration to avoid mixing client-only code with common code. If you're using 1.9, don't use GameRegistry.registerItem / registerBlock , use GameRegistry.register . This registers any IForgeRegistryEntry implementation, including Item and Block . This doesn't create an ItemBlock for your Block , you need to do that yourself. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
May 23, 20169 yr Author Alright, I changed the subject. I am using 1.9.4 I tried to do what you listed and it all worked! I may have gotten a bit confused and did something different, but I got it to work overall. I split the registering and items into two classes. MyItems.java: package wes.firstmod; import wes.firstmod.FirstMod; //import net.minecraft.client.Minecraft; //import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.item.Item; //import net.minecraft.util.ResourceLocation; //import net.minecraftforge.client.model.ModelLoader; //import net.minecraftforge.fml.common.registry.GameRegistry; public class MyItems { public static Item cheese; public static void init() { cheese = new Item().setUnlocalizedName("cheese"); } } and MyItemRegistry.java: package wes.firstmod; import wes.firstmod.FirstMod; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.item.Item; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fml.common.registry.GameRegistry; public class MyItemRegistry { public static Item cheese = MyItems.cheese; public static void register() { Item cheeseName = cheese.setRegistryName("item_cheese"); GameRegistry.register(cheeseName); } public static void registerRender(Item item) { ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(FirstMod.MODID + ":" + item.getRegistryName(), "inventory")); } public static void registerRenders() { registerRender(MyItems.cheese); } } I just wanted to make sure this is what you were telling me, I tried my best to follow the list since my knowledge is limited. EDIT: I have a question, as well. What is the point of an unlocalized name? It doesn't look like there is a use to it, but I am probably very wrong Thanks a ton for helping! +1 "I'm not afraid of computers taking over the world. They're just sitting there. I can hit them with a two by four." - Thom Yorke
May 23, 20169 yr Item instantiation and registration should be in a single class, done at the same time. Model registration should be in a separate class only referenced from your client proxy. You can see how I register my mod's items here and models here. My code uses several Java 8 features that can't be used if you're targeting an earlier version (the default is Java 6). Registry names already include your mod ID, don't add it again when registering your models. Unlocalised names are used as translation keys. When Minecraft displays the name of an item, it looks up the unlocalised name in the lang file for the current locale. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
May 23, 20169 yr Author Alrighty, I think I got it all fixed up. Thanks again for the help! I also have another question, would there ever be a case when modding where I would need to use an unlocalized name? I just want to know for future reference. "I'm not afraid of computers taking over the world. They're just sitting there. I can hit them with a two by four." - Thom Yorke
May 23, 20169 yr I also have another question, would there ever be a case when modding where I would need to use an unlocalized name? I just want to know for future reference. You need unlocalised names for translation/display purposes, but that's it. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
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.