From 28fce6ef5dc87a7f9099e80bb9722eafb115095a Mon Sep 17 00:00:00 2001 From: Sollace Date: Tue, 1 May 2018 16:46:59 +0200 Subject: [PATCH] Cut all of the extra code from armour --- .../model/AbstractPonyModel.java | 28 +-- .../model/armour/ModelPonyArmor.java | 178 +++++------------- .../model/armour/ModelSkeletonPonyArmor.java | 15 -- .../model/armour/ModelZombiePonyArmor.java | 29 --- .../model/armour/PonyArmor.java | 9 +- .../model/components/PonySnout.java | 6 +- .../model/ponies/ModelSkeletonPony.java | 8 - .../model/ponies/ModelZombiePony.java | 8 - .../render/AbstractPonyRenderer.java | 16 +- .../render/layer/LayerPonyArmor.java | 149 +++++---------- 10 files changed, 121 insertions(+), 325 deletions(-) delete mode 100644 src/main/java/com/minelittlepony/model/armour/ModelSkeletonPonyArmor.java delete mode 100644 src/main/java/com/minelittlepony/model/armour/ModelZombiePonyArmor.java diff --git a/src/main/java/com/minelittlepony/model/AbstractPonyModel.java b/src/main/java/com/minelittlepony/model/AbstractPonyModel.java index 4a7b15b3..24b160c1 100644 --- a/src/main/java/com/minelittlepony/model/AbstractPonyModel.java +++ b/src/main/java/com/minelittlepony/model/AbstractPonyModel.java @@ -137,9 +137,7 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { animateWears(); - if (snout != null) { - snout.setGender(metadata.getGender()); - } + snout.setGender(metadata.getGender()); } protected void adjustBodyRiding() { @@ -629,25 +627,17 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { bipedLeftLeg .setRotationPoint( rarmX, yOffset, 0); bipedRightLeg.setRotationPoint(-rarmX, yOffset, 0); - if (bipedLeftArmwear != null) { - bipedLeftArmwear.addBox(armX, armY, armZ, armWidth, 12, armDepth, stretch + 0.25f); - bipedLeftArmwear.setRotationPoint(rarmX, yOffset + rarmY, 0); - } + bipedLeftArmwear.addBox(armX, armY, armZ, armWidth, 12, armDepth, stretch + 0.25f); + bipedLeftArmwear.setRotationPoint(rarmX, yOffset + rarmY, 0); - if (bipedRightArmwear != null) { - bipedRightArmwear.addBox(armX - armWidth, armY, armZ, armWidth, 12, armDepth, stretch + 0.25f); - bipedRightArmwear.setRotationPoint(-rarmX, yOffset + rarmY, 0); - } + bipedRightArmwear.addBox(armX - armWidth, armY, armZ, armWidth, 12, armDepth, stretch + 0.25f); + bipedRightArmwear.setRotationPoint(-rarmX, yOffset + rarmY, 0); - if (bipedLeftLegwear != null) { - bipedLeftLegwear.addBox(armX, armY, armZ, armWidth, 12, armDepth, stretch + 0.25f); - bipedRightLegwear.setRotationPoint(rarmX, yOffset, 0); - } + bipedLeftLegwear.addBox(armX, armY, armZ, armWidth, 12, armDepth, stretch + 0.25f); + bipedRightLegwear.setRotationPoint(rarmX, yOffset, 0); - if (bipedRightLegwear != null) { - bipedRightLegwear.addBox(armX - armWidth, armY, armZ, armWidth, 12, armDepth, stretch + 0.25f); - bipedRightLegwear.setRotationPoint(-rarmX, yOffset, 0); - } + bipedRightLegwear.addBox(armX - armWidth, armY, armZ, armWidth, 12, armDepth, stretch + 0.25f); + bipedRightLegwear.setRotationPoint(-rarmX, yOffset, 0); } public ArmPose getArmPoseForSide(EnumHandSide side) { diff --git a/src/main/java/com/minelittlepony/model/armour/ModelPonyArmor.java b/src/main/java/com/minelittlepony/model/armour/ModelPonyArmor.java index 59205969..d1cfd238 100644 --- a/src/main/java/com/minelittlepony/model/armour/ModelPonyArmor.java +++ b/src/main/java/com/minelittlepony/model/armour/ModelPonyArmor.java @@ -4,58 +4,23 @@ import net.minecraft.entity.Entity; import static com.minelittlepony.model.PonyModelConstants.*; -import com.minelittlepony.model.ModelMobPony; +import com.minelittlepony.model.AbstractPonyModel; import com.minelittlepony.render.PonyRenderer; -public class ModelPonyArmor extends ModelMobPony { +public class ModelPonyArmor extends AbstractPonyModel { public PonyRenderer flankGuard; public PonyRenderer saddle; - public PonyRenderer helmet; - - public PonyRenderer leftLegging; - public PonyRenderer rightLegging; public ModelPonyArmor() { - super(); + super(false); textureHeight = 32; } @Override - 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); - syncLegs(); - } - - @Override - protected void rotateLook(float move, float swing, float bodySwing, float ticks) { - bipedBody.rotateAngleY = bodySwing / 5; - } - - @Override - protected void adjustBodyRiding() { - adjustBody(BODY_ROTATE_ANGLE_X_RIDING, BODY_RP_Y_RIDING, BODY_RP_Z_RIDING); - } - - @Override - protected void setHead(float posX, float posY, float posZ) { - super.setHead(posX, posY, posZ); - helmet.setRotationPoint(posX, posY, posZ); - } - - @Override - protected void updateHeadRotation(float x, float y) { - super.updateHeadRotation(x, y); - helmet.rotateAngleX = x; - helmet.rotateAngleY = y; - } - - @Override - protected void adjustBody(float rotateAngleX, float rotationPointY, float rotationPointZ) { - bipedBody.rotateAngleX = rotateAngleX; - bipedBody.rotationPointY = rotationPointY; - bipedBody.rotationPointZ = rotationPointZ; + protected void adjustBodyComponents(float rotateAngleX, float rotationPointY, float rotationPointZ) { + super.adjustBodyComponents(rotateAngleX, rotationPointY, rotationPointZ); flankGuard.rotateAngleX = rotateAngleX; flankGuard.rotationPointY = rotationPointY; @@ -66,26 +31,8 @@ public class ModelPonyArmor extends ModelMobPony { saddle.rotationPointZ = rotationPointZ; } - @Override - protected void renderHead(Entity entity, float move, float swing, float ticks, float headYaw, float headPitch, float scale) { - bipedHead.render(this.scale); - helmet.render(this.scale); - bipedHeadwear.render(this.scale); - } - - @Override - protected void renderNeck() { - // TODO: Disabling the neck like this forces more complexity lower down - } - - @Override - protected void adjustNeck(float rotateAngleX, float rotationPointY, float rotationPointZ) { - - } - @Override protected void renderBody(Entity entity, float move, float swing, float ticks, float headYaw, float headPitch, float scale) { - bipedBody.render(this.scale); flankGuard.render(this.scale); saddle.render(this.scale); } @@ -98,101 +45,50 @@ public class ModelPonyArmor extends ModelMobPony { saddle.postRender(scale); saddle.showModel = isLegs; } - bipedLeftArm.render(scale); - bipedRightArm.render(scale); - bipedLeftLeg.render(scale); - bipedRightLeg.render(scale); - rightLegging.render(scale); - leftLegging.render(scale); - } - @Override - protected void initTextures() { - initHeadTextures(); - initBodyTextures(); - initLegTextures(); - } - - @Override - protected void initHeadTextures() { - bipedHead = new PonyRenderer(this, 0, 0); - bipedHeadwear = new PonyRenderer(this, 32, 0); - helmet = new PonyRenderer(this, 0, 0); + super.renderLegs(); } @Override protected void initBodyTextures() { - bipedBody = new PonyRenderer(this, 16, 16); + super.initBodyTextures(); flankGuard = new PonyRenderer(this, 0, 0); saddle = new PonyRenderer(this, 16, 8); } @Override protected void initLegTextures() { - bipedRightArm = new PonyRenderer(this, 0, 16); - bipedRightLeg = new PonyRenderer(this, 0, 16); + super.initLegTextures(); bipedLeftArm = new PonyRenderer(this, 0, 16).flipX(); + bipedRightArm = new PonyRenderer(this, 0, 16); + bipedLeftLeg = new PonyRenderer(this, 0, 16).flipX(); - - unicornArmRight = new PonyRenderer(this, 0, 16); - unicornArmLeft = new PonyRenderer(this, 0, 16); - - leftLegging = new PonyRenderer(this, 48, 8); - rightLegging = new PonyRenderer(this, 48, 8); + bipedRightLeg = new PonyRenderer(this, 0, 16); } - @Override - protected void initTailPositions(float yOffset, float stretch) { - + public void synchroniseLegs(AbstractPonyModel mainModel) { + copyModelAngles(mainModel.bipedRightArm, bipedRightArm); + copyModelAngles(mainModel.bipedLeftArm, bipedLeftArm); + copyModelAngles(mainModel.bipedRightLeg, bipedRightLeg); + copyModelAngles(mainModel.bipedLeftLeg, bipedLeftLeg); } @Override protected void initHeadPositions(float yOffset, float stretch) { - bipedHead .addBox(HEAD_CENTRE_X - 4, HEAD_CENTRE_Y - 4, HEAD_CENTRE_Z - 4, 8, 8, 8, stretch * 1.1F); - bipedHeadwear.addBox(HEAD_CENTRE_X - 4, HEAD_CENTRE_Y - 4, HEAD_CENTRE_Z - 4, 8, 8, 8, stretch * 1.1F + 0.5F); - - helmet.offset(HEAD_CENTRE_X, HEAD_CENTRE_Y, HEAD_CENTRE_Z) - .around(HEAD_RP_X, HEAD_RP_Y + yOffset, HEAD_RP_Z) - .box(-4, -6, 1, 2, 2, 2, stretch * 0.5F) - .tex(0, 4).box( 2, -6, 1, 2, 2, 2, stretch * 0.5F); - - bipedHead .setRotationPoint(HEAD_RP_X, HEAD_RP_Y + yOffset, HEAD_RP_Z); - bipedHeadwear.setRotationPoint(HEAD_RP_X, HEAD_RP_Y + yOffset, HEAD_RP_Z); + super.initHeadPositions(yOffset, stretch * 1.1F); + ((PonyRenderer)bipedHead).child() + .tex(0, 4).box(2, -6, 1, 2, 2, 2, stretch * 0.5F) + .box(-4, -6, 1, 2, 2, 2, stretch * 0.5F); } @Override protected void initBodyPositions(float yOffset, float stretch) { - bipedBody.setRotationPoint(HEAD_RP_X, HEAD_RP_Y + yOffset, HEAD_RP_Z); - bipedBody.addBox(-4.0F, 4.0F, -2.0F, 8, 8, 4, stretch); - + super.initBodyPositions(yOffset, stretch); flankGuard.around(HEAD_RP_X, HEAD_RP_Y + yOffset, HEAD_RP_Z) - .box(-4.0F, 4.0F, 6.0F, 8, 8, 8, stretch); + .box(-4, 4, 6, 8, 8, 8, stretch); saddle.around(HEAD_RP_X, HEAD_RP_Y + yOffset, HEAD_RP_Z) - .box(-4.0F, 4.0F, -2.0F, 8, 8, 16, stretch); - } - - @Override - protected void initLegPositions(float yOffset, float stretch) { - super.initLegPositions(yOffset, stretch); - - float rarmX = getLegRotationX(); - - float armX = THIRDP_ARM_CENTRE_X; - float armY = THIRDP_ARM_CENTRE_Y; - float armZ = THIRDP_ARM_CENTRE_Z; - - leftLegging.offset(armX + 2, armY, armZ) - .around(rarmX, yOffset, 0) - .box(-2, -6, -2, 4, 12, 4, stretch); - rightLegging.offset(armX - 2, armY, armZ) - .around(-rarmX, yOffset, 0) - .flipX().box(-2, -6, -2, 4, 12, 4, stretch); - } - - protected void syncLegs() { - rightLegging.rotateAt(bipedRightLeg).rotateTo(bipedRightLeg); - leftLegging.rotateAt(bipedLeftLeg).rotateTo(bipedLeftLeg); + .box(-4, 4, -2, 8, 8, 16, stretch); } @Override @@ -200,8 +96,30 @@ public class ModelPonyArmor extends ModelMobPony { super.setVisible(invisible); flankGuard.showModel = invisible; saddle.showModel = invisible; - helmet.showModel = invisible; - leftLegging.showModel = invisible; - rightLegging.showModel = invisible; + bipedHead.showModel = invisible; + tail.isHidden = true; + neck.isHidden = true; + upperTorso.isHidden = true; + snout.isHidden = true; + } + + public void showFeet(boolean show) { + bipedRightArm.showModel = show; + bipedLeftArm.showModel = show; + bipedRightLeg.showModel = show; + bipedLeftLeg.showModel = show; + } + + public void showLegs(boolean isPony) { + bipedBody.showModel = true; + } + + public void showSaddle(boolean isPony) { + flankGuard.showModel = !isPony; + saddle.showModel = isPony; + } + + public void showHead(boolean show) { + bipedHead.showModel = show; } } diff --git a/src/main/java/com/minelittlepony/model/armour/ModelSkeletonPonyArmor.java b/src/main/java/com/minelittlepony/model/armour/ModelSkeletonPonyArmor.java deleted file mode 100644 index a2229dff..00000000 --- a/src/main/java/com/minelittlepony/model/armour/ModelSkeletonPonyArmor.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.minelittlepony.model.armour; - -/** - * Armour for skeleton ponies. - * - */ -public class ModelSkeletonPonyArmor extends ModelPonyArmor { - - @Override - protected void fixSpecialRotationPoints(float move) { - if (rightArmPose != ArmPose.EMPTY && !canCast()) { - bipedRightArm.setRotationPoint(-1.5F, 9.5F, 4); - } - } -} diff --git a/src/main/java/com/minelittlepony/model/armour/ModelZombiePonyArmor.java b/src/main/java/com/minelittlepony/model/armour/ModelZombiePonyArmor.java deleted file mode 100644 index 15a37cba..00000000 --- a/src/main/java/com/minelittlepony/model/armour/ModelZombiePonyArmor.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.minelittlepony.model.armour; - -import com.minelittlepony.render.AbstractPonyRenderer; - -public class ModelZombiePonyArmor extends ModelPonyArmor { - // Copied from ModelZombiePony - @Override - protected void adjustLegs(float move, float swing, float ticks) { - super.adjustLegs(move, swing, ticks); - if (rightArmPose != ArmPose.EMPTY) return; - - if (islookAngleRight(move)) { - rotateArmHolding(bipedRightArm, 1, swingProgress, ticks); - } else { - rotateArmHolding(bipedLeftArm, -1, swingProgress, ticks); - } - } - - @Override - protected void fixSpecialRotationPoints(float move) { - if (rightArmPose != ArmPose.EMPTY) return; - - if (islookAngleRight(move)) { - AbstractPonyRenderer.shiftRotationPoint(bipedRightArm, 0.5F, 1.5F, 3); - } else { - AbstractPonyRenderer.shiftRotationPoint(bipedLeftArm, -0.5F, 1.5F, 3); - } - } -} diff --git a/src/main/java/com/minelittlepony/model/armour/PonyArmor.java b/src/main/java/com/minelittlepony/model/armour/PonyArmor.java index 31aeeec6..fd5f6897 100644 --- a/src/main/java/com/minelittlepony/model/armour/PonyArmor.java +++ b/src/main/java/com/minelittlepony/model/armour/PonyArmor.java @@ -1,6 +1,5 @@ package com.minelittlepony.model.armour; -import com.minelittlepony.model.AbstractPonyModel; import com.minelittlepony.model.capabilities.IModelWrapper; import com.minelittlepony.pony.data.IPonyData; @@ -8,10 +7,10 @@ import net.minecraft.inventory.EntityEquipmentSlot; public class PonyArmor implements IModelWrapper { - public final AbstractPonyModel chestplate; - public final AbstractPonyModel leggings; + public final ModelPonyArmor chestplate; + public final ModelPonyArmor leggings; - public PonyArmor(AbstractPonyModel chest, AbstractPonyModel body) { + public PonyArmor(ModelPonyArmor chest, ModelPonyArmor body) { chestplate = chest; leggings = body; } @@ -26,7 +25,7 @@ public class PonyArmor implements IModelWrapper { leggings.init(0, 0.5f); } - public AbstractPonyModel getArmorForSlot(EntityEquipmentSlot slot) { + public ModelPonyArmor getArmorForSlot(EntityEquipmentSlot slot) { if (slot == EntityEquipmentSlot.LEGS) { return leggings; } diff --git a/src/main/java/com/minelittlepony/model/components/PonySnout.java b/src/main/java/com/minelittlepony/model/components/PonySnout.java index 05c12fd9..6a2066fe 100644 --- a/src/main/java/com/minelittlepony/model/components/PonySnout.java +++ b/src/main/java/com/minelittlepony/model/components/PonySnout.java @@ -9,6 +9,8 @@ import com.minelittlepony.model.AbstractPonyModel; public class PonySnout { + public boolean isHidden = false; + private PlaneRenderer mare; private PlaneRenderer stallion; @@ -43,7 +45,7 @@ public class PonySnout { } public void setGender(PonyGender gender) { - mare.isHidden = gender == PonyGender.STALLION; - stallion.isHidden = !mare.isHidden; + mare.isHidden = !isHidden && gender == PonyGender.STALLION; + stallion.isHidden = !isHidden && !mare.isHidden; } } diff --git a/src/main/java/com/minelittlepony/model/ponies/ModelSkeletonPony.java b/src/main/java/com/minelittlepony/model/ponies/ModelSkeletonPony.java index 0e999a26..0bb5e861 100644 --- a/src/main/java/com/minelittlepony/model/ponies/ModelSkeletonPony.java +++ b/src/main/java/com/minelittlepony/model/ponies/ModelSkeletonPony.java @@ -1,8 +1,6 @@ package com.minelittlepony.model.ponies; import com.minelittlepony.model.ModelMobPony; -import com.minelittlepony.model.armour.ModelSkeletonPonyArmor; -import com.minelittlepony.model.armour.PonyArmor; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.monster.AbstractSkeleton; @@ -12,12 +10,6 @@ import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHandSide; public class ModelSkeletonPony extends ModelMobPony { - - @Override - public PonyArmor createArmour() { - return new PonyArmor(new ModelSkeletonPonyArmor(), new ModelSkeletonPonyArmor()); - } - @Override public boolean isCasting() { return true; diff --git a/src/main/java/com/minelittlepony/model/ponies/ModelZombiePony.java b/src/main/java/com/minelittlepony/model/ponies/ModelZombiePony.java index 6faecbe5..d0a0fbfb 100644 --- a/src/main/java/com/minelittlepony/model/ponies/ModelZombiePony.java +++ b/src/main/java/com/minelittlepony/model/ponies/ModelZombiePony.java @@ -1,17 +1,9 @@ package com.minelittlepony.model.ponies; import com.minelittlepony.model.ModelMobPony; -import com.minelittlepony.model.armour.ModelZombiePonyArmor; -import com.minelittlepony.model.armour.PonyArmor; import com.minelittlepony.render.AbstractPonyRenderer; public class ModelZombiePony extends ModelMobPony { - - @Override - public PonyArmor createArmour() { - return new PonyArmor(new ModelZombiePonyArmor(), new ModelZombiePonyArmor()); - } - @Override protected void adjustLegs(float move, float swing, float ticks) { super.adjustLegs(move, swing, ticks); diff --git a/src/main/java/com/minelittlepony/render/AbstractPonyRenderer.java b/src/main/java/com/minelittlepony/render/AbstractPonyRenderer.java index 6be6717a..6748e0e8 100644 --- a/src/main/java/com/minelittlepony/render/AbstractPonyRenderer.java +++ b/src/main/java/com/minelittlepony/render/AbstractPonyRenderer.java @@ -138,14 +138,22 @@ public abstract class AbstractPonyRenderer> ex */ public T child(int index) { if (childModels == null || index >= childModels.size()) { - T copy = copySelf(); - child(copy.offset(modelOffsetX, modelOffsetY, modelOffsetZ)); - copy.textureHeight = textureHeight; - copy.textureWidth = textureWidth; + return child(); } return (T)childModels.get(index); } + /** + * Returns a brand new child under this renderer. + */ + public T child() { + T copy = copySelf(); + child(copy.offset(modelOffsetX, modelOffsetY, modelOffsetZ)); + copy.textureHeight = textureHeight; + copy.textureWidth = textureWidth; + return copy; + } + /** * Adds a new child renderer and returns itself for chaining. */ diff --git a/src/main/java/com/minelittlepony/render/layer/LayerPonyArmor.java b/src/main/java/com/minelittlepony/render/layer/LayerPonyArmor.java index 8ae87f37..e609ca13 100644 --- a/src/main/java/com/minelittlepony/render/layer/LayerPonyArmor.java +++ b/src/main/java/com/minelittlepony/render/layer/LayerPonyArmor.java @@ -3,7 +3,6 @@ package com.minelittlepony.render.layer; import com.google.common.collect.Maps; import com.minelittlepony.ForgeProxy; import com.minelittlepony.ducks.IRenderPony; -import com.minelittlepony.model.AbstractPonyModel; import com.minelittlepony.model.ModelWrapper; import com.minelittlepony.model.armour.ModelPonyArmor; import com.minelittlepony.util.coordinates.Color; @@ -12,6 +11,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.model.ModelBase; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.entity.RenderLivingBase; +import net.minecraft.client.renderer.entity.layers.LayerArmorBase; import net.minecraft.client.resources.ResourcePackRepository; import net.minecraft.entity.EntityLivingBase; import net.minecraft.inventory.EntityEquipmentSlot; @@ -24,17 +24,13 @@ import net.minecraft.util.Tuple; import javax.annotation.Nullable; -import org.lwjgl.opengl.GL11; - import java.io.IOException; import java.util.Map; public class LayerPonyArmor extends AbstractPonyLayer { - private static final ResourceLocation ENCHANTED_ITEM_GLINT_RES = new ResourceLocation("textures/misc/enchanted_item_glint.png"); - - private static final Map HUMAN_ARMORS = Maps.newHashMap(); - private static final Map PONY_ARMORS = Maps.newHashMap(); + private static final Map HUMAN_ARMOUR = Maps.newHashMap(); + private static final Map PONY_ARMOUR = Maps.newHashMap(); private ModelWrapper pony; @@ -60,26 +56,28 @@ public class LayerPonyArmor extends AbstractPonyLaye ItemArmor itemarmor = (ItemArmor) itemstack.getItem(); - AbstractPonyModel modelbase = pony.getArmor().getArmorForSlot(armorSlot); - modelbase = getArmorModel(entity, itemstack, armorSlot, modelbase); - modelbase.setModelAttributes(pony.getModel()); - modelbase.setRotationAngles(move, swing, ticks, headYaw, headPitch, scale, entity); + ModelPonyArmor armour = getArmorModel(entity, itemstack, armorSlot, pony.getArmor().getArmorForSlot(armorSlot)); + armour.setModelAttributes(pony.getModel()); + armour.setRotationAngles(move, swing, ticks, headYaw, headPitch, scale, entity); + armour.synchroniseLegs(pony.getModel()); Tuple armors = getArmorTexture(entity, itemstack, armorSlot, null); - prepareToRender((ModelPonyArmor) modelbase, armorSlot, armors.getSecond()); + prepareToRender(armour, armorSlot, armors.getSecond()); getRenderer().bindTexture(armors.getFirst()); + if (itemarmor.getArmorMaterial() == ArmorMaterial.LEATHER) { Color.glColor(itemarmor.getColor(itemstack), 1); - modelbase.render(entity, move, swing, ticks, headYaw, headPitch, scale); + armour.render(entity, move, swing, ticks, headYaw, headPitch, scale); armors = getArmorTexture(entity, itemstack, armorSlot, "overlay"); getRenderer().bindTexture(armors.getFirst()); } + GlStateManager.color(1, 1, 1, 1); - modelbase.render(entity, move, swing, ticks, headYaw, headPitch, scale); + armour.render(entity, move, swing, ticks, headYaw, headPitch, scale); if (itemstack.isItemEnchanted()) { - renderEnchantment(entity, modelbase, move, swing, partialTicks, ticks, headYaw, headPitch, scale); + LayerArmorBase.renderEnchantedGlint(getRenderer(), entity, armour, move, swing, partialTicks, ticks, headYaw, headPitch, scale); } } } @@ -87,16 +85,22 @@ public class LayerPonyArmor extends AbstractPonyLaye private Tuple getArmorTexture(T entity, ItemStack itemstack, EntityEquipmentSlot slot, @Nullable String type) { ItemArmor item = (ItemArmor) itemstack.getItem(); String texture = item.getArmorMaterial().getName(); + String domain = "minecraft"; + int idx = texture.indexOf(':'); - if (idx != -1) { + if (idx > -1) { domain = texture.substring(0, idx); texture = texture.substring(idx + 1); } - String s1 = String.format("%s:textures/models/armor/%s_layer_%d%s.png", domain, texture, slot == EntityEquipmentSlot.LEGS ? 2 : 1, - type == null ? "" : String.format("_%s", type)); - s1 = getArmorTexture(entity, itemstack, s1, slot, type); - ResourceLocation human = getHumanResource(s1); + + type = type == null ? "" : String.format("_%s", type); + + String ponyRes = String.format("%s:textures/models/armor/%s_layer_%d%s.png", domain, texture, slot == EntityEquipmentSlot.LEGS ? 2 : 1, type); + + ponyRes = getArmorTexture(entity, itemstack, ponyRes, slot, type); + + ResourceLocation human = getHumanResource(ponyRes); ResourceLocation pony = getPonyResource(human); // check resource packs for either texture. @@ -118,113 +122,48 @@ public class LayerPonyArmor extends AbstractPonyLaye } } - @SuppressWarnings("incomplete-switch") private void prepareToRender(ModelPonyArmor model, EntityEquipmentSlot slot, boolean isPony) { model.setVisible(false); switch (slot) { - // feet - case FEET: - model.bipedRightArm.showModel = true; - model.bipedLeftArm.showModel = true; - model.bipedRightLeg.showModel = !isPony; - model.bipedLeftLeg.showModel = !isPony; - model.leftLegging.showModel = isPony; - model.rightLegging.showModel = isPony; - break; - // legs - case LEGS: - model.bipedRightLeg.showModel = !isPony; - model.bipedLeftLeg.showModel = !isPony; - model.bipedRightArm.showModel = true; - model.bipedLeftArm.showModel = true; - model.bipedBody.showModel = !isPony; - model.flankGuard.showModel = !isPony; - model.saddle.showModel = isPony; - model.leftLegging.showModel = isPony; - model.rightLegging.showModel = isPony; - break; - // chest - case CHEST: - model.saddle.showModel = isPony; - model.bipedBody.showModel = !isPony; - model.flankGuard.showModel = !isPony; - break; - // head case HEAD: - model.bipedHead.showModel = true; - model.helmet.showModel = isPony; + model.showHead(isPony); + break; + case FEET: + model.showFeet(true); + break; + case LEGS: + model.showFeet(true); + model.showLegs(isPony); + case CHEST: + model.showSaddle(isPony); + default: } } - private void renderEnchantment(T entity, ModelBase model, float move, float swing, float partialTicks, float ticks, float headYaw, float headPitch, float scale) { - getRenderer().bindTexture(ENCHANTED_ITEM_GLINT_RES); - - GlStateManager.enableBlend(); - GlStateManager.depthFunc(GL11.GL_EQUAL); - GlStateManager.depthMask(false); - - float brightness = 0.5F; - GlStateManager.color(brightness, brightness, brightness, 1); - - float baseYOffset = entity.ticksExisted + partialTicks; - float glintBrightness = 0.76F; - float scaleFactor = 0.33333334F; - - for (int i = 0; i < 2; i++) { - GlStateManager.disableLighting(); - GlStateManager.blendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE); - - GlStateManager.color(glintBrightness / 2, glintBrightness / 4, 0.8F * glintBrightness, 1); - - GlStateManager.matrixMode(5890); - GlStateManager.loadIdentity(); - - - GlStateManager.scale(scaleFactor, scaleFactor, scaleFactor); - GlStateManager.rotate(30 - i * 60, 0, 0, 1); - GlStateManager.translate(0, baseYOffset * (0.02F + i * 0.06F), 0); - GlStateManager.matrixMode(GL11.GL_MODELVIEW); - - model.render(entity, move, swing, ticks, headYaw, headPitch, scale); - } - - GlStateManager.matrixMode(GL11.GL_TEXTURE); - GlStateManager.loadIdentity(); - GlStateManager.matrixMode(GL11.GL_MODELVIEW); - GlStateManager.enableLighting(); - GlStateManager.depthMask(true); - GlStateManager.depthFunc(GL11.GL_LEQUAL); - GlStateManager.disableBlend(); - } - - private static ResourceLocation getHumanResource(String s1) { - return HUMAN_ARMORS.computeIfAbsent(s1, ResourceLocation::new); + private static ResourceLocation getHumanResource(String resource) { + return HUMAN_ARMOUR.computeIfAbsent(resource, ResourceLocation::new); } private static ResourceLocation getPonyResource(ResourceLocation human) { - ResourceLocation pony = PONY_ARMORS.get(human); - if (pony == null) { + return PONY_ARMOUR.computeIfAbsent(human, key -> { String domain = human.getResourceDomain(); - String path = human.getResourcePath(); - if (domain.equals("minecraft")) { + if ("minecraft".equals(domain)) { domain = "minelittlepony"; // it's a vanilla armor. I provide these. } - path = path.replace(".png", "_pony.png"); - pony = new ResourceLocation(domain, path); - PONY_ARMORS.put(human, pony); - } - return pony; + String path = human.getResourcePath().replace(".png", "_pony.png"); + return new ResourceLocation(domain, path); + }); } private static String getArmorTexture(EntityLivingBase entity, ItemStack item, String def, EntityEquipmentSlot slot, @Nullable String type) { return ForgeProxy.getArmorTexture(entity, item, def, slot, type); } - private static AbstractPonyModel getArmorModel(EntityLivingBase entity, ItemStack itemstack, EntityEquipmentSlot slot, AbstractPonyModel def) { + private static ModelPonyArmor getArmorModel(EntityLivingBase entity, ItemStack itemstack, EntityEquipmentSlot slot, ModelPonyArmor def) { ModelBase model = ForgeProxy.getArmorModel(entity, itemstack, slot, def); if (model instanceof ModelPonyArmor) { - return (AbstractPonyModel) model; + return (ModelPonyArmor) model; } return def;