Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.5] Dynamic texture based on stack size?


Sinu
 Share

Recommended Posts

I have been wondering how to make an item change texture based on certain stack sizes? Someone had already posted about this many years back (https://forums.minecraftforge.net/topic/31987-18-texture-dependant-on-stack-size/) but I am wondering how I can go about doing this in 1.16.5? Also, I am pretty new at modding so a little bit of helping hand would be much appreciated!¬†ūüėÉ

Link to comment
Share on other sites

In FMLClienetSetupEvent use enqueue to schedule work on the main thread. In there use ItemModelsProperties.register to register an IItemPropertyGetter for your item. This then needs to return something based on the stack size. Your model can then reference this property, similarly to how the bow pulling works (check the bow model).

Link to comment
Share on other sites

Posted (edited)

Where can I find where Forge references the bow to change it's texture? Or does the bow implement it's features differently than the way you explained it? Looking at example codes help me learn the best I think.

EDIT: Oh, I think I understand what you mean. I found https://mcforge.readthedocs.io/en/latest/models/overrides/ which seems pretty close to what I want. So from what I am understanding, I am defining a new "predicate" for the item to recognize within the json file?

My next question is, where do I insert the FMLClientSetupEvent event?
I figured out where to put it! I have trouble editing this line to have it reflect with the number of stacks:
return entity != null && stack.getCount() && entity.getActiveItemStack() == stack ? 1.0F : 0.0F;

I am assuming I don't need to check if entity is null or not but only have it register the number of item stack?

Edited by Sinu
Link to comment
Share on other sites

Posted (edited)

I think I got a hang of what I should be doing but I think I am doing something wrong.
My json file looks like this which I think is correct:

{
	"parent": "item/generated",
	"textures": {
		"layer0": "brimheim:items/coin_bronze"
	},
	"overrides": [
		{
			"predicate": {
				"brimheim:stack": 16
			},
			"model": "brimheim:item/coin_bronze_stack"
		},
		{
			"predicate": {
				"brimheim:stack": 32
			},
			"model": "brimheim:item/coin_bronze_bag"
		}
	]
}

and this is my FMLClientSetupEvent event:

@Mod.EventBusSubscriber(modid = Brimheim.MODID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
public class BrimheimClient
{
	@SubscribeEvent
	public void setModelProperties(final FMLClientSetupEvent event)
	{
		event.enqueueWork(() ->
		{
			ItemModelsProperties.register(BrimheimItems.COIN_BRONZE.get(), 
				new ResourceLocation(Brimheim.MODID, "stack"), (stack, world, entity) -> {
	        return stack.getCount();
	        });
		});
	}
}

Also, I am not sure if the event method should be public or private. When I had it on private, I had a java.lang.RuntimeException: Illegal private member with @SubscribeEvent annotation error.

Edited by Sinu
Link to comment
Share on other sites

Actually I figured it out. Instead of doing SubscribeEvent, I just registered it to my main method with: 

FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

private void doClientStuff(FMLClientSetupEvent event) {
		event.enqueueWork(() ->
		{
			ItemModelsProperties.register(BrimheimItems.COIN_BRONZE.get(), 
				new ResourceLocation(Brimheim.MODID, "stack"), (stack, world, entity) -> {
	        return stack.getCount();
	        });
		});
    }

 

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

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.