question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hooks for ItemStack NBT update animation

See original GitHub issue

Issue

When an ItemStack’s NBT updates, a quick “reload” animation is played (which involves the item dipping down and then pulling back up). This quickly becomes an issue when you have items that reload NBT quickly, like a tick counter item:

Registry.register(
        Registry.ITEM,
        new Identifier("nbtissue", "testitem"),
        new Item(new Item.Settings()) {
            @Override
            public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
                float currentTicks = stack.getOrCreateTag().getFloat("ticks");
                stack.getOrCreateTag().putFloat("ticks", currentTicks + 1);
                super.inventoryTick(stack, world, entity, slot, selected);
            }
        }
);

(result)

Context

HeldItemRenderer#updateHeldItems is where this animation update takes place. Forge has a hook here that allows you to define whether an item should cause said re-equip animation, and I think providing something similar in the API would be a good idea.

Current Solutions

In Inmis, I use an entirely cursed solution for getting around this issue. This will, obviously, fail as soon as 2 people try to do it (I claimed it first!!!). I’m writing this issue up now because several other people are encountering this issue and need a solution.

Potential Solutions

Forge provides a method in their Item class that allows you to define whether the re-equip animation should occur between stack A and stack B. We could do something similar in usage, like:

FabricItemUpdateAnimations.register(Items.MY_ITEM, (originalStack, newStack) -> {
        return [...]
});

An event might also make sense (so multiple people can have a say in whether a diamond sword triggers the reload animation):

ItemUpdateAnimationCallback.event(Items.DIAMOND_SWORD).register((originalStack, newStack) -> {
        return ActionResult.FAIL;
});

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Technici4ncommented, Jun 1, 2022

Implemented in #1790.

0reactions
TheBrokenRailcommented, Jul 1, 2020

If you only cancel in your special case, it will fall through to other injections and eventually the default implementation:

@Mixin(ItemStack.class)
public class ItemStackMixin {

    @Inject(at = @At("HEAD"), method = "equals", cancelable = true)
    public void equals(Object obj, CallbackInfoRetrunable<Boolean> info) {
        if (obj instanceof ItemStack) {
            ItemStack thisStack = (ItemStack) (Object) this;
            ItemStack checkStack = (ItemStack) obj;

            Item thisStackItem = thisStack.getItem();
            Item checkStackItem = checkStack.getItem();

            if (thisStackItem instanceof BackpackItem && checkStackItem instanceof BackpackItem) {
                info.setRetunrValue(true);
            }
        }
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

[SOLVED] Preventing 1st-person item change animation?
I've got an item that I don't want to have this 'animation' - I want it to ... when you modify the NBT...
Read more >
NBT Tags - Blfngl's Forge Tutorials!Updating to 1.8! - Weebly
This just tells minecraft that you want a new NBT tag written for this item. To create an NBT, add this directly below...
Read more >
Uses of Class net.minecraft.item.ItemStack - Empty
net.minecraftforge.client.model.animation ... Fields in net.minecraft.advancements declared as ItemStack ... Hook to allow item-sensitive armor model.
Read more >
JetsMinions | #1 MINIONS PLUGIN | ACTIONS | UPGRADES
This plugin hooks into some of the largest plugins including SkyBlocks, Towny, ... Customizable delays for Animations and Actions per Minion ...
Read more >
Minecraft Forge Changelog | Juan Carlos Oroza - Academia.edu
Closes #527 Build 1.5.1-7.7.1.657 LexManos: New hook to allow Items to render ... Should allow storing data in the nbt :) Build 1.5.1-7.7.0.603...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found