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

[Solved] [1.17.1] Is there are way to define a client only item state for client animation and other effects ?


Kaworru
 Share

Recommended Posts

Hi,

I created a simple steel lighter item, which has a item property "open" with "1.0" or "0.0" to display two different models, see:

https://github.com/MarkusBordihn/BOs-Steel-Armor-Tools-Weapons/blob/main/src/main/resources/assets/steel_armor_tools_weapons/models/item/steel_lighter.json

This works fine, but I want to change the state in the case the steel lighter is currently selected in the hotbar or not.

I tried the LivingEquipmentChangeEvent which offers exactly the needed functionality, see:

https://github.com/MarkusBordihn/BOs-Steel-Armor-Tools-Weapons/blob/main/src/main/java/de/markusbordihn/steelarmortoolsweapons/client/equipment/EquipmentChange.java

But it seems that the ItemStack from this event is different from the ItemStack which is used for the ItemProperties.register(...), even both should be client side only.

What I tried so far:

  • Using itemStack.getOrCreateTag().putBoolean(...) and itemStack.getOrCreateTag().getBoolean(...)
  • Using a hashmap with <itemStack, boolean>
  • Using a local variable (current version)

A debug of the hashmap with <itemStack, boolean> shows that the itemStack within the ItemProperties.register(...) is different from the itemStack in LivingEquipmentChangeEvent.

So I wonder if there is a alternative event / approach I could use in this case or any other client only item state which I could share between these two events.

Edited by Kaworru
Link to comment
Share on other sites

4 hours ago, diesieben07 said:

Check whether the LivingEntity you get is not null and if the ItemStack being rendered is == to LivingEntity#getMainHandItem.

Thanks. Works like a charm. 

Example for the record:

ItemProperties.register(ModItems.STEEL_LIGHTER.get(),
    new ResourceLocation(Constants.MOD_ID, "open"),
    (itemStack, clientLevel, livingEntity, id) -> {
      return (livingEntity == null || !itemStack.is(ModItems.STEEL_LIGHTER.get())
          || livingEntity.getMainHandItem().isEmpty()
          || itemStack != livingEntity.getMainHandItem()) ? 0.0F : 1.0F;
    });

 

Link to comment
Share on other sites

  • Kaworru changed the title to [Solved] [1.17.1] Is there are way to define a client only item state for client animation and other effects ?

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.