From 32b8c2907378ac6c8fc7737652e87a78c8466e3a Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 26 Aug 2020 15:02:56 +0200 Subject: [PATCH] Fixed parrots on shoulders rendering at the wrong position --- .../entity/feature/PassengerFeature.java | 51 +++++++++++-------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/minelittlepony/client/render/entity/feature/PassengerFeature.java b/src/main/java/com/minelittlepony/client/render/entity/feature/PassengerFeature.java index 250761e8..16ef612d 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/feature/PassengerFeature.java +++ b/src/main/java/com/minelittlepony/client/render/entity/feature/PassengerFeature.java @@ -10,11 +10,14 @@ import net.minecraft.client.util.math.Vector3f; import net.minecraft.entity.EntityType; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.CompoundTag; +import net.minecraft.util.Identifier; import com.minelittlepony.client.model.ClientPonyModel; import com.minelittlepony.client.render.IPonyRenderContext; import com.minelittlepony.model.BodyPart; +import java.util.Optional; + public class PassengerFeature> extends AbstractPonyFeature { private final ParrotEntityModel model = new ParrotEntityModel(); @@ -24,26 +27,34 @@ public class PassengerFeature p == EntityType.PARROT).ifPresent((entityType) -> { - stack.push(); - - getContextModel().transform(BodyPart.BODY, stack); - - stack.translate(left ? 0.25 : -0.25, entity.isInSneakingPose() ? -0.5 : -0.25, 0.35); - stack.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(left ? -5 : 5)); - - VertexConsumer vertexConsumer = renderContext.getBuffer(model.getLayer(ParrotEntityRenderer.TEXTURES[riderTag.getInt("Variant")])); - model.poseOnShoulder(stack, vertexConsumer, lightUv, OverlayTexture.DEFAULT_UV, limbDistance, limbAngle, headYaw, headPitch, entity.age); - stack.pop(); + public void render(MatrixStack stack, VertexConsumerProvider renderContext, int light, T entity, float limbDistance, float limbAngle, float tickDelta, float age, float headYaw, float headPitch) { + getShoulderParrot(entity.getShoulderEntityLeft()).ifPresent(texture -> { + renderShoulderParrot(stack, renderContext, light, entity, limbDistance, limbAngle, headYaw, headPitch, texture, 1); + }); + getShoulderParrot(entity.getShoulderEntityRight()).ifPresent(texture -> { + renderShoulderParrot(stack, renderContext, light, entity, limbDistance, limbAngle, headYaw, headPitch, texture, -1); }); } + + private Optional getShoulderParrot(CompoundTag tag) { + return EntityType.get(tag.getString("id")) + .filter(p -> p == EntityType.PARROT) + .map(type -> ParrotEntityRenderer.TEXTURES[tag.getInt("Variant")]); + } + + private void renderShoulderParrot(MatrixStack stack, VertexConsumerProvider renderContext, int light, T entity, float limbDistance, float limbAngle, float headYaw, float headPitch, Identifier texture, int sigma) { + stack.push(); + + getContextModel().transform(BodyPart.BODY, stack); + + stack.translate( + sigma * 0.25, + entity.isInSneakingPose() ? -0.9 : -1.2, + 0.45); + stack.multiply(Vector3f.NEGATIVE_Z.getDegreesQuaternion(sigma * -5)); + + VertexConsumer buffer = renderContext.getBuffer(model.getLayer(texture)); + model.poseOnShoulder(stack, buffer, light, OverlayTexture.DEFAULT_UV, limbDistance, limbAngle, headYaw, headPitch, entity.age); + stack.pop(); + } }