From c7ea57c2b6c424ae25824246cf7254ae68dc37e3 Mon Sep 17 00:00:00 2001 From: Sollace Date: Mon, 1 Mar 2021 00:16:39 +0200 Subject: [PATCH] Separate wing angle and whether a model is horizontal into separate model attributes --- gradle.properties | 2 +- .../client/model/AbstractPonyModel.java | 2 +- .../client/render/EquineRenderManager.java | 6 ++-- .../client/transform/PonyPosture.java | 4 +-- .../com/minelittlepony/model/IPegasus.java | 13 +------- .../minelittlepony/model/ModelAttributes.java | 30 +++++++++++++++++-- 6 files changed, 36 insertions(+), 21 deletions(-) diff --git a/gradle.properties b/gradle.properties index 5b0a861c..a940d5aa 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ org.gradle.daemon=false displayname=Mine Little Pony authors=Verdana, Rene_Z, Mumfrey, Killjoy1221, Sollace description=Mine Little Pony turns players and mobs into ponies. Press F9 ingame to access settings. - version=4.2.1 + version=4.2.2 release=SNAPSHOT # Dependencies diff --git a/src/main/java/com/minelittlepony/client/model/AbstractPonyModel.java b/src/main/java/com/minelittlepony/client/model/AbstractPonyModel.java index 5fb1915e..2dec0543 100644 --- a/src/main/java/com/minelittlepony/client/model/AbstractPonyModel.java +++ b/src/main/java/com/minelittlepony/client/model/AbstractPonyModel.java @@ -68,7 +68,7 @@ public abstract class AbstractPonyModel extends ClientPo */ @Override public void setAngles(T entity, float move, float swing, float ticks, float headYaw, float headPitch) { - attributes.checkRainboom(entity, swing, canFly()); + attributes.checkRainboom(entity, swing, canFly(), ticks); PonyModelPrepareCallback.EVENT.invoker().onPonyModelPrepared(entity, this, EquineRenderManager.Mode.OTHER); super.setAngles(entity, move, swing, ticks, headYaw, headPitch); diff --git a/src/main/java/com/minelittlepony/client/render/EquineRenderManager.java b/src/main/java/com/minelittlepony/client/render/EquineRenderManager.java index cdf44ca1..f87027f7 100644 --- a/src/main/java/com/minelittlepony/client/render/EquineRenderManager.java +++ b/src/main/java/com/minelittlepony/client/render/EquineRenderManager.java @@ -114,15 +114,15 @@ public class EquineRenderManager { - PonyPosture DEFAULT = new PostureStanding();; + PonyPosture STANDING = new PostureStanding();; PonyPosture ELYTRA = new PostureElytra(); - PonyPosture FLIGHT = new PostureFlight(); + PonyPosture FLYING = new PostureFlight(); PonyPosture SWIMMING = new PostureSwimming(); PonyPosture FALLING = new PostureFalling(); diff --git a/src/main/java/com/minelittlepony/model/IPegasus.java b/src/main/java/com/minelittlepony/model/IPegasus.java index 0d3ff076..0c2c7dd9 100644 --- a/src/main/java/com/minelittlepony/model/IPegasus.java +++ b/src/main/java/com/minelittlepony/model/IPegasus.java @@ -1,10 +1,5 @@ package com.minelittlepony.model; -import net.minecraft.util.math.MathHelper; - -import static com.minelittlepony.model.PonyModelConstants.ROTATE_270; -import static com.minelittlepony.model.PonyModelConstants.WING_ROT_Z_SNEAK; - public interface IPegasus extends IModel { /** @@ -25,13 +20,7 @@ public interface IPegasus extends IModel { * @param ticks Partial render ticks */ default float getWingRotationFactor(float ticks) { - if (getAttributes().isSwimming) { - return (MathHelper.sin(ticks * 0.136f) / 2) + ROTATE_270; - } - if (isFlying()) { - return MathHelper.sin(ticks * 0.536f) + ROTATE_270 + 0.4f; - } - return WING_ROT_Z_SNEAK; + return getAttributes().wingAngle; } } diff --git a/src/main/java/com/minelittlepony/model/ModelAttributes.java b/src/main/java/com/minelittlepony/model/ModelAttributes.java index 63a6383b..270ff8f4 100644 --- a/src/main/java/com/minelittlepony/model/ModelAttributes.java +++ b/src/main/java/com/minelittlepony/model/ModelAttributes.java @@ -8,10 +8,14 @@ import com.minelittlepony.util.MathUtil; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.Arm; +import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import java.util.UUID; +import static com.minelittlepony.model.PonyModelConstants.ROTATE_270; +import static com.minelittlepony.model.PonyModelConstants.WING_ROT_Z_SNEAK; + public class ModelAttributes { /** @@ -27,6 +31,10 @@ public class ModelAttributes { * from regular flying in that there are actual "wings" involved. */ public boolean isGliding; + /** + * True if the model is rotated 90degs (players) + */ + public boolean isHorizontal; /** * True if the model is swimming under water. */ @@ -79,10 +87,15 @@ public class ModelAttributes { */ public float visualHeight = 2F; + /** + * The angle used to animate wing flaps whilst flying/swimming. + */ + public float wingAngle; + /** * Checks flying and speed conditions and sets rainboom to true if we're a species with wings and is going faaast. */ - public void checkRainboom(T entity, float swing, boolean hasWings) { + public void checkRainboom(T entity, float swing, boolean hasWings, float ticks) { Vec3d motion = entity.getVelocity(); double zMotion = Math.sqrt(motion.x * motion.x + motion.z * motion.z); @@ -90,6 +103,18 @@ public class ModelAttributes { isGoingFast &= zMotion > 0.4F; motionLerp = MathUtil.clampLimit(zMotion * 30, 1); + + wingAngle = calcWingRotationFactor(ticks); + } + + private float calcWingRotationFactor(float ticks) { + if (isSwimming) { + return (MathHelper.sin(ticks * 0.136f) / 2) + ROTATE_270; + } + if (isFlying) { + return MathHelper.sin(ticks * 0.536f) + ROTATE_270 + 0.4f; + } + return WING_ROT_Z_SNEAK; } public void updateLivingState(T entity, IPony pony, EquineRenderManager.Mode mode) { @@ -99,7 +124,8 @@ public class ModelAttributes { isFlying = mode == Mode.THIRD_PERSON && pony.isFlying(entity); isGliding = entity.isFallFlying(); isSwimming = mode == Mode.THIRD_PERSON && pony.isSwimming(entity); - isSwimmingRotated = mode == Mode.THIRD_PERSON && isSwimming && (entity instanceof PlayerEntity || entity instanceof IRotatedSwimmer); + isSwimmingRotated = isSwimming && (entity instanceof PlayerEntity || entity instanceof IRotatedSwimmer); + isHorizontal = isSwimming; isRidingInteractive = pony.isRidingInteractive(entity); interpolatorId = entity.getUuid(); isLeftHanded = entity.getMainArm() == Arm.LEFT;