Fixed eye position when riding a vehicle

This commit is contained in:
Sollace 2020-11-26 20:58:24 +02:00
parent 728e2b1a39
commit d74a853824
2 changed files with 30 additions and 3 deletions

View file

@ -5,14 +5,29 @@ import com.minelittlepony.client.MineLittlePony;
import net.minecraft.client.network.AbstractClientPlayerEntity; import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityDimensions; import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityPose; import net.minecraft.entity.EntityPose;
import org.spongepowered.asm.mixin.Mixin; 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) @Mixin(ClientPlayerEntity.class)
abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity { abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity {
public MixinClientPlayerEntity() { super(null, null); } 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<Boolean> info) {
calculateDimensions();
}
@Override
public void stopRiding() {
super.stopRiding();
calculateDimensions();
}
@Override @Override
public float getActiveEyeHeight(EntityPose pose, EntityDimensions dimensions) { public float getActiveEyeHeight(EntityPose pose, EntityDimensions dimensions) {
float value = super.getActiveEyeHeight(pose, dimensions); float value = super.getActiveEyeHeight(pose, dimensions);
@ -21,8 +36,13 @@ abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity {
if (!pony.getRace(false).isHuman()) { if (!pony.getRace(false).isHuman()) {
value *= pony.getMetadata().getSize().getEyeHeightFactor(); value *= pony.getMetadata().getSize().getEyeHeightFactor();
if (hasVehicle()) {
value += getVehicle().getEyeHeight(getVehicle().getPose());
value -= getVehicle().getMountedHeightOffset();
}
} }
return value; return Math.max(value, 0.3F);
} }
} }

View file

@ -120,7 +120,11 @@ public class Pony implements IPony {
protected Vec3d getVisualEyePosition(LivingEntity entity) { protected Vec3d getVisualEyePosition(LivingEntity entity) {
Size size = entity.isBaby() ? Size.FOAL : metadata.getSize(); 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 @Override
@ -184,9 +188,12 @@ public class Pony implements IPony {
float delta = MinecraftClient.getInstance().getTickDelta(); float delta = MinecraftClient.getInstance().getTickDelta();
Entity vehicle = entity.getVehicle();
double vehicleOffset = vehicle == null ? 0 : vehicle.getHeight() - vehicle.getMountedHeightOffset();
return new Vec3d( return new Vec3d(
MathHelper.lerp(delta, entity.prevX, entity.getX()), 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()) MathHelper.lerp(delta, entity.prevZ, entity.getZ())
); );
} }