#Air Movement Speed

7 messages · Page 1 of 1 (latest)

earnest wraith
#

Is there a method into which i could mixin to be able to scale a LivingEntity/PlayerEntity's air movement speed?

fair oasis
# earnest wraith Is there a method into which i could mixin to be able to scale a LivingEntity/Pl...

There is a method called setFlyingSpeed inside net.minecraft.world.entity.player.Abilities with which you can change the player flying speed. However, if you want to change air movement speed (jumping, while player in air, etc.) There is a method called travelInAir(final Vec3d input) (26.1-SNAPSHOT4) which you can you use mixin to implement what you need.
An example: (don't fly very high!)

import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(LivingEntity.class)
public class LivingEntityMixin {

    @Inject(
            method = "travelInAir",
            at = @At(
                    value = "INVOKE",
                    target = "Lnet/minecraft/world/entity/LivingEntity;handleRelativeFrictionAndCalculateMovement(Lnet/minecraft/world/phys/Vec3;F)Lnet/minecraft/world/phys/Vec3;"),
            cancellable = false
    )
    private void scaleAirMovement(Vec3 input, CallbackInfo ci) {
        LivingEntity self = (LivingEntity)(Object)this;

        if (!self.onGround()) {
            Vec3 original = self.getDeltaMovement();
            double multiplier = 1.5;

            self.setDeltaMovement(
                    original.x * multiplier,
                    original.y,
                    original.z * multiplier
            );
        }
    }
}
mighty otter
#

No need to double cast

earnest wraith
earnest wraith
#

believe so

mighty otter
#

This last else block contains the values you want