Properly position the held entity in first person view

This commit is contained in:
Sollace 2022-12-26 21:37:23 +01:00
parent 0488c7a051
commit 25044b6f69

View file

@ -26,26 +26,13 @@ public class HeldEntityFeatureRenderer<E extends LivingEntity> implements Access
@Override
public void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, E entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
Pony.of(entity).flatMap(Pony::getEntityInArms).ifPresent(passenger -> {
Living<E> l = Living.living(entity);
Vec3d carryPosition = getCarryPosition(l, passenger);
LivingEntity p = passenger.asEntity();
@SuppressWarnings("unchecked")
EntityRenderer<LivingEntity> renderer = (EntityRenderer<LivingEntity>)MinecraftClient.getInstance().getEntityRenderDispatcher().getRenderer(p);
float f = tickDelta;
matrices.push();
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(180));
float leanAmount = ((LivingEntityDuck)entity).getLeaningPitch();
//matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(leanAmount * 0));
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-leanAmount * 90));
matrices.push();
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(180 - leanAmount * 90));
carryPosition = carryPosition.rotateX(-leanAmount * MathHelper.PI / 4F)
Vec3d carryPosition = getCarryPosition(Living.living(entity), passenger)
.rotateX(-leanAmount * MathHelper.PI / 4F)
.add(new Vec3d(0, -0.5F, 0).multiply(leanAmount));
matrices.translate(carryPosition.x, carryPosition.y, carryPosition.z);
@ -53,36 +40,48 @@ public class HeldEntityFeatureRenderer<E extends LivingEntity> implements Access
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(90));
}
float oldYaw = entity.bodyYaw;
float prevOldYaw = entity.prevBodyYaw;
entity.bodyYaw = 0;
entity.prevBodyYaw = 0;
Entity vehicle = p.getVehicle();
((EntityDuck)p).setVehicle(null);
p.prevBodyYaw = 0;
p.bodyYaw = 0;
p.headYaw = 0;
p.prevHeadYaw = 0;
p.prevYaw = 0;
p.setYaw(0);
p.setBodyYaw(0);
renderer.render(p, 0, f, matrices, vertexConsumers, light);
entity.bodyYaw = oldYaw;
entity.prevBodyYaw = prevOldYaw;
((EntityDuck)p).setVehicle(vehicle);
renderCarriedEntity(passenger.asEntity(), matrices, vertexConsumers, light, tickDelta);
matrices.pop();
});
}
@Override
public void renderArm(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, E entity, ModelPart arm, Arm side) {
render(matrices, vertexConsumers, light, entity, 0, 0, 0, 0, 0, 0);
Pony.of(entity).flatMap(Pony::getEntityInArms).ifPresent(passenger -> {
float tickDelta = MinecraftClient.getInstance().getTickDelta();
matrices.push();
matrices.translate(0.8F, 0.4F, -0.1F);
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(90));
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-60 - 13));
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(-30));
matrices.translate(0, 0, -0.2F);
if (!(passenger instanceof Pony)) {
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(90));
}
matrices.translate(-passenger.asEntity().getWidth() / 16F, 0.3F, 0);
renderCarriedEntity(passenger.asEntity(), matrices, vertexConsumers, light, tickDelta);
matrices.pop();
});
}
private void renderCarriedEntity(LivingEntity p, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, float tickDelta) {
Entity vehicle = p.getVehicle();
((EntityDuck)p).setVehicle(null);
p.prevBodyYaw = 0;
p.bodyYaw = 0;
p.headYaw = 0;
p.prevHeadYaw = 0;
p.prevYaw = 0;
p.setYaw(0);
p.setBodyYaw(0);
@SuppressWarnings("unchecked")
EntityRenderer<LivingEntity> renderer = (EntityRenderer<LivingEntity>)MinecraftClient.getInstance().getEntityRenderDispatcher().getRenderer(p);
renderer.render(p, 0, tickDelta, matrices, vertexConsumers, light);
((EntityDuck)p).setVehicle(vehicle);
}
protected Vec3d getCarryPosition(Living<E> entity, Living<?> passenger) {