#when is onStoppedUsing and usageTick called?

14 messages · Page 1 of 1 (latest)

pseudo escarp
#

I'm trying to make an item that levitates the player while they are using the item (right clicking), but these two methods don't seem to ever be called by the game in order to stop the levitating effect.

    public ActionResult use(World world, PlayerEntity user, Hand hand)
    {
        if(user.hasStatusEffect(StatusEffects.LEVITATION)) return ActionResult.PASS;

        user.addStatusEffect(new StatusEffectInstance(StatusEffects.LEVITATION, -1));
        return ActionResult.CONSUME;
    }


    @Override
    public boolean onStoppedUsing(ItemStack stack, World world, LivingEntity user, int remainingUseTicks)
    {
        System.out.println("Stopped");
        if(!user.hasStatusEffect(StatusEffects.LEVITATION)) return false;
        user.removeStatusEffect(StatusEffects.LEVITATION);
        return true;
    }```
unkempt crest
#

Also according to the documentation you also have to override getMaxUseTime for onStoppedUsing to be called

pseudo escarp
#

Where did you see that in the documentation? Couldn't find it anywhere.

pseudo escarp
#

I wanted to make my own levitating effect, but use isn't called every tick to make a smooth effect.
Hence why I'd want to try usageTick.

unkempt crest
#

Maybe it's not being called due to the isUsingItem check in LivingEntity#tickActiveItemStack

#

And it seems like the flag behind isUsingItem is manually set in the use method of other items that require holding rclick

#

More specifically, it's being set in PlayerEntity#setCurrentHand which is called within use

#

You could try adding a call to that to your method

pseudo escarp
#

I'm still having trouble navigating through Minecraft's code
I'm not new to Java but I'm new to Minecraft modding in general

#

I looked in every possible place and could find that hahaha