From 5686608969d1a2f46688f72fc12ad2cc16e5a86e Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 10 May 2018 18:24:27 +0200 Subject: [PATCH] Decompose ModelAlicorn into its constituents --- .../model/AbstractPonyModel.java | 38 ++-- .../model/capabilities/IModel.java | 15 ++ .../model/capabilities/IModelPegasus.java | 9 +- .../model/player/ModelAlicorn.java | 152 ++-------------- .../model/player/ModelPegasus.java | 53 +----- .../model/player/ModelUnicorn.java | 164 ++++++++++++++++++ .../render/player/RenderPonyBase.java | 2 +- 7 files changed, 224 insertions(+), 209 deletions(-) create mode 100644 src/main/java/com/minelittlepony/model/player/ModelUnicorn.java diff --git a/src/main/java/com/minelittlepony/model/AbstractPonyModel.java b/src/main/java/com/minelittlepony/model/AbstractPonyModel.java index 4a7b15b3..7372ae7f 100644 --- a/src/main/java/com/minelittlepony/model/AbstractPonyModel.java +++ b/src/main/java/com/minelittlepony/model/AbstractPonyModel.java @@ -52,7 +52,7 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { /** * Flag indicating that this model is performing a rainboom (flight). */ - public boolean rainboom; + protected boolean rainboom; public PlaneRenderer upperTorso; public PlaneRenderer neck; @@ -69,6 +69,13 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { return new PonyArmor(new ModelPonyArmor(), new ModelPonyArmor()); } + /** + * Checks flying and speed conditions and sets rainboom to true if we're a species with wings and is going faaast. + */ + protected void checkRainboom(Entity entity, float swing) { + rainboom = canFly() && isFlying(entity) && swing >= 0.9999F; + } + /** * Sets the model's various rotation angles. * @@ -82,6 +89,8 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { */ @Override public void setRotationAngles(float move, float swing, float ticks, float headYaw, float headPitch, float scale, Entity entity) { + checkRainboom(entity, swing); + super.setRotationAngles(move, swing, ticks, headYaw, headPitch, scale, entity); float headRotateAngleY = isSleeping ? 1.4f : headYaw / 57.29578F; @@ -100,7 +109,9 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { rotateLook(move, swing, bodySwingRotation, ticks); setLegs(move, swing, ticks, entity); - holdItem(swing); + if (!rainboom) { + holdItem(swing); + } swingItem(entity); if (isCrouching()) { @@ -224,8 +235,8 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { * */ protected void rotateLegsInFlight(float move, float swing, float ticks, Entity entity) { - float armX = MathHelper.sin(-swing / 2); - float legX = MathHelper.sin(swing / 2); + float armX = rainboom ? ROTATE_270 : MathHelper.sin(-swing / 2); + float legX = rainboom ? ROTATE_90 : MathHelper.sin(swing / 2); bipedLeftArm.rotateAngleX = armX; bipedRightArm.rotateAngleX = armX; @@ -655,23 +666,26 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { } @Override - public boolean isCrouching() { - return isSneak && !isFlying; + public IPonyData getMetadata() { + return metadata; } - /** - * Checks flying and speed conditions and sets rainboom to true if we're a species with wings and is going faaast. - */ - protected void checkRainboom(Entity entity, float swing) { - rainboom = isFlying(entity) && swing >= 0.9999F; + @Override + public boolean isCrouching() { + return !rainboom && isSneak && !isFlying; } @Override public boolean isFlying(Entity entity) { - return (isFlying && metadata.getRace().hasWings()) || + return (isFlying && canFly()) || (entity instanceof EntityLivingBase && ((EntityLivingBase) entity).isElytraFlying()); } + @Override + public boolean isGoingFast() { + return rainboom; + } + @Override public boolean isFlying() { return isFlying; diff --git a/src/main/java/com/minelittlepony/model/capabilities/IModel.java b/src/main/java/com/minelittlepony/model/capabilities/IModel.java index acc4e84c..38638a93 100644 --- a/src/main/java/com/minelittlepony/model/capabilities/IModel.java +++ b/src/main/java/com/minelittlepony/model/capabilities/IModel.java @@ -2,6 +2,7 @@ package com.minelittlepony.model.capabilities; import com.minelittlepony.model.BodyPart; import com.minelittlepony.model.armour.PonyArmor; +import com.minelittlepony.pony.data.IPonyData; import net.minecraft.entity.Entity; @@ -25,6 +26,8 @@ public interface IModel { */ PonyArmor createArmour(); + IPonyData getMetadata(); + /** * Returns true if this model is on the ground and crouching. */ @@ -40,6 +43,18 @@ public interface IModel { */ boolean isFlying(); + /** + * Returns true if we're flying really fast. + */ + boolean isGoingFast(); + + /** + * Returns true if this model is being applied to a race that has wings. + */ + default boolean canFly() { + return getMetadata().getRace().hasWings(); + } + /** * Returns true if the current model is a child or a child-like foal. */ diff --git a/src/main/java/com/minelittlepony/model/capabilities/IModelPegasus.java b/src/main/java/com/minelittlepony/model/capabilities/IModelPegasus.java index c2edccdb..e344b2cf 100644 --- a/src/main/java/com/minelittlepony/model/capabilities/IModelPegasus.java +++ b/src/main/java/com/minelittlepony/model/capabilities/IModelPegasus.java @@ -4,10 +4,7 @@ public interface IModelPegasus extends IModel { /** * Returns true if the wings are spread. */ - boolean wingsAreOpen(); - - /** - * Returns true if this model is being applied to a race that has wings. - */ - boolean canFly(); + default boolean wingsAreOpen() { + return isFlying() || isCrouching(); + } } diff --git a/src/main/java/com/minelittlepony/model/player/ModelAlicorn.java b/src/main/java/com/minelittlepony/model/player/ModelAlicorn.java index 5350c5fb..68d341b5 100644 --- a/src/main/java/com/minelittlepony/model/player/ModelAlicorn.java +++ b/src/main/java/com/minelittlepony/model/player/ModelAlicorn.java @@ -1,24 +1,13 @@ package com.minelittlepony.model.player; -import com.minelittlepony.model.components.UnicornHorn; -import com.minelittlepony.render.PonyRenderer; +import com.minelittlepony.model.components.PegasusWings; import net.minecraft.entity.Entity; -import net.minecraft.util.EnumHandSide; -import net.minecraft.util.math.MathHelper; -import com.minelittlepony.model.capabilities.IModelUnicorn; +import com.minelittlepony.model.capabilities.IModelPegasus; -import static com.minelittlepony.model.PonyModelConstants.*; +public class ModelAlicorn extends ModelUnicorn implements IModelPegasus { -/** - * Used for both unicorns and alicorns since there's no logical way to keep them distinct and not duplicate stuff. - */ -public class ModelAlicorn extends ModelPegasus implements IModelUnicorn { - - public PonyRenderer unicornArmRight; - public PonyRenderer unicornArmLeft; - - public UnicornHorn horn; + public PegasusWings wings; public ModelAlicorn(boolean smallArms) { super(smallArms); @@ -27,138 +16,23 @@ public class ModelAlicorn extends ModelPegasus implements IModelUnicorn { @Override public void init(float yOffset, float stretch) { super.init(yOffset, stretch); - horn = new UnicornHorn(this, yOffset, stretch); + wings = new PegasusWings(this, yOffset, stretch); } @Override - protected void rotateLegsOnGround(float move, float swing, float ticks, Entity entity) { - super.rotateLegsOnGround(move, swing, ticks, entity); + public void setRotationAngles(float move, float swing, float ticks, float headYaw, float headPitch, float scale, Entity entity) { + super.setRotationAngles(move, swing, ticks, headYaw, headPitch, scale, entity); - unicornArmRight.rotateAngleY = 0; - unicornArmLeft.rotateAngleY = 0; - } - - @Override - protected void adjustLegs(float move, float swing, float ticks) { - super.adjustLegs(move, swing, ticks); - - unicornArmLeft.rotateAngleZ = 0; - unicornArmRight.rotateAngleZ = 0; - - unicornArmLeft.rotateAngleX = 0; - unicornArmRight.rotateAngleX = 0; - } - - @Override - protected void holdItem(float swing) { - if (canCast()) { - boolean both = leftArmPose == ArmPose.ITEM && rightArmPose == ArmPose.ITEM; - - alignArmForAction(unicornArmLeft, leftArmPose, both, swing); - alignArmForAction(unicornArmRight, rightArmPose, both, swing); - } else { - super.holdItem(swing); + if (canFly()) { + wings.setRotationAngles(move, swing, ticks); } } @Override - protected void swingItem(Entity entity) { - EnumHandSide mainSide = getMainHand(entity); - - if (canCast() && getArmPoseForSide(mainSide) != ArmPose.EMPTY) { - if (swingProgress > -9990.0F && !isSleeping) { - swingArm(getUnicornArmForSide(mainSide)); - } - } else { - super.swingItem(entity); + protected void renderBody(Entity entity, float move, float swing, float ticks, float headYaw, float headPitch, float scale) { + super.renderBody(entity, move, swing, ticks, headYaw, headPitch, scale); + if (canFly()) { + wings.render(scale); } } - - @Override - protected void swingArms(float ticks) { - if (isSleeping) return; - - if (canCast()) { - float cos = MathHelper.cos(ticks * 0.09F) * 0.05F + 0.05F; - float sin = MathHelper.sin(ticks * 0.067F) * 0.05F; - - if (rightArmPose != ArmPose.EMPTY) { - unicornArmRight.rotateAngleZ += cos; - unicornArmRight.rotateAngleX += sin; - } - - if (leftArmPose != ArmPose.EMPTY) { - unicornArmLeft.rotateAngleZ += cos; - unicornArmLeft.rotateAngleX += sin; - } - } else { - super.swingArms(ticks); - } - } - - @Override - public PonyRenderer getUnicornArmForSide(EnumHandSide side) { - return side == EnumHandSide.LEFT ? unicornArmLeft : unicornArmRight; - } - - @Override - public boolean canCast() { - return metadata.hasMagic(); - } - - @Override - public boolean isCasting() { - return rightArmPose != ArmPose.EMPTY || leftArmPose != ArmPose.EMPTY; - } - - @Override - public int getMagicColor() { - return metadata.getGlowColor(); - } - - @Override - protected void sneakLegs() { - super.sneakLegs(); - unicornArmRight.rotateAngleX += SNEAK_LEG_X_ROTATION_ADJUSTMENT; - unicornArmLeft.rotateAngleX += SNEAK_LEG_X_ROTATION_ADJUSTMENT; - } - - @Override - protected void aimBow(ArmPose leftArm, ArmPose rightArm, float ticks) { - if (canCast()) { - if (rightArm == ArmPose.BOW_AND_ARROW) aimBowPony(unicornArmRight, ticks); - if (leftArm == ArmPose.BOW_AND_ARROW) aimBowPony(unicornArmLeft, ticks); - } else { - super.aimBow(leftArm, rightArm, ticks); - } - } - - @Override - protected void renderHead(Entity entity, float move, float swing, float ticks, float headYaw, float headPitch, float scale) { - super.renderHead(entity, move, swing, ticks, headYaw, headPitch, scale); - - if (canCast()) { - horn.render(scale); - if (isCasting()) { - horn.renderMagic(getMagicColor(), scale); - } - } - } - - @Override - protected void initLegTextures() { - super.initLegTextures(); - unicornArmLeft = new PonyRenderer(this, 40, 32).size(64, 64); - unicornArmRight = new PonyRenderer(this, 40, 32).size(64, 64); - } - - @Override - protected void initLegPositions(float yOffset, float stretch) { - super.initLegPositions(yOffset, stretch); - float armY = THIRDP_ARM_CENTRE_Y - 6; - float armZ = THIRDP_ARM_CENTRE_Z - 2; - - unicornArmLeft .box(FIRSTP_ARM_CENTRE_X - 2, armY, armZ, 4, 12, 4, stretch + .25F).around(5, yOffset + 2, 0); - unicornArmRight.box(FIRSTP_ARM_CENTRE_X - 2, armY, armZ, 4, 12, 4, stretch + .25F).around(-5, yOffset + 2, 0); - } } diff --git a/src/main/java/com/minelittlepony/model/player/ModelPegasus.java b/src/main/java/com/minelittlepony/model/player/ModelPegasus.java index 8fdadfb0..b24e9d7e 100644 --- a/src/main/java/com/minelittlepony/model/player/ModelPegasus.java +++ b/src/main/java/com/minelittlepony/model/player/ModelPegasus.java @@ -3,8 +3,6 @@ package com.minelittlepony.model.player; import com.minelittlepony.model.components.PegasusWings; import net.minecraft.entity.Entity; -import static com.minelittlepony.model.PonyModelConstants.*; - import com.minelittlepony.model.capabilities.IModelPegasus; public class ModelPegasus extends ModelEarthPony implements IModelPegasus { @@ -21,62 +19,15 @@ public class ModelPegasus extends ModelEarthPony implements IModelPegasus { wings = new PegasusWings(this, yOffset, stretch); } - @Override - public boolean isCrouching() { - return super.isCrouching() && !rainboom; - } - @Override public void setRotationAngles(float move, float swing, float ticks, float headYaw, float headPitch, float scale, Entity entity) { - checkRainboom(entity, swing); - super.setRotationAngles(move, swing, ticks, headYaw, headPitch, scale, entity); - - if (bipedCape != null) { - wings.setRotationAngles(move, swing, ticks); - } - } - - @Override - protected void rotateLegsInFlight(float move, float swing, float ticks, Entity entity) { - if (rainboom) { - bipedLeftArm.rotateAngleX = ROTATE_270; - bipedRightArm.rotateAngleX = ROTATE_270; - - bipedLeftLeg.rotateAngleX = ROTATE_90; - bipedRightLeg.rotateAngleX = ROTATE_90; - - bipedLeftArm.rotateAngleY = -0.2F; - bipedLeftLeg.rotateAngleY = 0.2F; - - bipedRightArm.rotateAngleY = 0.2F; - bipedRightLeg.rotateAngleY = -0.2F; - } else { - super.rotateLegsInFlight(move, swing, ticks, entity); - } - } - - protected void holdItem(float swing) { - if (!rainboom) { - super.holdItem(swing); - } + wings.setRotationAngles(move, swing, ticks); } @Override protected void renderBody(Entity entity, float move, float swing, float ticks, float headYaw, float headPitch, float scale) { super.renderBody(entity, move, swing, ticks, headYaw, headPitch, scale); - if (canFly()) { - wings.render(scale); - } - } - - @Override - public boolean wingsAreOpen() { - return isFlying || isCrouching(); - } - - @Override - public boolean canFly() { - return metadata.getRace().hasWings(); + wings.render(scale); } } diff --git a/src/main/java/com/minelittlepony/model/player/ModelUnicorn.java b/src/main/java/com/minelittlepony/model/player/ModelUnicorn.java new file mode 100644 index 00000000..d758a9c1 --- /dev/null +++ b/src/main/java/com/minelittlepony/model/player/ModelUnicorn.java @@ -0,0 +1,164 @@ +package com.minelittlepony.model.player; + +import com.minelittlepony.model.components.UnicornHorn; +import com.minelittlepony.render.PonyRenderer; +import net.minecraft.entity.Entity; +import net.minecraft.util.EnumHandSide; +import net.minecraft.util.math.MathHelper; + +import com.minelittlepony.model.capabilities.IModelUnicorn; + +import static com.minelittlepony.model.PonyModelConstants.*; + +/** + * Used for both unicorns and alicorns since there's no logical way to keep them distinct and not duplicate stuff. + */ +public class ModelUnicorn extends ModelEarthPony implements IModelUnicorn { + + public PonyRenderer unicornArmRight; + public PonyRenderer unicornArmLeft; + + public UnicornHorn horn; + + public ModelUnicorn(boolean smallArms) { + super(smallArms); + } + + @Override + public void init(float yOffset, float stretch) { + super.init(yOffset, stretch); + horn = new UnicornHorn(this, yOffset, stretch); + } + + @Override + protected void rotateLegsOnGround(float move, float swing, float ticks, Entity entity) { + super.rotateLegsOnGround(move, swing, ticks, entity); + + unicornArmRight.rotateAngleY = 0; + unicornArmLeft.rotateAngleY = 0; + } + + @Override + protected void adjustLegs(float move, float swing, float ticks) { + super.adjustLegs(move, swing, ticks); + + unicornArmLeft.rotateAngleZ = 0; + unicornArmRight.rotateAngleZ = 0; + + unicornArmLeft.rotateAngleX = 0; + unicornArmRight.rotateAngleX = 0; + } + + @Override + protected void holdItem(float swing) { + if (canCast()) { + boolean both = leftArmPose == ArmPose.ITEM && rightArmPose == ArmPose.ITEM; + + alignArmForAction(unicornArmLeft, leftArmPose, both, swing); + alignArmForAction(unicornArmRight, rightArmPose, both, swing); + } else { + super.holdItem(swing); + } + } + + @Override + protected void swingItem(Entity entity) { + EnumHandSide mainSide = getMainHand(entity); + + if (canCast() && getArmPoseForSide(mainSide) != ArmPose.EMPTY) { + if (swingProgress > -9990.0F && !isSleeping) { + swingArm(getUnicornArmForSide(mainSide)); + } + } else { + super.swingItem(entity); + } + } + + @Override + protected void swingArms(float ticks) { + if (isSleeping) return; + + if (canCast()) { + float cos = MathHelper.cos(ticks * 0.09F) * 0.05F + 0.05F; + float sin = MathHelper.sin(ticks * 0.067F) * 0.05F; + + if (rightArmPose != ArmPose.EMPTY) { + unicornArmRight.rotateAngleZ += cos; + unicornArmRight.rotateAngleX += sin; + } + + if (leftArmPose != ArmPose.EMPTY) { + unicornArmLeft.rotateAngleZ += cos; + unicornArmLeft.rotateAngleX += sin; + } + } else { + super.swingArms(ticks); + } + } + + @Override + public PonyRenderer getUnicornArmForSide(EnumHandSide side) { + return side == EnumHandSide.LEFT ? unicornArmLeft : unicornArmRight; + } + + @Override + public boolean canCast() { + return metadata.hasMagic(); + } + + @Override + public boolean isCasting() { + return rightArmPose != ArmPose.EMPTY || leftArmPose != ArmPose.EMPTY; + } + + @Override + public int getMagicColor() { + return metadata.getGlowColor(); + } + + @Override + protected void sneakLegs() { + super.sneakLegs(); + unicornArmRight.rotateAngleX += SNEAK_LEG_X_ROTATION_ADJUSTMENT; + unicornArmLeft.rotateAngleX += SNEAK_LEG_X_ROTATION_ADJUSTMENT; + } + + @Override + protected void aimBow(ArmPose leftArm, ArmPose rightArm, float ticks) { + if (canCast()) { + if (rightArm == ArmPose.BOW_AND_ARROW) aimBowPony(unicornArmRight, ticks); + if (leftArm == ArmPose.BOW_AND_ARROW) aimBowPony(unicornArmLeft, ticks); + } else { + super.aimBow(leftArm, rightArm, ticks); + } + } + + @Override + protected void renderHead(Entity entity, float move, float swing, float ticks, float headYaw, float headPitch, float scale) { + super.renderHead(entity, move, swing, ticks, headYaw, headPitch, scale); + + if (canCast()) { + horn.render(scale); + if (isCasting()) { + horn.renderMagic(getMagicColor(), scale); + } + } + } + + @Override + protected void initLegTextures() { + super.initLegTextures(); + unicornArmLeft = new PonyRenderer(this, 40, 32).size(64, 64); + unicornArmRight = new PonyRenderer(this, 40, 32).size(64, 64); + } + + @Override + protected void initLegPositions(float yOffset, float stretch) { + super.initLegPositions(yOffset, stretch); + float armY = THIRDP_ARM_CENTRE_Y - 6; + float armZ = THIRDP_ARM_CENTRE_Z - 2; + + unicornArmLeft .box(FIRSTP_ARM_CENTRE_X - 2, armY, armZ, 4, 12, 4, stretch + .25F).around(5, yOffset + 2, 0); + unicornArmRight.box(FIRSTP_ARM_CENTRE_X - 2, armY, armZ, 4, 12, 4, stretch + .25F).around(-5, yOffset + 2, 0); + } +} diff --git a/src/main/java/com/minelittlepony/render/player/RenderPonyBase.java b/src/main/java/com/minelittlepony/render/player/RenderPonyBase.java index 0a3f3447..3520a484 100644 --- a/src/main/java/com/minelittlepony/render/player/RenderPonyBase.java +++ b/src/main/java/com/minelittlepony/render/player/RenderPonyBase.java @@ -98,7 +98,7 @@ public abstract class RenderPonyBase extends RenderPlayer implements IRenderPony if (player.isEntityAlive() && player.isPlayerSleeping()) return; - if (ponyModel.rainboom) { + if (ponyModel.isGoingFast()) { transformPegasusFlight(player, motionX, motionY, motionZ, yaw, pitch, ticks); return; }