Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Posted

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

  • Author
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;
    });

 

  • 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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.