From d74a853824590f22a5a3225acb6322d773f67a5b Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 26 Nov 2020 20:58:24 +0200 Subject: [PATCH] Fixed eye position when riding a vehicle --- .../client/mixin/MixinClientPlayerEntity.java | 22 ++++++++++++++++++- .../com/minelittlepony/client/pony/Pony.java | 11 ++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/minelittlepony/client/mixin/MixinClientPlayerEntity.java b/src/main/java/com/minelittlepony/client/mixin/MixinClientPlayerEntity.java index b6dee851..686b2548 100644 --- a/src/main/java/com/minelittlepony/client/mixin/MixinClientPlayerEntity.java +++ b/src/main/java/com/minelittlepony/client/mixin/MixinClientPlayerEntity.java @@ -5,14 +5,29 @@ import com.minelittlepony.client.MineLittlePony; import net.minecraft.client.network.AbstractClientPlayerEntity; import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.entity.Entity; import net.minecraft.entity.EntityDimensions; import net.minecraft.entity.EntityPose; 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.callback.CallbackInfoReturnable; @Mixin(ClientPlayerEntity.class) abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity { public MixinClientPlayerEntity() { super(null, null); } + @Inject(method = "startRiding(Lnet/minecraft/entity/Entity;Z)Z", at = @At("RETURN")) + public void onStartRiding(Entity entity, boolean bl, CallbackInfoReturnable info) { + calculateDimensions(); + } + + @Override + public void stopRiding() { + super.stopRiding(); + calculateDimensions(); + } + @Override public float getActiveEyeHeight(EntityPose pose, EntityDimensions dimensions) { float value = super.getActiveEyeHeight(pose, dimensions); @@ -21,8 +36,13 @@ abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity { if (!pony.getRace(false).isHuman()) { value *= pony.getMetadata().getSize().getEyeHeightFactor(); + + if (hasVehicle()) { + value += getVehicle().getEyeHeight(getVehicle().getPose()); + value -= getVehicle().getMountedHeightOffset(); + } } - return value; + return Math.max(value, 0.3F); } } diff --git a/src/main/java/com/minelittlepony/client/pony/Pony.java b/src/main/java/com/minelittlepony/client/pony/Pony.java index 0cac5cda..ce0382b9 100644 --- a/src/main/java/com/minelittlepony/client/pony/Pony.java +++ b/src/main/java/com/minelittlepony/client/pony/Pony.java @@ -120,7 +120,11 @@ public class Pony implements IPony { protected Vec3d getVisualEyePosition(LivingEntity entity) { Size size = entity.isBaby() ? Size.FOAL : metadata.getSize(); - return new Vec3d(entity.getX(), entity.getY() + (double) entity.getEyeHeight(entity.getPose()) * size.getScaleFactor(), entity.getZ()); + return new Vec3d( + entity.getX(), + entity.getY() + (double) entity.getEyeHeight(entity.getPose()) * size.getScaleFactor(), + entity.getZ() + ); } @Override @@ -184,9 +188,12 @@ public class Pony implements IPony { float delta = MinecraftClient.getInstance().getTickDelta(); + Entity vehicle = entity.getVehicle(); + double vehicleOffset = vehicle == null ? 0 : vehicle.getHeight() - vehicle.getMountedHeightOffset(); + return new Vec3d( MathHelper.lerp(delta, entity.prevX, entity.getX()), - MathHelper.lerp(delta, entity.prevY, entity.getY()), + MathHelper.lerp(delta, entity.prevY, entity.getY()) + vehicleOffset, MathHelper.lerp(delta, entity.prevZ, entity.getZ()) ); }