From b1ae2daf4487945a8467a531dd9e38bc1833b726 Mon Sep 17 00:00:00 2001 From: Matthew Messinger Date: Tue, 10 May 2016 15:10:29 -0400 Subject: [PATCH] Add some more 1.9 functionality (left arm, shields, elytra) --- .../java/com/brohoof/minelittlepony/Pony.java | 2 +- .../mixin/MixinRenderPlayer.java | 18 +++- .../model/AbstractPonyModel.java | 11 ++- .../minelittlepony/model/ModelPonyElytra.java | 84 ++++++++++++++++++ .../model/pony/ModelPlayerPony.java | 85 ++++++++++++------- .../model/pony/ModelSkeletonPony.java | 5 +- .../model/pony/ModelVillagerPony.java | 5 +- .../model/pony/armor/ModelPonyArmor.java | 9 +- .../renderer/layer/LayerHeldPonyItem.java | 2 +- .../renderer/layer/LayerPonyElytra.java | 75 ++++++++++++++++ 10 files changed, 248 insertions(+), 48 deletions(-) create mode 100644 src/main/java/com/brohoof/minelittlepony/model/ModelPonyElytra.java create mode 100644 src/main/java/com/brohoof/minelittlepony/renderer/layer/LayerPonyElytra.java diff --git a/src/main/java/com/brohoof/minelittlepony/Pony.java b/src/main/java/com/brohoof/minelittlepony/Pony.java index 9b3fbe12..6bad88ca 100644 --- a/src/main/java/com/brohoof/minelittlepony/Pony.java +++ b/src/main/java/com/brohoof/minelittlepony/Pony.java @@ -99,7 +99,7 @@ public class Pony { if (this.metadata.getRace() == null || !this.metadata.getRace().hasWings()) { return false; } - return player.capabilities.isFlying || !(player.onGround || player.isRiding() || player.isOnLadder() || player.isInWater()); + return player.capabilities.isFlying || !(player.onGround || player.isRiding() || player.isOnLadder() || player.isInWater() || player.isElytraFlying()); } public PlayerModel getModel(boolean ignorePony, boolean smallArms) { diff --git a/src/main/java/com/brohoof/minelittlepony/mixin/MixinRenderPlayer.java b/src/main/java/com/brohoof/minelittlepony/mixin/MixinRenderPlayer.java index 1a68fd9b..878403d3 100644 --- a/src/main/java/com/brohoof/minelittlepony/mixin/MixinRenderPlayer.java +++ b/src/main/java/com/brohoof/minelittlepony/mixin/MixinRenderPlayer.java @@ -17,14 +17,17 @@ import com.brohoof.minelittlepony.ducks.IRenderPony; import com.brohoof.minelittlepony.model.PMAPI; import com.brohoof.minelittlepony.model.PlayerModel; import com.brohoof.minelittlepony.model.pony.ModelHumanPlayer; +import com.brohoof.minelittlepony.model.pony.ModelPlayerPony; import com.brohoof.minelittlepony.renderer.layer.LayerHeldPonyItem; import com.brohoof.minelittlepony.renderer.layer.LayerPonyArmor; import com.brohoof.minelittlepony.renderer.layer.LayerPonyCape; +import com.brohoof.minelittlepony.renderer.layer.LayerPonyElytra; import com.brohoof.minelittlepony.renderer.layer.LayerPonySkull; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.model.ModelPlayer; import net.minecraft.client.model.ModelRenderer; +import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.entity.RenderLivingBase; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.entity.RenderPlayer; @@ -55,8 +58,9 @@ public abstract class MixinRenderPlayer extends RenderLivingBase= 0.9999F; + + if (entity instanceof EntityLivingBase && ((EntityLivingBase) entity).isElytraFlying()) { + this.rainboom = true; + } } protected void setHead(float posX, float posY, float posZ) { @@ -317,20 +324,40 @@ public class ModelPlayerPony extends AbstractPonyModel implements PonyModelConst } + @SuppressWarnings("incomplete-switch") protected void holdItem() { if (!this.rainboom && (!this.metadata.getRace().hasHorn() || this.metadata.getGlowColor() != 0)) { - if (this.rightArmPose != ArmPose.EMPTY) { - this.bipedRightArm.rotateAngleX = this.bipedRightArm.rotateAngleX * 0.5F - (float) Math.PI / 10F; - this.steveRightArm.rotateAngleX = this.steveRightArm.rotateAngleX * 0.5F - (float) Math.PI / 10F; + + switch (this.leftArmPose) { + case EMPTY: + this.bipedLeftArm.rotateAngleY = 0.0F; + break; + case BLOCK: + this.bipedLeftArm.rotateAngleX = this.bipedLeftArm.rotateAngleX * 0.5F - 0.9424779F; + this.bipedLeftArm.rotateAngleY = 0.5235988F; + break; + case ITEM: + this.bipedLeftArm.rotateAngleX = this.bipedLeftArm.rotateAngleX * 0.5F - ((float) Math.PI / 10F); + this.bipedLeftArm.rotateAngleY = 0.0F; } - if (this.leftArmPose != ArmPose.EMPTY) { - this.bipedLeftArm.rotateAngleX = this.bipedLeftArm.rotateAngleX * 0.05F - (float) Math.PI / 10F; - this.steveLeftArm.rotateAngleX = this.steveLeftArm.rotateAngleX * 0.05F - (float) Math.PI / 10F; + + switch (this.rightArmPose) { + case EMPTY: + this.bipedRightArm.rotateAngleY = 0.0F; + break; + case BLOCK: + this.bipedRightArm.rotateAngleX = this.bipedRightArm.rotateAngleX * 0.5F - 0.9424779F; + this.bipedRightArm.rotateAngleY = -0.5235988F; + break; + case ITEM: + this.bipedRightArm.rotateAngleX = this.bipedRightArm.rotateAngleX * 0.5F - ((float) Math.PI / 10F); + this.bipedRightArm.rotateAngleY = 0.0F; } + } } - protected void swingItem(float swingProgress) { + protected void swingItem(Entity entity, float swingProgress) { if (swingProgress > -9990.0F && !this.isSleeping) { float f16 = 1.0F - swingProgress; f16 *= f16 * f16; @@ -338,23 +365,29 @@ public class ModelPlayerPony extends AbstractPonyModel implements PonyModelConst float f22 = MathHelper.sin(f16 * 3.1415927F); float f28 = MathHelper.sin(swingProgress * 3.1415927F); float f33 = f28 * -(this.bipedHead.rotateAngleX - 0.7F) * 0.75F; - if (this.metadata.getRace().hasHorn() && this.metadata.getGlowColor() != 0 && this.rightArmPose != ArmPose.EMPTY) { + EnumHandSide mainSide = this.getMainHand(entity); + boolean mainRight = mainSide == EnumHandSide.RIGHT; + ArmPose mainPose = mainRight ? this.rightArmPose : this.leftArmPose; + if (this.metadata.getRace().hasHorn() && this.metadata.getGlowColor() != 0 && mainPose != ArmPose.EMPTY) { this.unicornarm.rotateAngleX = (float) (this.unicornarm.rotateAngleX - (f22 * 1.2D + f33)); this.unicornarm.rotateAngleY += this.bipedBody.rotateAngleY * 2.0F; this.unicornarm.rotateAngleZ = f28 * -0.4F; } else { - this.bipedRightArm.rotateAngleX = (float) (this.bipedRightArm.rotateAngleX - (f22 * 1.2D + f33)); - this.bipedRightArm.rotateAngleY += this.bipedBody.rotateAngleY * 2.0F; - this.bipedRightArm.rotateAngleZ = f28 * -0.4F; - this.steveRightArm.rotateAngleX = (float) (this.steveRightArm.rotateAngleX - (f22 * 1.2D + f33)); - this.steveRightArm.rotateAngleY += this.bipedBody.rotateAngleY * 2.0F; - this.steveRightArm.rotateAngleZ = f28 * -0.4F; + ModelRenderer bipedArm = this.getArmForSide(mainSide); + ModelRenderer steveArm = mainRight ? this.steveRightArm : this.steveLeftArm; + bipedArm.rotateAngleX = (float) (bipedArm.rotateAngleX - (f22 * 1.2D + f33)); + bipedArm.rotateAngleY += this.bipedBody.rotateAngleY * 2.0F; + bipedArm.rotateAngleZ = f28 * -0.4F; + steveArm.rotateAngleX = (float) (steveArm.rotateAngleX - (f22 * 1.2D + f33)); + steveArm.rotateAngleY += this.bipedBody.rotateAngleY * 2.0F; + steveArm.rotateAngleZ = f28 * -0.4F; } } } - protected void swingArms(float tick) { + protected void swingArms(Entity entity, float tick) { + if (this.rightArmPose != ArmPose.EMPTY && !this.isSleeping) { float cosTickFactor = MathHelper.cos(tick * 0.09F) * 0.05F + 0.05F; float sinTickFactor = MathHelper.sin(tick * 0.067F) * 0.05F; @@ -459,7 +492,6 @@ public class ModelPlayerPony extends AbstractPonyModel implements PonyModelConst } protected void aimBowPony(ArmPose leftArm, ArmPose rightArm, float tick) { - // TODO test left arm if (rightArm == ArmPose.BOW_AND_ARROW) { this.bipedRightArm.rotateAngleZ = 0.0F; this.bipedRightArm.rotateAngleY = -0.06F + this.bipedHead.rotateAngleY; @@ -475,17 +507,6 @@ public class ModelPlayerPony extends AbstractPonyModel implements PonyModelConst this.bipedLeftArm.rotateAngleX += MathHelper.sin(tick * 0.067F) * 0.05F; shiftRotationPoint(this.bipedLeftArm, 0.0F, 0.0F, 1.0F); } - - // this.bipedRightArmwear.rotateAngleZ = 0.0F; - // this.bipedRightArmwear.rotateAngleY = -0.06F + - // this.bipedHead.rotateAngleY; - // this.bipedRightArmwear.rotateAngleX = ROTATE_270 + - // this.bipedHead.rotateAngleX; - // this.bipedRightArmwear.rotateAngleZ += MathHelper.cos(tick * 0.09F) * - // 0.05F + 0.05F; - // this.bipedRightArmwear.rotateAngleX += MathHelper.sin(tick * 0.067F) - // * 0.05F; - // shiftRotationPoint(this.bipedRightArmwear, 0.0F, 0.0F, 1.0F); } protected void aimBowUnicorn(float tick) { diff --git a/src/main/java/com/brohoof/minelittlepony/model/pony/ModelSkeletonPony.java b/src/main/java/com/brohoof/minelittlepony/model/pony/ModelSkeletonPony.java index 33e4a76a..9c1cfe12 100644 --- a/src/main/java/com/brohoof/minelittlepony/model/pony/ModelSkeletonPony.java +++ b/src/main/java/com/brohoof/minelittlepony/model/pony/ModelSkeletonPony.java @@ -12,10 +12,7 @@ public class ModelSkeletonPony extends ModelPlayerPony { @Override protected void rotateLegs(float move, float swing, float tick) { - if (true){ - super.rotateLegs(move, swing, tick); - return; - } + float rightArmRotateAngleX; float leftArmRotateAngleX; float rightLegRotateAngleX; diff --git a/src/main/java/com/brohoof/minelittlepony/model/pony/ModelVillagerPony.java b/src/main/java/com/brohoof/minelittlepony/model/pony/ModelVillagerPony.java index c0e9b890..a5bb697a 100644 --- a/src/main/java/com/brohoof/minelittlepony/model/pony/ModelVillagerPony.java +++ b/src/main/java/com/brohoof/minelittlepony/model/pony/ModelVillagerPony.java @@ -2,6 +2,7 @@ package com.brohoof.minelittlepony.model.pony; import com.brohoof.minelittlepony.renderer.PlaneRenderer; +import net.minecraft.entity.Entity; import net.minecraft.util.math.MathHelper; public class ModelVillagerPony extends ModelPlayerPony { @@ -17,8 +18,8 @@ public class ModelVillagerPony extends ModelPlayerPony { } @Override - public void animate(float move, float swing, float tick, float horz, float vert) { - super.animate(move, swing, tick, horz, vert); + public void animate(float move, float swing, float tick, float horz, float vert, Entity entity) { + super.animate(move, swing, tick, horz, vert, entity); float bodySwingRotation = 0.0F; if (this.swingProgress > -9990.0F && (!this.metadata.getRace().hasHorn() || this.metadata.getGlowColor() == 0)) { bodySwingRotation = MathHelper.sin(MathHelper.sqrt_float(this.swingProgress) * 3.1415927F * 2.0F) * 0.2F; diff --git a/src/main/java/com/brohoof/minelittlepony/model/pony/armor/ModelPonyArmor.java b/src/main/java/com/brohoof/minelittlepony/model/pony/armor/ModelPonyArmor.java index 34a7b4e7..d2acd0d5 100644 --- a/src/main/java/com/brohoof/minelittlepony/model/pony/armor/ModelPonyArmor.java +++ b/src/main/java/com/brohoof/minelittlepony/model/pony/armor/ModelPonyArmor.java @@ -4,6 +4,7 @@ import com.brohoof.minelittlepony.model.pony.ModelPlayerPony; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.model.ModelRenderer; +import net.minecraft.entity.Entity; import net.minecraft.util.math.MathHelper; public class ModelPonyArmor extends ModelPlayerPony { @@ -24,8 +25,8 @@ public class ModelPonyArmor extends ModelPlayerPony { } @Override - public void animate(float move, float swing, float tick, float horz, float vert) { - this.checkRainboom(swing); + public void animate(float move, float swing, float tick, float horz, float vert, Entity entity) { + this.checkRainboom(entity, swing); this.rotateHead(horz, vert); float bodySwingRotation = 0.0F; if (this.swingProgress > -9990.0F && (!this.metadata.getRace().hasHorn() || this.metadata.getGlowColor() == 0)) { @@ -42,7 +43,7 @@ public class ModelPonyArmor extends ModelPlayerPony { this.extHead[1].offsetZ = 0f; this.setLegs(move, swing, tick); this.holdItem(); - this.swingItem(this.swingProgress); + this.swingItem(entity, this.swingProgress); if (this.isSneak && !this.isFlying) { this.adjustBody(BODY_ROTATE_ANGLE_X_SNEAK, BODY_RP_Y_SNEAK, BODY_RP_Z_SNEAK); this.sneakLegs(); @@ -71,7 +72,7 @@ public class ModelPonyArmor extends ModelPlayerPony { this.bipedRightLeg.rotationPointY = FRONT_LEG_RP_Y_NOTSNEAK; this.bipedLeftLeg.rotationPointY = FRONT_LEG_RP_Y_NOTSNEAK; - this.swingArms(tick); + this.swingArms(entity, tick); this.setHead(0.0F, 0.0F, 0.0F); } diff --git a/src/main/java/com/brohoof/minelittlepony/renderer/layer/LayerHeldPonyItem.java b/src/main/java/com/brohoof/minelittlepony/renderer/layer/LayerHeldPonyItem.java index 55d6237c..2b60c095 100644 --- a/src/main/java/com/brohoof/minelittlepony/renderer/layer/LayerHeldPonyItem.java +++ b/src/main/java/com/brohoof/minelittlepony/renderer/layer/LayerHeldPonyItem.java @@ -89,7 +89,7 @@ public class LayerHeldPonyItem implements LayerRenderer { if (isUnicorn) { GlStateManager.translate(isLeft ? -0.1F : 0.1F, 1, -.5); } else { - GlStateManager.translate(isLeft ? -0.0625F : 0.0625F, 0.125F, -1.00F); + GlStateManager.translate(0.0425F, 0.125F, -1.00F); } Minecraft.getMinecraft().getItemRenderer().renderItemSide(entity, drop, transform, isLeft); diff --git a/src/main/java/com/brohoof/minelittlepony/renderer/layer/LayerPonyElytra.java b/src/main/java/com/brohoof/minelittlepony/renderer/layer/LayerPonyElytra.java new file mode 100644 index 00000000..0a62cb06 --- /dev/null +++ b/src/main/java/com/brohoof/minelittlepony/renderer/layer/LayerPonyElytra.java @@ -0,0 +1,75 @@ +package com.brohoof.minelittlepony.renderer.layer; + +import com.brohoof.minelittlepony.ducks.IRenderPony; +import com.brohoof.minelittlepony.model.AbstractPonyModel; +import com.brohoof.minelittlepony.model.BodyPart; +import com.brohoof.minelittlepony.model.ModelPonyElytra; +import com.brohoof.minelittlepony.model.pony.ModelHumanPlayer; + +import net.minecraft.client.entity.AbstractClientPlayer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.entity.RenderPlayer; +import net.minecraft.client.renderer.entity.layers.LayerArmorBase; +import net.minecraft.client.renderer.entity.layers.LayerElytra; +import net.minecraft.client.renderer.entity.layers.LayerRenderer; +import net.minecraft.entity.player.EnumPlayerModelParts; +import net.minecraft.init.Items; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + +public class LayerPonyElytra implements LayerRenderer { + + private static final ResourceLocation TEXTURE_ELYTRA = new ResourceLocation("textures/entity/elytra.png"); + private RenderPlayer renderPlayer; + private ModelPonyElytra modelElytra = new ModelPonyElytra(); + + private LayerElytra elytra; + + public LayerPonyElytra(RenderPlayer rp) { + this.renderPlayer = rp; + this.elytra = new LayerElytra(rp); + } + + @Override + public void doRenderLayer(AbstractClientPlayer entity, float swing, float swingAmount, float ticks, float age, float yaw, float head, float scale) { + + AbstractPonyModel model = ((IRenderPony) this.renderPlayer).getPony().getModel(); + if (model instanceof ModelHumanPlayer) { + this.elytra.doRenderLayer(entity, swing, swingAmount, ticks, age, yaw, head, scale); + return; + } + + ItemStack itemstack = entity.getItemStackFromSlot(EntityEquipmentSlot.CHEST); + + if (itemstack != null && itemstack.getItem() == Items.ELYTRA) { + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + + if (entity.isPlayerInfoSet() && entity.getLocationElytra() != null) { + this.renderPlayer.bindTexture(entity.getLocationElytra()); + } else if (entity.hasPlayerInfo() && entity.getLocationCape() != null && entity.isWearing(EnumPlayerModelParts.CAPE)) { + this.renderPlayer.bindTexture(entity.getLocationCape()); + } else { + this.renderPlayer.bindTexture(TEXTURE_ELYTRA); + } + + GlStateManager.pushMatrix(); + GlStateManager.translate(0.0F, 0.25F, 0.125F); + model.transform(BodyPart.BODY); + this.modelElytra.setRotationAngles(swing, swingAmount, age, yaw, head, scale, entity); + this.modelElytra.render(entity, swing, swingAmount, age, yaw, head, scale); + + if (itemstack.isItemEnchanted()) { + LayerArmorBase.renderEnchantedGlint(this.renderPlayer, entity, this.modelElytra, swing, swingAmount, ticks, age, yaw, head, scale); + } + + GlStateManager.popMatrix(); + } + } + + @Override + public boolean shouldCombineTextures() { + return false; + } + +}