mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-26 22:38:00 +01:00
Add armour apis
This commit is contained in:
parent
910dbd43c0
commit
f8084c2975
8 changed files with 120 additions and 5 deletions
|
@ -0,0 +1,7 @@
|
||||||
|
@MethodsReturnNonnullByDefault
|
||||||
|
@ParametersAreNonnullByDefault
|
||||||
|
package com.minelittlepony.api.armor;
|
||||||
|
|
||||||
|
import mcp.MethodsReturnNonnullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.ParametersAreNonnullByDefault;
|
48
src/api/java/com/minelittlepony/api/events/Armor.java
Normal file
48
src/api/java/com/minelittlepony/api/events/Armor.java
Normal file
|
@ -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>, IPreArmorEventHandler {
|
||||||
|
|
||||||
|
private final List<IPreArmorEventHandler> handlers = new ArrayList<IPreArmorEventHandler>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPreArmorEventHandler dispatcher() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addEventListener(IPreArmorEventHandler handler) {
|
||||||
|
if (handler == this) return;
|
||||||
|
|
||||||
|
handlers.add(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean cancel = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T extends ModelBiped & IModelArmor> 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 <T extends ModelBiped & IModelArmor> 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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
10
src/api/java/com/minelittlepony/api/events/EventBus.java
Normal file
10
src/api/java/com/minelittlepony/api/events/EventBus.java
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
package com.minelittlepony.api.events;
|
||||||
|
|
||||||
|
public interface EventBus<T> {
|
||||||
|
|
||||||
|
public static final EventBus<IPreArmorEventHandler> ARMOR = new Armor();
|
||||||
|
|
||||||
|
T dispatcher();
|
||||||
|
|
||||||
|
void addEventListener(T handler);
|
||||||
|
}
|
|
@ -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 {
|
||||||
|
<T extends ModelBiped & IModelArmor>
|
||||||
|
boolean preRenderPonyArmor(T armour, Entity entity, float move, float swing, float partialTicks, float ticks, float headYaw, float headPitch, float scale, EntityEquipmentSlot armourSlot);
|
||||||
|
|
||||||
|
<T extends ModelBiped & IModelArmor>
|
||||||
|
void postRenderPonyArmor(T armour, Entity entity, float move, float swing, float partialTicks, float ticks, float headYaw, float headPitch, float scale, EntityEquipmentSlot armourSlot);
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
@MethodsReturnNonnullByDefault
|
||||||
|
@ParametersAreNonnullByDefault
|
||||||
|
package com.minelittlepony.api.events;
|
||||||
|
|
||||||
|
import mcp.MethodsReturnNonnullByDefault;
|
||||||
|
|
||||||
|
import javax.annotation.ParametersAreNonnullByDefault;
|
|
@ -1,13 +1,16 @@
|
||||||
package com.minelittlepony.model.armour;
|
package com.minelittlepony.model.armour;
|
||||||
|
|
||||||
|
import net.minecraft.client.model.ModelBiped;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
|
|
||||||
import static com.minelittlepony.model.PonyModelConstants.*;
|
import static com.minelittlepony.model.PonyModelConstants.*;
|
||||||
|
|
||||||
import com.minelittlepony.model.AbstractPonyModel;
|
import com.minelittlepony.model.AbstractPonyModel;
|
||||||
|
import com.minelittlepony.model.capabilities.IModel;
|
||||||
|
import com.minelittlepony.model.capabilities.IModelArmor;
|
||||||
import com.minelittlepony.render.PonyRenderer;
|
import com.minelittlepony.render.PonyRenderer;
|
||||||
|
|
||||||
public class ModelPonyArmor extends AbstractPonyModel {
|
public class ModelPonyArmor extends AbstractPonyModel implements IModelArmor {
|
||||||
|
|
||||||
public PonyRenderer flankGuard;
|
public PonyRenderer flankGuard;
|
||||||
|
|
||||||
|
@ -49,7 +52,7 @@ public class ModelPonyArmor extends AbstractPonyModel {
|
||||||
super.renderLegs(scale);
|
super.renderLegs(scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void synchroniseLegs(AbstractPonyModel mainModel) {
|
public <T extends ModelBiped & IModel> void synchroniseLegs(T mainModel) {
|
||||||
copyModelAngles(mainModel.bipedRightArm, bipedRightArm);
|
copyModelAngles(mainModel.bipedRightArm, bipedRightArm);
|
||||||
copyModelAngles(mainModel.bipedLeftArm, bipedLeftArm);
|
copyModelAngles(mainModel.bipedLeftArm, bipedLeftArm);
|
||||||
copyModelAngles(mainModel.bipedRightLeg, bipedRightLeg);
|
copyModelAngles(mainModel.bipedRightLeg, bipedRightLeg);
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.minelittlepony.model.capabilities;
|
||||||
|
|
||||||
|
import net.minecraft.client.model.ModelBiped;
|
||||||
|
|
||||||
|
public interface IModelArmor extends IModel {
|
||||||
|
<T extends ModelBiped & IModel> void synchroniseLegs(T model);
|
||||||
|
|
||||||
|
void showFeet(boolean show);
|
||||||
|
|
||||||
|
void showLegs(boolean isPony);
|
||||||
|
|
||||||
|
void showSaddle(boolean isPony);
|
||||||
|
|
||||||
|
void showHead(boolean show);
|
||||||
|
}
|
|
@ -2,12 +2,15 @@ package com.minelittlepony.render.layer;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.minelittlepony.ForgeProxy;
|
import com.minelittlepony.ForgeProxy;
|
||||||
|
import com.minelittlepony.api.events.EventBus;
|
||||||
import com.minelittlepony.model.ModelWrapper;
|
import com.minelittlepony.model.ModelWrapper;
|
||||||
import com.minelittlepony.model.armour.ModelPonyArmor;
|
import com.minelittlepony.model.armour.ModelPonyArmor;
|
||||||
|
import com.minelittlepony.model.capabilities.IModelArmor;
|
||||||
import com.minelittlepony.util.coordinates.Color;
|
import com.minelittlepony.util.coordinates.Color;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.model.ModelBase;
|
import net.minecraft.client.model.ModelBase;
|
||||||
|
import net.minecraft.client.model.ModelBiped;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
import net.minecraft.client.renderer.entity.RenderLivingBase;
|
import net.minecraft.client.renderer.entity.RenderLivingBase;
|
||||||
import net.minecraft.client.renderer.entity.layers.LayerArmorBase;
|
import net.minecraft.client.renderer.entity.layers.LayerArmorBase;
|
||||||
|
@ -48,7 +51,7 @@ public class LayerPonyArmor<T extends EntityLivingBase> extends AbstractPonyLaye
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderArmor(T entity, float move, float swing, float partialTicks, float ticks, float headYaw, float headPitch, float scale, EntityEquipmentSlot armorSlot) {
|
private <V extends ModelBiped & IModelArmor> 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);
|
ItemStack itemstack = entity.getItemStackFromSlot(armorSlot);
|
||||||
|
|
||||||
if (!itemstack.isEmpty() && itemstack.getItem() instanceof ItemArmor) {
|
if (!itemstack.isEmpty() && itemstack.getItem() instanceof ItemArmor) {
|
||||||
|
@ -65,6 +68,10 @@ public class LayerPonyArmor<T extends EntityLivingBase> extends AbstractPonyLaye
|
||||||
|
|
||||||
getRenderer().bindTexture(armors.getFirst());
|
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) {
|
if (itemarmor.getArmorMaterial() == ArmorMaterial.LEATHER) {
|
||||||
Color.glColor(itemarmor.getColor(itemstack), 1);
|
Color.glColor(itemarmor.getColor(itemstack), 1);
|
||||||
armour.render(entity, move, swing, ticks, headYaw, headPitch, scale);
|
armour.render(entity, move, swing, ticks, headYaw, headPitch, scale);
|
||||||
|
@ -78,6 +85,8 @@ public class LayerPonyArmor<T extends EntityLivingBase> extends AbstractPonyLaye
|
||||||
if (itemstack.isItemEnchanted()) {
|
if (itemstack.isItemEnchanted()) {
|
||||||
LayerArmorBase.renderEnchantedGlint(getRenderer(), entity, armour, move, swing, partialTicks, ticks, headYaw, headPitch, scale);
|
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<T extends EntityLivingBase> extends AbstractPonyLaye
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prepareToRender(ModelPonyArmor model, EntityEquipmentSlot slot, boolean isPony) {
|
private <V extends ModelBiped & IModelArmor> void prepareToRender(V model, EntityEquipmentSlot slot, boolean isPony) {
|
||||||
model.setVisible(false);
|
model.setVisible(false);
|
||||||
|
|
||||||
switch (slot) {
|
switch (slot) {
|
||||||
|
@ -161,6 +170,7 @@ public class LayerPonyArmor<T extends EntityLivingBase> extends AbstractPonyLaye
|
||||||
|
|
||||||
private static ModelPonyArmor getArmorModel(EntityLivingBase entity, ItemStack itemstack, EntityEquipmentSlot slot, ModelPonyArmor def) {
|
private static ModelPonyArmor getArmorModel(EntityLivingBase entity, ItemStack itemstack, EntityEquipmentSlot slot, ModelPonyArmor def) {
|
||||||
ModelBase model = ForgeProxy.getArmorModel(entity, itemstack, slot, def);
|
ModelBase model = ForgeProxy.getArmorModel(entity, itemstack, slot, def);
|
||||||
|
|
||||||
if (model instanceof ModelPonyArmor) {
|
if (model instanceof ModelPonyArmor) {
|
||||||
return (ModelPonyArmor)model;
|
return (ModelPonyArmor)model;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue