Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ItemStacks share the same STACK_ANIMATABLE_ID_COMPONENT after cloning in creative mode #681

Open
Mishin870 opened this issue Feb 20, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@Mishin870
Copy link

It's not really a library problem, but rather a minecraft problem

I have an animated item that has an inventoryTick method that has the following code in it:

var id = GeoItem.getId(stack);
var animationController = getAnimatableInstanceCache().getManagerForId(id).getAnimationControllers().get("controller");

var isSprinting = entity.isSprinting();
var isTriggeredSprinting = animationController.isPlayingTriggeredAnimation() && animationName.equals("sprinting");

var activeStack = ((PlayerEntity) entity).getMainHandStack();
var isActiveStack = activeStack == stack;
var isActiveStackAndSprinting = isSprinting && isActiveStack;

// The animation of an inactive ItemStack must be forced to idle
if (isActiveStackAndSprinting && !isTriggeredSprinting) {
    animationController.tryTriggerAnimation("sprinting");
} else if (!isActiveStackAndSprinting && isTriggeredSprinting) {
    animationController.tryTriggerAnimation("idle");
    animationController.stop();
}

And when I have two items with the same STACK_ANIMATABLE_ID_COMPONENT in my inventory, they behave as follows:

java_2025-02-19_15-18-03-932.mp4

If I try something like this:

if (isActiveStack) {
    if (isSprinting && !isTriggeredSprinting) {
        animationController.tryTriggerAnimation("sprinting");
    } else if (!isSprinting && isTriggeredSprinting) {
        animationController.tryTriggerAnimation("idle");
        animationController.stop();
    }
}

Then it works as expected, but when switching to an inactive item I'll see it suddenly go from sprinting to idle

java.2025-02-20.04-31-58-909.mp4

Because the sprinting animation wasn't turned off in it earlier
But if I try to turn it off, it will also turn off the animation of the active item, because of the same id

@Tslat Tslat added the enhancement New feature or request label Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants