Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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.

  • 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!

  • Author

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.

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.