Jump to content

[Solved][1.8.9] Changing Item texture based on an NBT flag


Recommended Posts

Posted

Hello, I am messing around with creating various things in 1.8.9 in an attempt to get a better feel for the new model system. Right now I am trying to create a basic helmet which changes the armor texture and the item texture depending on the value of the design tag in the ItemStack NBT. I have read through a few other topics on changing the item texture/model depending on the NBT or other conditions, and have found a way to do what I am trying to achieve. The way I am attempting makes use of a custom ItemMeshDefinition which allows me to change the ModelResourceLocation based on an ItemStack. The other topics I have read, along with the 1.8.9 Rendering Primer document that has been going around say that I must first bake the models using ModelLoader#registerItemVariants and passing it all the ResourceLocations pointing to my variants, and then I must use  ModelLoader#setCustomMeshDefinition to apply my custom ItemMeshDefinition. I believe that I have done both of those things correctly, however my item still has the over sized block model, and the purple/black missing texture look. I have also compared my code against code found in the 1.8 port of Botania (the mana gun and other items use the same approach) however I couldn't find any differences or things I might have left out. This issue has really stumped me, and I would really appreciate it if someone could give my code a look over.

 

Some important notes

-Right now I have only creates json models for 3/16 of my current designs.

-The 3 designs that have json models are not listed in the console output of missing models, the other 13 are.

-The models I am using use a custom parent model to cut down on the size of my json files. This seems to be a common thing, however it is worth mentioning.

 

The entire source for this mod is public on GitHub however here are some other important files

Mod Class

Main Mod Class

Mesh Definition

Model Files

Item Class

Posted

You have a few problems:

  • Your item textures are in textures/item instead of textures/item.
  • You're registering your models in init.
    ModelLoader.setCustomMeshDefinition

    only works if called before init.

  • You're returning a
    ModelResourceLocation

    with the default

    "normal"

    variant from your

    Deadmau5MeshDefinition

    , but the

    builtin/generated

    model only provides the 

    "inventory"

    variant.

 

I've forked your mod on GitHub and fixed these problems. You can see what I changed and/or merge the changes 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.

Posted

Thank you for having a look at the project, you were spot on with the problems you found. Some of them such as the textures being in the wrong directory were pretty foolish on my part :P Also, thank you for creating a fork of the repository, that was far more then I could have hoped for, and I really appreciate it.

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.