From a2855237f2d705688a85591d9424fae1c5eda6c5 Mon Sep 17 00:00:00 2001 From: Sollace Date: Fri, 22 Mar 2019 22:09:06 +0200 Subject: [PATCH] - Fixed Elytra not following the same rules for crouching as the pony body - Various changes away from using AbstractPonyModel directly --- .../model/AbstractPonyModel.java | 27 ++++++++++++++++--- .../model/capabilities/ICapitated.java | 10 ++++++- .../model/capabilities/IModel.java | 4 +++ .../model/components/ModelPonyHead.java | 9 ++++++- .../model/components/PonyElytra.java | 7 +++-- .../model/gear/AbstractGear.java | 2 +- .../com/minelittlepony/pony/data/IPony.java | 22 ++++++++++++++- .../com/minelittlepony/pony/data/Pony.java | 17 ++++++++++++ .../render/layer/LayerGear.java | 3 ++- .../render/layer/LayerPonyCape.java | 2 +- .../render/layer/LayerPonyElytra.java | 15 ++++++++--- .../minelittlepony/transform/PonyPosture.java | 4 +-- .../transform/PostureElytra.java | 3 ++- .../transform/PostureFalling.java | 6 ++--- .../transform/PostureFlight.java | 8 +++--- 15 files changed, 114 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/minelittlepony/model/AbstractPonyModel.java b/src/main/java/com/minelittlepony/model/AbstractPonyModel.java index f89a843b..0df37d63 100644 --- a/src/main/java/com/minelittlepony/model/AbstractPonyModel.java +++ b/src/main/java/com/minelittlepony/model/AbstractPonyModel.java @@ -15,6 +15,8 @@ import com.minelittlepony.render.model.PonyRenderer; import com.minelittlepony.util.math.MathUtil; import com.minelittlepony.util.render.AbstractBoxRenderer; +import javax.annotation.Nullable; + import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelPlayer; import net.minecraft.client.model.ModelRenderer; @@ -38,11 +40,12 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel, P public boolean isFlying; public boolean isElytraFlying; public boolean isSwimming; + public boolean isCrouching; public boolean isRidingInteractive; public boolean headGear; /** - * Associcated pony data. + * Associated pony data. */ public IPonyData metadata = new PonyData(); @@ -90,6 +93,7 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel, P public void updateLivingState(EntityLivingBase entity, IPony pony) { isChild = entity.isChild(); isSneak = entity.isSneaking(); + isCrouching = pony.isCrouching(entity); isSleeping = entity.isPlayerSleeping(); isFlying = pony.isFlying(entity); isElytraFlying = entity.isElytraFlying(); @@ -267,6 +271,22 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel, P return bipedHead; } + @Nullable + @Override + public ModelRenderer getBody() { + return bipedBody; + } + + @Override + public void setPitch(float pitch) { + motionPitch = pitch; + } + + @Override + public float getPitch() { + return motionPitch; + } + /** * Sets the head rotation point. */ @@ -743,7 +763,7 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel, P @Override public boolean isCrouching() { - return !rainboom && !isSwimming && isSneak && !isFlying; + return isCrouching; } @Override @@ -788,7 +808,7 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel, P @Override public PonySize getSize() { - return isChild ? PonySize.FOAL : metadata.getSize(); + return isChild ? PonySize.FOAL : getMetadata().getSize(); } @Override @@ -927,6 +947,7 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel, P if (model instanceof AbstractPonyModel) { AbstractPonyModel pony = (AbstractPonyModel) model; isFlying = pony.isFlying; + isCrouching = pony.isCrouching; isElytraFlying = pony.isElytraFlying; isSwimming = pony.isSwimming; isSleeping = pony.isSleeping; diff --git a/src/main/java/com/minelittlepony/model/capabilities/ICapitated.java b/src/main/java/com/minelittlepony/model/capabilities/ICapitated.java index 6afbe0b1..1b586428 100644 --- a/src/main/java/com/minelittlepony/model/capabilities/ICapitated.java +++ b/src/main/java/com/minelittlepony/model/capabilities/ICapitated.java @@ -2,6 +2,8 @@ package com.minelittlepony.model.capabilities; import net.minecraft.client.model.ModelRenderer; +import javax.annotation.Nullable; + public interface ICapitated { /** * Gets the head of this capitated object. @@ -9,7 +11,13 @@ public interface ICapitated { ModelRenderer getHead(); /** - * Returns true if we're wearing any uconventional headgear (ie. a Pumpkin) + * Gets the main body + */ + @Nullable + ModelRenderer getBody(); + + /** + * Returns true if we're wearing any unconventional headgear (ie. a Pumpkin) */ boolean hasHeadGear(); diff --git a/src/main/java/com/minelittlepony/model/capabilities/IModel.java b/src/main/java/com/minelittlepony/model/capabilities/IModel.java index 84bf54ec..1a1fc419 100644 --- a/src/main/java/com/minelittlepony/model/capabilities/IModel.java +++ b/src/main/java/com/minelittlepony/model/capabilities/IModel.java @@ -20,6 +20,10 @@ public interface IModel extends ICapitated { */ void transform(BodyPart part); + void setPitch(float pitch); + + float getPitch(); + /** * Gets the active scaling profile used to lay out this model's parts. */ diff --git a/src/main/java/com/minelittlepony/model/components/ModelPonyHead.java b/src/main/java/com/minelittlepony/model/components/ModelPonyHead.java index 7e545b91..322ca435 100644 --- a/src/main/java/com/minelittlepony/model/components/ModelPonyHead.java +++ b/src/main/java/com/minelittlepony/model/components/ModelPonyHead.java @@ -5,6 +5,8 @@ import com.minelittlepony.pony.data.IPonyData; import com.minelittlepony.pony.data.PonyData; import com.minelittlepony.render.model.PonyRenderer; +import javax.annotation.Nullable; + import net.minecraft.client.model.ModelHumanoidHead; import net.minecraft.client.model.ModelRenderer; import net.minecraft.entity.Entity; @@ -39,6 +41,12 @@ public class ModelPonyHead extends ModelHumanoidHead implements ICapitated { return skeletonHead; } + @Nullable + @Override + public ModelRenderer getBody() { + return null; + } + @Override public boolean hasHeadGear() { return false; @@ -58,5 +66,4 @@ public class ModelPonyHead extends ModelHumanoidHead implements ICapitated { horn.renderPart(scale, entity.getUniqueID()); } } - } diff --git a/src/main/java/com/minelittlepony/model/components/PonyElytra.java b/src/main/java/com/minelittlepony/model/components/PonyElytra.java index 22e1a1eb..fa5cd151 100644 --- a/src/main/java/com/minelittlepony/model/components/PonyElytra.java +++ b/src/main/java/com/minelittlepony/model/components/PonyElytra.java @@ -15,6 +15,9 @@ import static com.minelittlepony.model.PonyModelConstants.*; * Modified from ModelElytra. */ public class PonyElytra extends ModelBase { + + public boolean isSneaking; + private PonyRenderer rightWing = new PonyRenderer(this, 22, 0); private PonyRenderer leftWing = new PonyRenderer(this, 22, 0); @@ -55,13 +58,13 @@ public class PonyElytra extends ModelBase { float velY = 1; if (entity.motionY < 0) { - Vec3d motion = (new Vec3d(entity.motionX, entity.motionY, entity.motionZ)).normalize(); + Vec3d motion = new Vec3d(entity.motionX, entity.motionY, entity.motionZ).normalize(); velY = 1 - (float) Math.pow(-motion.y, 1.5); } rotateX = velY * PI * (2 / 3F) + (1 - velY) * rotateX; rotateY = velY * (PI / 2) + (1 - velY) * rotateY; - } else if (entity.isSneaking()) { + } else if (isSneaking) { rotateX = PI * 1.175F; rotateY = PI / 2; rotateZ = PI / 4; diff --git a/src/main/java/com/minelittlepony/model/gear/AbstractGear.java b/src/main/java/com/minelittlepony/model/gear/AbstractGear.java index 53b99865..fc70fb6c 100644 --- a/src/main/java/com/minelittlepony/model/gear/AbstractGear.java +++ b/src/main/java/com/minelittlepony/model/gear/AbstractGear.java @@ -28,7 +28,7 @@ public abstract class AbstractGear extends ModelBase implements IGear, PonyModel case NECK: return model.neck; case TAIL: case LEGS: - case BODY: return model.bipedBody; + case BODY: return model.getBody(); } } diff --git a/src/main/java/com/minelittlepony/pony/data/IPony.java b/src/main/java/com/minelittlepony/pony/data/IPony.java index 47481dba..54e6123f 100644 --- a/src/main/java/com/minelittlepony/pony/data/IPony.java +++ b/src/main/java/com/minelittlepony/pony/data/IPony.java @@ -25,6 +25,26 @@ public interface IPony { return MineLittlePony.getInstance().getManager().getPony(texture); } + /** + * Returns true if this pony has wings and the will to use them. + */ + default boolean canFly() { + return getMetadata().getRace().hasWings(); + } + + /** + * Checks the required conditions for whether the given entity can perform a sonic rainboom. + */ + boolean isPerformingRainboom(EntityLivingBase entity); + + /** + * Unlike sneaking, crouching is a more specific animation parameter that controls whether the player is visible + * nose to the ground, crouching the sand. + * + * You cannot crouch whilst flying or swimming. + */ + boolean isCrouching(EntityLivingBase entity); + /** * Returns true if the provided entity is flying like a pegasus. * True if the entity is off the ground. @@ -35,7 +55,7 @@ public interface IPony { boolean isFlying(EntityLivingBase entity); /** - * Returns true if the provided antity is actively wimming. + * Returns true if the provided entity is actively swimming. * That is, it should be fully submerged (isFullySubmerged returns true) * and is not standing on the (river) bed or riding a ladder or any other entity. */ diff --git a/src/main/java/com/minelittlepony/pony/data/Pony.java b/src/main/java/com/minelittlepony/pony/data/Pony.java index 362736eb..e70a15d9 100644 --- a/src/main/java/com/minelittlepony/pony/data/Pony.java +++ b/src/main/java/com/minelittlepony/pony/data/Pony.java @@ -111,6 +111,23 @@ public class Pony extends Touchable implements IPony { return PonyData.parse(bufferedimage); } + @Override + public boolean isPerformingRainboom(EntityLivingBase entity) { + double zMotion = Math.sqrt(entity.motionX * entity.motionX + entity.motionZ * entity.motionZ); + + return (isFlying(entity) && canFly()) || entity.isElytraFlying() & zMotion > 0.4F; + } + + @Override + public boolean isCrouching(EntityLivingBase entity) { + + boolean isSneak = entity.isSneaking(); + boolean isFlying = isFlying(entity); + boolean isSwimming = isSwimming(entity); + + return !isPerformingRainboom(entity) && !isSwimming && isSneak && !isFlying; + } + @Override public boolean isFlying(EntityLivingBase entity) { return !(entity.onGround diff --git a/src/main/java/com/minelittlepony/render/layer/LayerGear.java b/src/main/java/com/minelittlepony/render/layer/LayerGear.java index 962d3cc2..b7a22690 100644 --- a/src/main/java/com/minelittlepony/render/layer/LayerGear.java +++ b/src/main/java/com/minelittlepony/render/layer/LayerGear.java @@ -11,6 +11,7 @@ import com.google.common.collect.Lists; import com.minelittlepony.ducks.IRenderPony; import com.minelittlepony.model.AbstractPonyModel; import com.minelittlepony.model.BodyPart; +import com.minelittlepony.model.capabilities.IModel; import com.minelittlepony.model.gear.ChristmasHat; import com.minelittlepony.model.gear.IGear; import com.minelittlepony.model.gear.IStackable; @@ -72,7 +73,7 @@ public class LayerGear extends AbstractPonyLayer } } - private void renderGear(AbstractPonyModel model, T entity, IGear gear, float move, float swing, float scale, float ticks) { + private void renderGear(IModel model, T entity, IGear gear, float move, float swing, float scale, float ticks) { GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); ResourceLocation texture = gear.getTexture(entity); diff --git a/src/main/java/com/minelittlepony/render/layer/LayerPonyCape.java b/src/main/java/com/minelittlepony/render/layer/LayerPonyCape.java index 221e67ca..29505034 100644 --- a/src/main/java/com/minelittlepony/render/layer/LayerPonyCape.java +++ b/src/main/java/com/minelittlepony/render/layer/LayerPonyCape.java @@ -33,7 +33,7 @@ public class LayerPonyCape extends AbstractPonyLayer { model.transform(BodyPart.BODY); translate(0, 0.24F, 0); - model.bipedBody.postRender(scale); + model.getBody().postRender(scale); double capeX = player.prevChasingPosX + (player.chasingPosX - player.prevChasingPosX) * scale - (player.prevPosX + (player.posX - player.prevPosX) * scale); double capeY = player.prevChasingPosY + (player.chasingPosY - player.prevChasingPosY) * scale - (player.prevPosY + (player.posY - player.prevPosY) * scale); diff --git a/src/main/java/com/minelittlepony/render/layer/LayerPonyElytra.java b/src/main/java/com/minelittlepony/render/layer/LayerPonyElytra.java index 7c433088..a1d73b49 100644 --- a/src/main/java/com/minelittlepony/render/layer/LayerPonyElytra.java +++ b/src/main/java/com/minelittlepony/render/layer/LayerPonyElytra.java @@ -20,7 +20,8 @@ import javax.annotation.Nonnull; public class LayerPonyElytra extends AbstractPonyLayer { private static final ResourceLocation TEXTURE_ELYTRA = new ResourceLocation("textures/entity/elytra.png"); - private PonyElytra modelElytra = new PonyElytra(); + + private final PonyElytra modelElytra = new PonyElytra(); public LayerPonyElytra(RenderLivingBase rp) { super(rp); @@ -38,11 +39,17 @@ public class LayerPonyElytra extends AbstractPonyLay GlStateManager.pushMatrix(); preRenderCallback(); - getElytraModel().setRotationAngles(move, swing, ticks, yaw, head, scale, entity); - getElytraModel().render(entity, move, swing, ticks, yaw, head, scale); + ModelBase elytra = getElytraModel(); + + if (elytra instanceof PonyElytra) { + ((PonyElytra)elytra).isSneaking = getPonyRenderer().getEntityPony(entity).isCrouching(entity); + } + + elytra.setRotationAngles(move, swing, ticks, yaw, head, scale, entity); + elytra.render(entity, move, swing, ticks, yaw, head, scale); if (itemstack.isItemEnchanted()) { - LayerArmorBase.renderEnchantedGlint(getRenderer(), entity, getElytraModel(), move, swing, partialTicks, ticks, yaw, head, scale); + LayerArmorBase.renderEnchantedGlint(getRenderer(), entity, elytra, move, swing, partialTicks, ticks, yaw, head, scale); } GlStateManager.popMatrix(); diff --git a/src/main/java/com/minelittlepony/transform/PonyPosture.java b/src/main/java/com/minelittlepony/transform/PonyPosture.java index 3a8c975e..6b4ab7b2 100644 --- a/src/main/java/com/minelittlepony/transform/PonyPosture.java +++ b/src/main/java/com/minelittlepony/transform/PonyPosture.java @@ -1,6 +1,6 @@ package com.minelittlepony.transform; -import com.minelittlepony.model.AbstractPonyModel; +import com.minelittlepony.model.capabilities.IModel; import net.minecraft.entity.EntityLivingBase; @@ -14,5 +14,5 @@ public interface PonyPosture { return true; } - void transform(AbstractPonyModel model, T entity, double motionX, double motionY, double motionZ, float yaw, float ticks); + void transform(IModel model, T entity, double motionX, double motionY, double motionZ, float yaw, float ticks); } diff --git a/src/main/java/com/minelittlepony/transform/PostureElytra.java b/src/main/java/com/minelittlepony/transform/PostureElytra.java index e79a3265..7314c582 100644 --- a/src/main/java/com/minelittlepony/transform/PostureElytra.java +++ b/src/main/java/com/minelittlepony/transform/PostureElytra.java @@ -1,13 +1,14 @@ package com.minelittlepony.transform; import com.minelittlepony.model.AbstractPonyModel; +import com.minelittlepony.model.capabilities.IModel; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.EntityLivingBase; public class PostureElytra implements PonyPosture { @Override - public void transform(AbstractPonyModel model, EntityLivingBase entity, double motionX, double motionY, double motionZ, float yaw, float ticks) { + public void transform(IModel model, EntityLivingBase entity, double motionX, double motionY, double motionZ, float yaw, float ticks) { GlStateManager.rotate(90, 1, 0, 0); GlStateManager.translate(0, entity.isSneaking() ? 0.2F : -1, 0); } diff --git a/src/main/java/com/minelittlepony/transform/PostureFalling.java b/src/main/java/com/minelittlepony/transform/PostureFalling.java index 2ed9e16f..6d7de7f7 100644 --- a/src/main/java/com/minelittlepony/transform/PostureFalling.java +++ b/src/main/java/com/minelittlepony/transform/PostureFalling.java @@ -1,12 +1,12 @@ package com.minelittlepony.transform; -import com.minelittlepony.model.AbstractPonyModel; +import com.minelittlepony.model.capabilities.IModel; import net.minecraft.entity.EntityLivingBase; public class PostureFalling implements PonyPosture { @Override - public void transform(AbstractPonyModel model, EntityLivingBase entity, double motionX, double motionY, double motionZ, float yaw, float ticks) { - model.motionPitch = 0; + public void transform(IModel model, EntityLivingBase entity, double motionX, double motionY, double motionZ, float yaw, float ticks) { + model.setPitch(0); } } diff --git a/src/main/java/com/minelittlepony/transform/PostureFlight.java b/src/main/java/com/minelittlepony/transform/PostureFlight.java index bf0f78f1..a4d7b500 100644 --- a/src/main/java/com/minelittlepony/transform/PostureFlight.java +++ b/src/main/java/com/minelittlepony/transform/PostureFlight.java @@ -1,6 +1,6 @@ package com.minelittlepony.transform; -import com.minelittlepony.model.AbstractPonyModel; +import com.minelittlepony.model.capabilities.IModel; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.renderer.GlStateManager; @@ -13,10 +13,10 @@ public class PostureFlight extends MotionCompositor implements PonyPosture