Jump to content

Textures not showing, not sure how to implement renders


cxminer

Recommended Posts

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 by cxminer
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

OMG it works, so happy! My first banana! :D

 

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.

Link to comment
Share on other sites

8 minutes ago, cxminer said:

OMG it works, so happy! My first banana! :D

 

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.