#1.21.1 cancel horizontal movement

4 messages · Page 1 of 1 (latest)

pliant mango
#

This is my LivingEntity#travel method mixin which in my head was supposed to cancel any movement with the only exception of falling, however it cancels falling too for both players and regular entities. Any ideas how to fix it?

@Inject(
            method = "travel",
            at = @At(value = "HEAD"),
            cancellable = true
    )
    private void blockMovement(Vec3 vector, CallbackInfo callbackInfo) {
        var entity = (LivingEntity) (Object) this;
        if (!entity.hasEffect(DotcEffects.STUN))
            return;

        if (entity.getDeltaMovement().y < 0 && !entity.onGround())
            return;

        entity.setDeltaMovement(0, 0, 0);
        callbackInfo.cancel();
    }
tired trail
#

Maybe don't change the y value in setDeltaMovement()?

#

nvm

#

There's an Entity.fallDistance, maybe check if it's not zero.