Jump to content

[1.10.2] Item Model Variants


theDataSmith

Recommended Posts

Let's say I have a block with a .obj model that has 3 materials. Each material can be one of 10 textures, giving a total of 1000 different combinations. I can easily instantiate all these blocks with a for loop, but it would be impractical to have separate json files for each version. For the block model, I can pass information to the blockstates json file using the block's IBlockState, but how would I do this for the ItemBlock model?

Edited by theDataSmith
Link to comment
Share on other sites

1 hour ago, theDataSmith said:

If anyone knows how to register the ItemBlock to use [mod]/models/items/[name].json instead of [mod]/blockstates/[name].json I could probably figure it out from there.

Same way you register any other item model.

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.

Link to comment
Share on other sites

4 hours ago, theDataSmith said:

When I use ModelLoader.setCustomModelResourceLocation to register the model for the ItemBlock, it uses the blockstates json, not the models/item json. How to I make it use the models/item json?

 

Forge tries to load the item model first and only tries to load the model from the blockstates file if that fails. I have a more detailed explanation of the model loading process here.

 

If it's not loading your item models, the FML log should have an error message explaining why.

  • Like 1

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

Thank you! That link helped me out a lot. I was thinking I could pass data to the item model json, similarly to a blockstate json, but that appears to be impossible. Does anyone know if there's any way to load models/textures programmatically, rather than using a json?

Link to comment
Share on other sites

You can make an ICustomModelLoader.

Point the ResourceLocation to a custom IModel, that points to a custom IBakedModel.

In the IBakedModel's getQuads method, provide the list of BakedQuad's to render for the given side.

Do note, only calculate the BakedQuad's once, and store them somewhere. It's quite expensive to re-calculate every frame.

  • Like 1

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

After several hours going through source code, I finally figured out how to do it. I had to create an ICustomModelLoader and register it using ModelLoaderRegistry#registerLoader. I then used ModelLoaderRegistry#getModel and cast that IModel to an OBJModel so I could use OBJModel#retexture and OBJModel#process to swap out the textures and add the custom data "flip-v" = "true". That would have been enough, but I also needed different transformations for different item perspectives (GUI, GROUND, FIRST_PERSON_RIGHT_HAND, etc). I had to create my own IModel and IPerspectiveAwareModel classes so I could override IModel#bake and IPerspectiveAwareModel#handlePerective. handlePerspective should always be

 

return MapWrapper.handlePerspective(this, [Your IModelState], cameraTransformType);

 

but you can pass in your own IModelState class to handle the different transform types.

 

Anyway, I wrote this hoping someone would find it helpful. Thanks to Matryoshika for pointing me in the right direction.

Edited by theDataSmith
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.

Announcements



×
×
  • Create New...

Important Information

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