diff --git a/src/api/java/com/minelittlepony/api/armor/package-info.java b/src/api/java/com/minelittlepony/api/armor/package-info.java new file mode 100644 index 00000000..abae6cfc --- /dev/null +++ b/src/api/java/com/minelittlepony/api/armor/package-info.java @@ -0,0 +1,7 @@ +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault +package com.minelittlepony.api.armor; + +import mcp.MethodsReturnNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/src/api/java/com/minelittlepony/api/events/Armor.java b/src/api/java/com/minelittlepony/api/events/Armor.java new file mode 100644 index 00000000..83035460 --- /dev/null +++ b/src/api/java/com/minelittlepony/api/events/Armor.java @@ -0,0 +1,48 @@ +package com.minelittlepony.api.events; + +import java.util.ArrayList; +import java.util.List; + +import com.minelittlepony.model.capabilities.IModelArmor; + +import net.minecraft.client.model.ModelBiped; +import net.minecraft.entity.Entity; +import net.minecraft.inventory.EntityEquipmentSlot; + +class Armor implements EventBus, IPreArmorEventHandler { + + private final List handlers = new ArrayList(); + + @Override + public IPreArmorEventHandler dispatcher() { + return this; + } + + public void addEventListener(IPreArmorEventHandler handler) { + if (handler == this) return; + + handlers.add(handler); + } + + private boolean cancel = false; + + @Override + public boolean preRenderPonyArmor(T armour, Entity entity, float move, float swing, float partialTicks, float ticks, float headYaw, float headPitch, float scale, EntityEquipmentSlot armourSlot) { + if (handlers.size() == 0) return false; + + handlers.forEach(handler -> { + cancel |= handler.preRenderPonyArmor(armour, entity, move, swing, partialTicks, ticks, headYaw, headPitch, scale, armourSlot); + }); + + return cancel; + } + + @Override + public void postRenderPonyArmor(T armour, Entity entity, float move, float swing, float partialTicks, float ticks, float headYaw, float headPitch, float scale, EntityEquipmentSlot armourSlot) { + if (handlers.size() == 0) return; + + handlers.forEach(handler -> { + handler.postRenderPonyArmor(armour, entity, move, swing, partialTicks, ticks, headYaw, headPitch, scale, armourSlot); + }); + } +} diff --git a/src/api/java/com/minelittlepony/api/events/EventBus.java b/src/api/java/com/minelittlepony/api/events/EventBus.java new file mode 100644 index 00000000..8a4881cf --- /dev/null +++ b/src/api/java/com/minelittlepony/api/events/EventBus.java @@ -0,0 +1,10 @@ +package com.minelittlepony.api.events; + +public interface EventBus { + + public static final EventBus ARMOR = new Armor(); + + T dispatcher(); + + void addEventListener(T handler); +} diff --git a/src/api/java/com/minelittlepony/api/events/IPreArmorEventHandler.java b/src/api/java/com/minelittlepony/api/events/IPreArmorEventHandler.java new file mode 100644 index 00000000..a3bb75e9 --- /dev/null +++ b/src/api/java/com/minelittlepony/api/events/IPreArmorEventHandler.java @@ -0,0 +1,15 @@ +package com.minelittlepony.api.events; + +import com.minelittlepony.model.capabilities.IModelArmor; + +import net.minecraft.client.model.ModelBiped; +import net.minecraft.entity.Entity; +import net.minecraft.inventory.EntityEquipmentSlot; + +public interface IPreArmorEventHandler { + + boolean preRenderPonyArmor(T armour, Entity entity, float move, float swing, float partialTicks, float ticks, float headYaw, float headPitch, float scale, EntityEquipmentSlot armourSlot); + + + void postRenderPonyArmor(T armour, Entity entity, float move, float swing, float partialTicks, float ticks, float headYaw, float headPitch, float scale, EntityEquipmentSlot armourSlot); +} diff --git a/src/api/java/com/minelittlepony/api/events/package-info.java b/src/api/java/com/minelittlepony/api/events/package-info.java new file mode 100644 index 00000000..c5b87a6c --- /dev/null +++ b/src/api/java/com/minelittlepony/api/events/package-info.java @@ -0,0 +1,7 @@ +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault +package com.minelittlepony.api.events; + +import mcp.MethodsReturnNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/src/main/java/com/minelittlepony/model/armour/ModelPonyArmor.java b/src/main/java/com/minelittlepony/model/armour/ModelPonyArmor.java index 6b1b6d1c..e9b27576 100644 --- a/src/main/java/com/minelittlepony/model/armour/ModelPonyArmor.java +++ b/src/main/java/com/minelittlepony/model/armour/ModelPonyArmor.java @@ -1,13 +1,16 @@ package com.minelittlepony.model.armour; +import net.minecraft.client.model.ModelBiped; import net.minecraft.entity.Entity; import static com.minelittlepony.model.PonyModelConstants.*; import com.minelittlepony.model.AbstractPonyModel; +import com.minelittlepony.model.capabilities.IModel; +import com.minelittlepony.model.capabilities.IModelArmor; import com.minelittlepony.render.PonyRenderer; -public class ModelPonyArmor extends AbstractPonyModel { +public class ModelPonyArmor extends AbstractPonyModel implements IModelArmor { public PonyRenderer flankGuard; @@ -49,7 +52,7 @@ public class ModelPonyArmor extends AbstractPonyModel { super.renderLegs(scale); } - public void synchroniseLegs(AbstractPonyModel mainModel) { + public void synchroniseLegs(T mainModel) { copyModelAngles(mainModel.bipedRightArm, bipedRightArm); copyModelAngles(mainModel.bipedLeftArm, bipedLeftArm); copyModelAngles(mainModel.bipedRightLeg, bipedRightLeg); diff --git a/src/main/java/com/minelittlepony/model/capabilities/IModelArmor.java b/src/main/java/com/minelittlepony/model/capabilities/IModelArmor.java new file mode 100644 index 00000000..fcbc7273 --- /dev/null +++ b/src/main/java/com/minelittlepony/model/capabilities/IModelArmor.java @@ -0,0 +1,15 @@ +package com.minelittlepony.model.capabilities; + +import net.minecraft.client.model.ModelBiped; + +public interface IModelArmor extends IModel { + void synchroniseLegs(T model); + + void showFeet(boolean show); + + void showLegs(boolean isPony); + + void showSaddle(boolean isPony); + + void showHead(boolean show); +} diff --git a/src/main/java/com/minelittlepony/render/layer/LayerPonyArmor.java b/src/main/java/com/minelittlepony/render/layer/LayerPonyArmor.java index 44ea0314..a007589c 100644 --- a/src/main/java/com/minelittlepony/render/layer/LayerPonyArmor.java +++ b/src/main/java/com/minelittlepony/render/layer/LayerPonyArmor.java @@ -2,12 +2,15 @@ package com.minelittlepony.render.layer; import com.google.common.collect.Maps; import com.minelittlepony.ForgeProxy; +import com.minelittlepony.api.events.EventBus; import com.minelittlepony.model.ModelWrapper; import com.minelittlepony.model.armour.ModelPonyArmor; +import com.minelittlepony.model.capabilities.IModelArmor; import com.minelittlepony.util.coordinates.Color; import net.minecraft.client.Minecraft; import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelBiped; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.entity.RenderLivingBase; import net.minecraft.client.renderer.entity.layers.LayerArmorBase; @@ -48,7 +51,7 @@ public class LayerPonyArmor extends AbstractPonyLaye } } - private void renderArmor(T entity, float move, float swing, float partialTicks, float ticks, float headYaw, float headPitch, float scale, EntityEquipmentSlot armorSlot) { + private void renderArmor(T entity, float move, float swing, float partialTicks, float ticks, float headYaw, float headPitch, float scale, EntityEquipmentSlot armorSlot) { ItemStack itemstack = entity.getItemStackFromSlot(armorSlot); if (!itemstack.isEmpty() && itemstack.getItem() instanceof ItemArmor) { @@ -65,6 +68,10 @@ public class LayerPonyArmor extends AbstractPonyLaye getRenderer().bindTexture(armors.getFirst()); + if (EventBus.ARMOR.dispatcher().preRenderPonyArmor(armour, entity, move, swing, partialTicks, ticks, headYaw, headPitch, scale, armorSlot)) { + return; + } + if (itemarmor.getArmorMaterial() == ArmorMaterial.LEATHER) { Color.glColor(itemarmor.getColor(itemstack), 1); armour.render(entity, move, swing, ticks, headYaw, headPitch, scale); @@ -78,6 +85,8 @@ public class LayerPonyArmor extends AbstractPonyLaye if (itemstack.isItemEnchanted()) { LayerArmorBase.renderEnchantedGlint(getRenderer(), entity, armour, move, swing, partialTicks, ticks, headYaw, headPitch, scale); } + + EventBus.ARMOR.dispatcher().postRenderPonyArmor(armour, entity, move, swing, partialTicks, ticks, headYaw, headPitch, scale, armorSlot); } } @@ -121,7 +130,7 @@ public class LayerPonyArmor extends AbstractPonyLaye } } - private void prepareToRender(ModelPonyArmor model, EntityEquipmentSlot slot, boolean isPony) { + private void prepareToRender(V model, EntityEquipmentSlot slot, boolean isPony) { model.setVisible(false); switch (slot) { @@ -161,8 +170,9 @@ public class LayerPonyArmor extends AbstractPonyLaye 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 (ModelPonyArmor) model; + return (ModelPonyArmor)model; } return def;