Jump to content

[Solved][1.8.9] How to change inventory icons of an item based on nbt


DanielDawn

Recommended Posts

So I have a tool that is supposed to change colors based on nbt, and I have this working for the model in the hand. However, the model in the hotbar remains the same. In the past, I've used 

Item#getIcon

Is it possible to change the inventory texture of an item based on it's nbt data? If so, I'd like to know how I would do so. I don't want to use durability because the item is a tool, and having a consumable item used to change its texture damaging it wouldn't make much sense and would mean that if the item were repaired its texture would be lost. 

Edited by DanielDawn
Link to comment
Share on other sites

You need to set the item's custom mesh definition.

I do that here (this code being client side, super being the common code part of just registering the item as normal):

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/hardlib/client/ClientEasyRegistry.java#L124-L130

IItemWithMeshDefinition is just an interface that allows my items to define their own mesh definitions, which is done here:

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/industry/item/ItemCastingMold.java#L87-L118

In this case, it allows me to select any one of these models:

https://github.com/Draco18s/ReasonableRealism/tree/1.12.1/src/main/resources/assets/expindustry/models/item

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

So does Custom Mesh Definition use the modelresourcelocation specified? How can I be sure that the models it's using are registered? I keep getting a black and purple box, meaning that it couldn't find a json. 

 

My Platinum_Bow is using this method. It's currently just a placeholder for a different item. I'm testing to see if it even uses the se/models/item/platinum_bow_pulling_2.json and se/models/item/platinum_bow_pulling_0.json. 

@Override
	@SideOnly(Side.CLIENT)
	public ItemMeshDefinition getMeshDefinition() {
		return new ItemMeshDefinition()
		{
			public ModelResourceLocation getModelLocation(ItemStack stack)
			{
				if(stack.hasTagCompound()) {
					NBTTagCompound nbt = stack.getTagCompound();
					if(nbt.getBoolean("platinum")) {
						return new ModelResourceLocation("se:" + SeItems.platinum_bow.getUnlocalizedName().substring(5) + "_pulling_2", "inventory");
					}
				}
				return new ModelResourceLocation("se:" + SeItems.platinum_bow.getUnlocalizedName().substring(5) + "_pulling_0", "inventory");
			}
		};
	}

 

I'm using my regular proxy to do what your easyregistry classes do.

public static <T extends Item & IItemWithMeshDefinition> void registerItemWithCustomMeshDefinition(T item, String registryname) {
		SmallEnhancements.proxy._registerItemWithCustomMeshDefinition(item, registryname);
	}

	public <T extends Item & IItemWithMeshDefinition> void _registerItemWithCustomMeshDefinition(T item, String registryname) {
		GameRegistry.registerItem(item, registryname);
	}
	
	public static <T extends Item & IItemWithMeshDefinition> void registerSpecificItemVariantsWithBakery(T item, ItemStack variantStack) {
				SmallEnhancements.proxy._registerSpecificItemVariantsWithBakery(item, variantStack);
			}
	
	public <T extends IItemWithMeshDefinition> void _registerSpecificItemVariantsWithBakery(T item, ItemStack variantStack) {
				
			}

 

I'm running those inside of my main class's fmlinitevent.

proxy.registerRenders();
		proxy._registerItemWithCustomMeshDefinition((Platinum_Bow)SeItems.platinum_bow, SeItems.platinum_bow.getUnlocalizedName().substring(5));
		ItemStack variantStack = new ItemStack(SeItems.platinum_bow);
		variantStack.setTagCompound(new NBTTagCompound());
		variantStack.getTagCompound().setBoolean("platinum", true);
		proxy.registerSpecificItemVariantsWithBakery((Platinum_Bow)SeItems.platinum_bow, variantStack);

 

I'm clueless as to how to properly use the variant stack especially. I'm really lost. (Also I used 'history' to go to your commits where you barely started using custommeshdefinitions.)

Edited by DanielDawn
Link to comment
Share on other sites

Thank you, I registered my ItemMeshDefinition and my models were registered I just didn't show them. I also found out that the reason my item was using the inappropriate model was because I was not preventing the default model from loading, no wonder it kept using the default model. Anyway thank you so much for all your help, I'm recently updating from 1.7.10 to 1.8.9, and I hope to update to 1.9 as soon as I can finish this 1.8.9 version. 

Link to comment
Share on other sites

46 minutes ago, DanielDawn said:

and I hope to update to 1.9 as soon as I can finish this 1.8.9 version. 

1.10 and 1.12 after that? Hopefully in time for 1.13?

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

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.