From da5c9851489dfe18393045a7e265457504449058 Mon Sep 17 00:00:00 2001 From: Sollace Date: Fri, 12 Oct 2018 18:01:23 +0200 Subject: [PATCH] Decouple armour from the rest of the models system --- .../java/com/minelittlepony/ducks/IRenderPony.java | 4 ++-- .../java/com/minelittlepony/model/ModelWrapper.java | 6 +++--- .../model/armour/IEquestrianArmor.java | 9 +++++++-- .../com/minelittlepony/model/armour/PonyArmor.java | 7 +++---- .../minelittlepony/model/capabilities/IModel.java | 4 ++-- .../model/capabilities/IModelArmor.java | 2 +- .../minelittlepony/render/layer/LayerPonyArmor.java | 13 +++++++------ .../render/layer/LayerPonyCustomHead.java | 5 +++-- 8 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/minelittlepony/ducks/IRenderPony.java b/src/main/java/com/minelittlepony/ducks/IRenderPony.java index 66885726..023668eb 100644 --- a/src/main/java/com/minelittlepony/ducks/IRenderPony.java +++ b/src/main/java/com/minelittlepony/ducks/IRenderPony.java @@ -1,8 +1,8 @@ package com.minelittlepony.ducks; -import com.minelittlepony.model.AbstractPonyModel; import com.minelittlepony.model.BodyPart; import com.minelittlepony.model.ModelWrapper; +import com.minelittlepony.model.capabilities.IModel; import com.minelittlepony.pony.data.IPony; import com.minelittlepony.render.RenderPony; import com.minelittlepony.util.math.MathUtil; @@ -31,7 +31,7 @@ public interface IRenderPony { float yaw = MathUtil.interpolateDegress(entity.prevRenderYawOffset, entity.renderYawOffset, ticks); getModelWrapper().apply(entityPony.getMetadata()); - AbstractPonyModel model = getModelWrapper().getBody(); + IModel model = getModelWrapper().getBody(); model.transform(BodyPart.BACK); diff --git a/src/main/java/com/minelittlepony/model/ModelWrapper.java b/src/main/java/com/minelittlepony/model/ModelWrapper.java index 7d5c9ff1..3b7334ea 100644 --- a/src/main/java/com/minelittlepony/model/ModelWrapper.java +++ b/src/main/java/com/minelittlepony/model/ModelWrapper.java @@ -2,7 +2,6 @@ package com.minelittlepony.model; import com.minelittlepony.MineLittlePony; import com.minelittlepony.model.armour.IEquestrianArmor; -import com.minelittlepony.model.armour.PonyArmor; import com.minelittlepony.model.capabilities.IModelWrapper; import com.minelittlepony.pony.data.IPonyData; @@ -12,7 +11,8 @@ import com.minelittlepony.pony.data.IPonyData; public class ModelWrapper implements IModelWrapper { private final AbstractPonyModel body; - private final PonyArmor armor; + + private final IEquestrianArmor armor; private int lastModelUpdate = 0; @@ -38,7 +38,7 @@ public class ModelWrapper implements IModelWrapper { /** * Returns the contained armour model. */ - public IEquestrianArmor getArmor() { + public IEquestrianArmor getArmor() { return armor; } diff --git a/src/main/java/com/minelittlepony/model/armour/IEquestrianArmor.java b/src/main/java/com/minelittlepony/model/armour/IEquestrianArmor.java index e14c8514..c5bc8884 100644 --- a/src/main/java/com/minelittlepony/model/armour/IEquestrianArmor.java +++ b/src/main/java/com/minelittlepony/model/armour/IEquestrianArmor.java @@ -1,7 +1,12 @@ package com.minelittlepony.model.armour; -public interface IEquestrianArmor { - ModelPonyArmor getArmorForLayer(ArmorLayer layer); +import net.minecraft.client.model.ModelBiped; + +import com.minelittlepony.model.capabilities.IModelArmor; +import com.minelittlepony.model.capabilities.IModelWrapper; + +public interface IEquestrianArmor extends IModelWrapper { + V getArmorForLayer(ArmorLayer layer); enum ArmorLayer { INNER, diff --git a/src/main/java/com/minelittlepony/model/armour/PonyArmor.java b/src/main/java/com/minelittlepony/model/armour/PonyArmor.java index 72917857..94dc05de 100644 --- a/src/main/java/com/minelittlepony/model/armour/PonyArmor.java +++ b/src/main/java/com/minelittlepony/model/armour/PonyArmor.java @@ -1,12 +1,11 @@ package com.minelittlepony.model.armour; -import com.minelittlepony.model.capabilities.IModelWrapper; import com.minelittlepony.pony.data.IPonyData; -public class PonyArmor implements IModelWrapper, IEquestrianArmor { +public class PonyArmor implements IEquestrianArmor { - public ModelPonyArmor outerLayer; - public ModelPonyArmor innerLayer; + private final ModelPonyArmor outerLayer; + private final ModelPonyArmor innerLayer; public PonyArmor(ModelPonyArmor outer, ModelPonyArmor inner) { outerLayer = outer; diff --git a/src/main/java/com/minelittlepony/model/capabilities/IModel.java b/src/main/java/com/minelittlepony/model/capabilities/IModel.java index 3e7a4900..4c4a8531 100644 --- a/src/main/java/com/minelittlepony/model/capabilities/IModel.java +++ b/src/main/java/com/minelittlepony/model/capabilities/IModel.java @@ -1,7 +1,7 @@ package com.minelittlepony.model.capabilities; import com.minelittlepony.model.BodyPart; -import com.minelittlepony.model.armour.PonyArmor; +import com.minelittlepony.model.armour.IEquestrianArmor; import com.minelittlepony.pony.data.IPonyData; import com.minelittlepony.pony.data.PonySize; import com.minelittlepony.pony.data.PonyWearable; @@ -25,7 +25,7 @@ public interface IModel extends ICapitated { /** * Returns a new pony armour to go with this model. Called on startup by a model wrapper. */ - PonyArmor createArmour(); + IEquestrianArmor createArmour(); IPonyData getMetadata(); diff --git a/src/main/java/com/minelittlepony/model/capabilities/IModelArmor.java b/src/main/java/com/minelittlepony/model/capabilities/IModelArmor.java index 4256b4e6..1a24fd94 100644 --- a/src/main/java/com/minelittlepony/model/capabilities/IModelArmor.java +++ b/src/main/java/com/minelittlepony/model/capabilities/IModelArmor.java @@ -5,7 +5,7 @@ import net.minecraft.inventory.EntityEquipmentSlot; import com.minelittlepony.model.armour.IEquestrianArmor.ArmorLayer; -public interface IModelArmor extends IModel { +public interface IModelArmor { /** * Called to synchronise this model's legs with that of another. * diff --git a/src/main/java/com/minelittlepony/render/layer/LayerPonyArmor.java b/src/main/java/com/minelittlepony/render/layer/LayerPonyArmor.java index 11082964..4157f177 100644 --- a/src/main/java/com/minelittlepony/render/layer/LayerPonyArmor.java +++ b/src/main/java/com/minelittlepony/render/layer/LayerPonyArmor.java @@ -5,7 +5,6 @@ import com.minelittlepony.model.ModelWrapper; import com.minelittlepony.model.armour.IEquestrianArmor; import com.minelittlepony.model.armour.IEquestrianArmor.ArmorLayer; import com.minelittlepony.model.armour.IArmorTextureResolver; -import com.minelittlepony.model.armour.ModelPonyArmor; import com.minelittlepony.model.armour.DefaultPonyArmorTextureResolver; import com.minelittlepony.model.capabilities.IModelArmor; import com.minelittlepony.util.render.Color; @@ -50,7 +49,8 @@ public class LayerPonyArmor extends AbstractPonyLaye if (!itemstack.isEmpty() && itemstack.getItem() instanceof ItemArmor) { - ModelPonyArmor armour = getArmorModel(entity, itemstack, armorSlot, layer, pony.getArmor().getArmorForLayer(layer)); + @SuppressWarnings("unchecked") + V armour = getArmorModel(entity, itemstack, armorSlot, layer, (V)pony.getArmor().getArmorForLayer(layer)); if (armour.prepareToRender(armorSlot, layer)) { @@ -84,15 +84,16 @@ public class LayerPonyArmor extends AbstractPonyLaye } } - private static ModelPonyArmor getArmorModel(EntityLivingBase entity, ItemStack itemstack, EntityEquipmentSlot slot, ArmorLayer layer, ModelPonyArmor def) { + @SuppressWarnings("unchecked") + private static V getArmorModel(EntityLivingBase entity, ItemStack itemstack, EntityEquipmentSlot slot, ArmorLayer layer, V def) { ModelBase model = ForgeProxy.getArmorModel(entity, itemstack, slot, def); - if (model instanceof ModelPonyArmor) { - return (ModelPonyArmor)model; + if (model instanceof IModelArmor) { + return (V)model; } if (model instanceof IEquestrianArmor) { - return ((IEquestrianArmor) model).getArmorForLayer(layer); + return ((IEquestrianArmor) model).getArmorForLayer(layer); } return def; diff --git a/src/main/java/com/minelittlepony/render/layer/LayerPonyCustomHead.java b/src/main/java/com/minelittlepony/render/layer/LayerPonyCustomHead.java index 2e338b53..63540118 100644 --- a/src/main/java/com/minelittlepony/render/layer/LayerPonyCustomHead.java +++ b/src/main/java/com/minelittlepony/render/layer/LayerPonyCustomHead.java @@ -11,6 +11,7 @@ import com.minelittlepony.ducks.IRenderPony; import com.minelittlepony.model.AbstractPonyModel; import com.minelittlepony.model.BodyPart; import com.minelittlepony.model.ModelWrapper; +import com.minelittlepony.model.capabilities.IModel; import com.minelittlepony.render.skull.PonySkullRenderer; import com.mojang.authlib.GameProfile; import net.minecraft.client.Minecraft; @@ -42,13 +43,13 @@ public class LayerPonyCustomHead implements LayerRen public void doRenderLayer(T entity, float move, float swing, float partialTicks, float ticks, float headYaw, float headPitch, float scale) { ItemStack itemstack = entity.getItemStackFromSlot(EntityEquipmentSlot.HEAD); if (!itemstack.isEmpty()) { - AbstractPonyModel model = getModel().getBody(); + IModel model = getModel().getBody(); Item item = itemstack.getItem(); pushMatrix(); model.transform(BodyPart.HEAD); - model.bipedHead.postRender(0.0625f); + model.getHead().postRender(0.0625f); if (model instanceof AbstractPonyModel) { translate(0, 0.2F, 0);