|
| 1 | +package com.lambda.mixin.entity; |
| 2 | + |
| 3 | +import com.lambda.Lambda; |
| 4 | +import com.lambda.event.EventFlow; |
| 5 | +import com.lambda.event.events.MovementEvent; |
| 6 | +import com.lambda.interaction.RotationManager; |
| 7 | +import net.minecraft.entity.Entity; |
| 8 | +import net.minecraft.entity.LivingEntity; |
| 9 | +import net.minecraft.util.math.MathHelper; |
| 10 | +import net.minecraft.util.math.Vec3d; |
| 11 | +import org.spongepowered.asm.mixin.Mixin; |
| 12 | +import org.spongepowered.asm.mixin.Shadow; |
| 13 | +import org.spongepowered.asm.mixin.injection.At; |
| 14 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 15 | +import org.spongepowered.asm.mixin.injection.Redirect; |
| 16 | +import org.spongepowered.asm.mixin.injection.Slice; |
| 17 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 18 | + |
| 19 | +@Mixin(LivingEntity.class) |
| 20 | +public abstract class LivingEntityMixin extends EntityMixin { |
| 21 | + |
| 22 | + @Shadow |
| 23 | + protected abstract float getJumpVelocity(); |
| 24 | + |
| 25 | + @Inject(method = "jump", at = @At("HEAD"), cancellable = true) |
| 26 | + void onJump(CallbackInfo ci) { |
| 27 | + LivingEntity self = (LivingEntity) (Object) this; |
| 28 | + if (self != Lambda.getMc().player) return; |
| 29 | + ci.cancel(); |
| 30 | + |
| 31 | + float height = this.getJumpVelocity(); |
| 32 | + MovementEvent.Jump event = EventFlow.post(new MovementEvent.Jump(height)); |
| 33 | + |
| 34 | + if (event.isCanceled()) return; |
| 35 | + |
| 36 | + Vec3d vec3d = self.getVelocity(); |
| 37 | + self.setVelocity(vec3d.x, event.getHeight(), vec3d.z); |
| 38 | + |
| 39 | + if (self.isSprinting()) { |
| 40 | + Float yaw = RotationManager.getMovementYaw(); |
| 41 | + float f = ((yaw != null) ? yaw : self.getYaw()) * ((float)Math.PI / 180); |
| 42 | + self.setVelocity(self.getVelocity().add(-MathHelper.sin(f) * 0.2f, 0.0, MathHelper.cos(f) * 0.2f)); |
| 43 | + } |
| 44 | + |
| 45 | + self.velocityDirty = true; |
| 46 | + } |
| 47 | + |
| 48 | + @Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;isImmobile()Z")) |
| 49 | + void onTravelH(CallbackInfo ci) { |
| 50 | + Entity self = (Entity) (Object) this; |
| 51 | + if (self != Lambda.getMc().player) return; |
| 52 | + |
| 53 | + RotationManager.update(); |
| 54 | + } |
| 55 | + |
| 56 | + @Redirect(method = "travel", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getPitch()F")) |
| 57 | + private float hookModifyFallFlyingPitch(LivingEntity entity) { |
| 58 | + Float pitch = RotationManager.getMovementPitch(); |
| 59 | + if (entity != Lambda.getMc().player || pitch == null) return entity.getPitch(); |
| 60 | + |
| 61 | + return pitch; |
| 62 | + } |
| 63 | + |
| 64 | + @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getYaw()F"), slice = @Slice(to = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getYaw()F", ordinal = 1))) |
| 65 | + private float rotBody(LivingEntity entity) { |
| 66 | + if ((Object) this != Lambda.getMc().player) { |
| 67 | + return entity.getYaw(); |
| 68 | + } |
| 69 | + |
| 70 | + Float yaw = RotationManager.getRenderYaw(); |
| 71 | + return (yaw == null) ? entity.getYaw() : yaw; |
| 72 | + } |
| 73 | + |
| 74 | + @Redirect(method = "turnHead", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getYaw()F")) |
| 75 | + private float rotHead(LivingEntity entity) { |
| 76 | + if ((Object) this != Lambda.getMc().player) { |
| 77 | + return entity.getYaw(); |
| 78 | + } |
| 79 | + |
| 80 | + Float yaw = RotationManager.getRenderYaw(); |
| 81 | + return (yaw == null) ? entity.getYaw() : yaw; |
| 82 | + } |
| 83 | +} |
0 commit comments