From dcb8631eb9a98384131b441ace15b628b5b47e37 Mon Sep 17 00:00:00 2001 From: Sollace Date: Tue, 26 Sep 2023 17:57:18 +0100 Subject: [PATCH] The direction a pony's head faces when lying in a bed is now determined by which way you're looking when you climb in --- .../api/model/ModelAttributes.java | 12 +++++++++--- .../minelittlepony/client/PonyManagerImpl.java | 1 - .../client/model/AbstractPonyModel.java | 18 ++++++++++-------- .../model/armour/ArmorModelRegistry.java | 2 +- .../client/model/entity/SkeleponyModel.java | 2 +- .../client/model/entity/race/SeaponyModel.java | 2 +- .../client/model/part/SeaponyTail.java | 2 +- .../client/transform/PonyPosture.java | 2 +- .../client/transform/PonyTransformation.java | 16 ++++++++-------- 9 files changed, 32 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/minelittlepony/api/model/ModelAttributes.java b/src/main/java/com/minelittlepony/api/model/ModelAttributes.java index 410edfe1..8f5c5993 100644 --- a/src/main/java/com/minelittlepony/api/model/ModelAttributes.java +++ b/src/main/java/com/minelittlepony/api/model/ModelAttributes.java @@ -20,6 +20,11 @@ public class ModelAttributes { * True if the model is sleeping in a bed. */ public boolean isSleeping; + + /** + * True if the model is lying down comfortably + */ + public boolean isLyingDown; /** * True if the model is flying like a pegasus. */ @@ -145,9 +150,10 @@ public class ModelAttributes { public void updateLivingState(LivingEntity entity, Pony pony, Mode mode) { visualHeight = entity.getHeight() + 0.125F; isSitting = PonyPosture.isSitting(entity); - isCrouching = !isSitting && mode == Mode.THIRD_PERSON && PonyPosture.isCrouching(pony, entity); - isSleeping = entity.isAlive() && entity.isSleeping(); - isFlying = mode == Mode.THIRD_PERSON && PonyPosture.isFlying(entity); + isSleeping = entity.isAlive() && entity.isSleeping();; + isLyingDown = isSleeping; + isCrouching = !isLyingDown && !isSitting && mode == Mode.THIRD_PERSON && PonyPosture.isCrouching(pony, entity); + isFlying = !isLyingDown && mode == Mode.THIRD_PERSON && PonyPosture.isFlying(entity); isGliding = entity.isFallFlying(); isSwimming = mode == Mode.THIRD_PERSON && PonyPosture.isSwimming(entity); isSwimmingRotated = isSwimming; diff --git a/src/main/java/com/minelittlepony/client/PonyManagerImpl.java b/src/main/java/com/minelittlepony/client/PonyManagerImpl.java index 7eced8d2..d859c77e 100644 --- a/src/main/java/com/minelittlepony/client/PonyManagerImpl.java +++ b/src/main/java/com/minelittlepony/client/PonyManagerImpl.java @@ -50,7 +50,6 @@ public class PonyManagerImpl implements PonyManager, SimpleSynchronousResourceRe @Override public Pony getPony(PlayerEntity player) { - clearCache(); return getPony(getSkin(player), player instanceof ForcedPony ? null : player.getGameProfile() == null ? player.getUuid() : player.getGameProfile().getId()); } diff --git a/src/main/java/com/minelittlepony/client/model/AbstractPonyModel.java b/src/main/java/com/minelittlepony/client/model/AbstractPonyModel.java index 8f3b3b96..b9d2afc9 100644 --- a/src/main/java/com/minelittlepony/client/model/AbstractPonyModel.java +++ b/src/main/java/com/minelittlepony/client/model/AbstractPonyModel.java @@ -119,11 +119,10 @@ public abstract class AbstractPonyModel extends ClientPo } protected void setModelAngles(T entity, float limbAngle, float limbSpeed, float animationProgress, float headYaw, float headPitch) { - - float pitch = (float)Math.toRadians(attributes.motionPitch); + float pitch = attributes.motionPitch * MathHelper.RADIANS_PER_DEGREE; head.setAngles( MathHelper.clamp(attributes.isSleeping ? 0.1f : headPitch / 57.29578F, -1.25f - pitch, 0.5f - pitch), - attributes.isSleeping ? (Math.abs(entity.getUuid().getMostSignificantBits()) % 2.8F) - 1.9F : headYaw / 57.29578F, + attributes.isSleeping ? (Math.signum(MathHelper.wrapDegrees(headYaw)) * 1.3F) : headYaw * MathHelper.RADIANS_PER_DEGREE, 0 ); @@ -149,7 +148,7 @@ public abstract class AbstractPonyModel extends ClientPo } else { adjustBody(0, ORIGIN); - if (!attributes.isSleeping) { + if (!attributes.isLyingDown) { animateBreathing(animationProgress); } @@ -159,7 +158,7 @@ public abstract class AbstractPonyModel extends ClientPo } } - if (attributes.isSleeping) { + if (attributes.isLyingDown) { ponySleep(); } @@ -197,7 +196,6 @@ public abstract class AbstractPonyModel extends ClientPo leftLeg.pitch = MathUtil.Angles._90_DEG; HEAD_SLEEPING.set(head); - head.pivotZ = sneaking ? -1 : 1; FONT_LEGS_SLEEPING.add(rightArm); FONT_LEGS_SLEEPING.add(leftArm); @@ -341,7 +339,7 @@ public abstract class AbstractPonyModel extends ClientPo } protected float getLegOutset() { - if (attributes.isSleeping) { + if (attributes.isLyingDown) { return 3.6f; } @@ -491,7 +489,7 @@ public abstract class AbstractPonyModel extends ClientPo * @param entity The entity we are being called for. */ protected void swingItem(T entity) { - if (getSwingAmount() > 0 && !attributes.isSleeping) { + if (getSwingAmount() > 0 && !attributes.isLyingDown) { Arm mainSide = getPreferredArm(entity); swingArm(getArm(mainSide)); @@ -624,6 +622,10 @@ public abstract class AbstractPonyModel extends ClientPo stack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180)); } + if (attributes.isLyingDown && !attributes.isSleeping) { + stack.translate(0, 1.35F, 0); + } + if (attributes.isHorsey) { if (part == BodyPart.BODY) { stack.scale(1.5F, 1, 1.5F); diff --git a/src/main/java/com/minelittlepony/client/model/armour/ArmorModelRegistry.java b/src/main/java/com/minelittlepony/client/model/armour/ArmorModelRegistry.java index eb277e84..8eaeb1ec 100644 --- a/src/main/java/com/minelittlepony/client/model/armour/ArmorModelRegistry.java +++ b/src/main/java/com/minelittlepony/client/model/armour/ArmorModelRegistry.java @@ -17,7 +17,7 @@ public interface ArmorModelRegistry { if (id.getNamespace().equals("minecraft")) { return Optional.empty(); } - return REGISTRY.computeIfAbsent(id.withPath(p -> "models/armor/" + layer.name().toLowerCase(Locale.ROOT) + "_" + p + ".json"), i -> { + return REGISTRY.computeIfAbsent(id.withPath(p -> "armor/" + layer.name().toLowerCase(Locale.ROOT) + "_" + p + ".json"), i -> { return Optional.of(Mson.getInstance().registerModel(i, PonyArmourModel::new)); }).filter(key -> key.getModelData().isPresent()); } diff --git a/src/main/java/com/minelittlepony/client/model/entity/SkeleponyModel.java b/src/main/java/com/minelittlepony/client/model/entity/SkeleponyModel.java index 6e99f3ab..7da3aea1 100644 --- a/src/main/java/com/minelittlepony/client/model/entity/SkeleponyModel.java +++ b/src/main/java/com/minelittlepony/client/model/entity/SkeleponyModel.java @@ -78,7 +78,7 @@ public class SkeleponyModel extends AlicornModel { @Override protected float getLegOutset() { - if (attributes.isSleeping) return 2.6f; + if (attributes.isLyingDown) return 2.6f; if (attributes.isCrouching) return 0; return 4; } diff --git a/src/main/java/com/minelittlepony/client/model/entity/race/SeaponyModel.java b/src/main/java/com/minelittlepony/client/model/entity/race/SeaponyModel.java index 47959c2d..dd95f528 100644 --- a/src/main/java/com/minelittlepony/client/model/entity/race/SeaponyModel.java +++ b/src/main/java/com/minelittlepony/client/model/entity/race/SeaponyModel.java @@ -65,7 +65,7 @@ public class SeaponyModel extends UnicornModel { float flapMotion = MathHelper.cos(ticks / 10) / 5; - if (attributes.isSleeping) { + if (attributes.isLyingDown) { flapMotion /= 2; } diff --git a/src/main/java/com/minelittlepony/client/model/part/SeaponyTail.java b/src/main/java/com/minelittlepony/client/model/part/SeaponyTail.java index f5e1d2ed..6b311f2d 100644 --- a/src/main/java/com/minelittlepony/client/model/part/SeaponyTail.java +++ b/src/main/java/com/minelittlepony/client/model/part/SeaponyTail.java @@ -23,7 +23,7 @@ public class SeaponyTail implements SubModel, MsonModel { @Override public void setPartAngles(ModelAttributes attributes, float limbAngle, float limbSpeed, float bodySwing, float animationProgress) { - float rotation = attributes.isSleeping ? 0 : MathHelper.sin(animationProgress * 0.536f) / 4; + float rotation = attributes.isLyingDown ? 0 : MathHelper.sin(animationProgress * 0.536f) / 4; tailBase.pitch = MathHelper.HALF_PI + rotation; tailTip.pitch = rotation; diff --git a/src/main/java/com/minelittlepony/client/transform/PonyPosture.java b/src/main/java/com/minelittlepony/client/transform/PonyPosture.java index 80790ec4..08f46c4b 100644 --- a/src/main/java/com/minelittlepony/client/transform/PonyPosture.java +++ b/src/main/java/com/minelittlepony/client/transform/PonyPosture.java @@ -29,7 +29,7 @@ public interface PonyPosture { return ELYTRA; } - if (attributes.isSleeping) { + if (attributes.isLyingDown) { return STANDING; } diff --git a/src/main/java/com/minelittlepony/client/transform/PonyTransformation.java b/src/main/java/com/minelittlepony/client/transform/PonyTransformation.java index 63b29976..242d694b 100644 --- a/src/main/java/com/minelittlepony/client/transform/PonyTransformation.java +++ b/src/main/java/com/minelittlepony/client/transform/PonyTransformation.java @@ -20,7 +20,7 @@ public enum PonyTransformation { public void transform(PonyModel model, BodyPart part, MatrixStack stack) { if (model.getAttributes().isSwimming) stack.translate(0, -0.3F, 0); if (model.getAttributes().isCrouching) stack.translate(0, -0.2F, 0); - if (model.getAttributes().isSleeping) stack.translate(0, -0.61F, 0.1F); + if (model.getAttributes().isLyingDown) stack.translate(0, -0.61F, 0.1F); if (model.getAttributes().isSitting) stack.translate(0, -0.2F, -0.2F); switch (part) { @@ -42,7 +42,7 @@ public enum PonyTransformation { public void transform(PonyModel model, BodyPart part, MatrixStack stack) { if (model.getAttributes().isSwimming) stack.translate(0, -0.2F, 0); if (model.getAttributes().isCrouching) stack.translate(0, -0.15F, 0); - if (model.getAttributes().isSleeping) stack.translate(0, -0.6F, 0.15F); + if (model.getAttributes().isLyingDown) stack.translate(0, -0.6F, 0.15F); if (model.getAttributes().isSitting) stack.translate(0, 0, -0.2F); switch (part) { @@ -53,7 +53,7 @@ public enum PonyTransformation { break; case HEAD: stack.translate(0, -0.14F, -0.04F); - if (model.getAttributes().isSleeping) stack.translate(0, 0, -0.1F); + if (model.getAttributes().isLyingDown) stack.translate(0, 0, -0.1F); if (model.getAttributes().isCrouching) stack.translate(0, 0.15F, 0); break; case BODY: @@ -77,7 +77,7 @@ public enum PonyTransformation { @Override public void transform(PonyModel model, BodyPart part, MatrixStack stack) { if (model.getAttributes().isCrouching) stack.translate(0, -0.15F, 0); - if (model.getAttributes().isSleeping) stack.translate(0, -0.6F, 0.25F); + if (model.getAttributes().isLyingDown) stack.translate(0, -0.6F, 0.25F); if (model.getAttributes().isSitting) stack.translate(0, 0, -0.2F); switch (part) { @@ -88,7 +88,7 @@ public enum PonyTransformation { break; case HEAD: stack.translate(0, -0.14F, -0.06F); - if (model.getAttributes().isSleeping) stack.translate(0, 0, -0.1F); + if (model.getAttributes().isLyingDown) stack.translate(0, 0, -0.1F); if (model.getAttributes().isCrouching) stack.translate(0, 0.15F, 0); break; case BODY: @@ -113,7 +113,7 @@ public enum PonyTransformation { public void transform(PonyModel model, BodyPart part, MatrixStack stack) { if (model.getAttributes().isSwimming) stack.translate(0, -0.9F, 0); if (model.getAttributes().isCrouching) stack.translate(0, -0.2F, 0); - if (model.getAttributes().isSleeping) stack.translate(0, -0.8F, -0.3F); + if (model.getAttributes().isLyingDown) stack.translate(0, -0.8F, -0.3F); if (model.getAttributes().isSitting) stack.translate(0, -0.6F, -0.2F); stack.translate(0, 0.2F, 0); @@ -142,7 +142,7 @@ public enum PonyTransformation { @Override public void transform(PonyModel model, BodyPart part, MatrixStack stack) { if (model.getAttributes().isCrouching) stack.translate(0, -0.15F, 0); - if (model.getAttributes().isSleeping) stack.translate(0, -0.5F, 0.35F); + if (model.getAttributes().isLyingDown) stack.translate(0, -0.5F, 0.35F); if (model.getAttributes().isSitting) stack.translate(0, 0.1F, -0.2F); switch (part) { @@ -175,7 +175,7 @@ public enum PonyTransformation { public void transform(PonyModel model, BodyPart part, MatrixStack stack) { if (model.getAttributes().isSwimming) stack.translate(0, -0.6F, 0); if (model.getAttributes().isCrouching) stack.translate(0, -0.15F, 0); - if (model.getAttributes().isSleeping) stack.translate(0, -0.45F, -0.3F); + if (model.getAttributes().isLyingDown) stack.translate(0, -0.45F, -0.3F); if (model.getAttributes().isSitting) stack.translate(0, -0.4F, -0.2F); switch (part) {