mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-25 13:57:59 +01:00
Fixed eye position when riding a vehicle
This commit is contained in:
parent
728e2b1a39
commit
d74a853824
2 changed files with 30 additions and 3 deletions
|
@ -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<Boolean> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue