Posted February 27, 20178 yr Hi everyone, my first post I'm working on my first mod, just got started and I'm having trouble showing textures. I'm trying to add a Banana ItemFood to the game. I've created a class ItemBanana that extends ItemFood, set the super(4, false) and registered the item to GameRegistry, copied my banana.png to ./resources/assets/[modid]/textures/items/banana.png and created a model for it (do I need it?) in ./resources/assets/[modid]/models/item/banana.json. I can give myself the item in game and can eat it but it is missing the texture so I think the problem is that I didn't register renders anywhere and I'm not sure how to do that, can someone help? Edit: Giving more info on my renders. I tried this code: if (!Minecraft.getMinecraft().world.isRemote) { ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory")); } So if I understand correctly I'm checking if the code is running on the client and if so I'm providing location to banana resource and binding it to ItemBanana, but this gives an error Caused by: java.lang.NullPointerException, I think its because I'm doing this in preInit or is that ok? Edited February 27, 20178 yr by cxminer
February 27, 20178 yr Use ModelLoader.setCustomModelResourceLocation to register metadata-based item models. You need to call it in ModelRegistryEvent (if you're registering your Items in RegistryEvent.Register) or in preInit (if you're registering your Items in preInit). This needs to be done from a client-only class. I have an explanation of the model loading process and how ModelResourceLocations are mapped to model files here. 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.
February 27, 20178 yr Author Provided more info, I am using ModelLoader (check my first post), getting null pointer exception. Gonna debug now to see where the problem is. Thanks for the link!
February 27, 20178 yr Author OMG it works, so happy! My first banana! Sorry I guess I posted too soon, should have investigated further before posting. So if anyone has a similar problem here is what the problem was. I was checking variable isRemote on a world that doesn't exist at that stage yet. So I implemented proxies and put the renders in the ClientProxy and it works! Thanks for the link Choonster, very helpful, now I understand how model loading works.
February 27, 20178 yr 8 minutes ago, cxminer said: OMG it works, so happy! My first banana! Sorry I guess I posted too soon, should have investigated further before posting. So if anyone has a similar problem here is what the problem was. I was checking variable isRemote on a world that doesn't exist at that stage yet. So I implemented proxies and put the renders in the ClientProxy and it works! Thanks for the link Choonster, very helpful, now I understand how model loading works. It may help to read Forge's documentation on sides, which explains the difference between physical and logical sides. I'm glad you found my explanation helpful. 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.