Fix modded armors.

Bug 1: forge postinit wasn't being called. Probably issue with event stub. Got rid of it to avoid the hassle.
Bug 2: ForgeHooksClient stub had bad signatures.
This commit is contained in:
Matthew Messinger 2017-03-28 02:02:23 -04:00
parent 9fc2650f44
commit f09a76b152
11 changed files with 51 additions and 148 deletions

View file

@ -1,17 +1,19 @@
package net.minecraftforge.client;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
// stub
public class ForgeHooksClient {
public static String getArmorTexture(EntityLivingBase entity, ItemStack armor, String def, int slot, String type) {
public static String getArmorTexture(Entity entity, ItemStack armor, String def, EntityEquipmentSlot slot, String type) {
return def;
}
public static ModelBase getArmorModel(EntityLivingBase entity, ItemStack item, int slot, ModelBase def) {
public static ModelBiped getArmorModel(EntityLivingBase entity, ItemStack item, EntityEquipmentSlot slot, ModelBiped def) {
return def;
}

View file

@ -1,24 +0,0 @@
package net.minecraftforge.fml.common;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
// stub
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Mod {
String modid();
String name() default "";
String version() default "";
boolean clientSideOnly() default false;
public @interface EventHandler {
}
}

View file

@ -1,4 +0,0 @@
package net.minecraftforge.fml.common.event;
// stub
public class FMLPostInitializationEvent {}

View file

@ -0,0 +1,27 @@
package com.minelittlepony;
import com.mumfrey.liteloader.util.ModUtilities;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.ForgeHooksClient;
public class ForgeProxy {
private static boolean forgeLoaded = ModUtilities.fmlIsPresent();
public static String getArmorTexture(Entity entity, ItemStack armor, String def, EntityEquipmentSlot slot, String type) {
if (forgeLoaded)
return ForgeHooksClient.getArmorTexture(entity, armor, def, slot, type);
return def;
}
public static ModelBiped getArmorModel(EntityLivingBase entity, ItemStack item, EntityEquipmentSlot slot, ModelBiped def) {
if (forgeLoaded)
return ForgeHooksClient.getArmorModel(entity, item, slot, def);
return def;
}
}

View file

@ -46,7 +46,6 @@ public class MineLittlePony {
private PonyConfig config;
private PonyManager ponyManager;
private ProxyContainer proxy;
private Map<Class<? extends Entity>, Render<?>> renderMap = Maps.newHashMap();
@ -59,7 +58,6 @@ public class MineLittlePony {
this.config = new PonyConfig();
this.ponyManager = new PonyManager(config);
this.proxy = new ProxyContainer();
LiteLoader.getInstance().registerExposable(config, null);
@ -159,10 +157,6 @@ public class MineLittlePony {
return this.ponyManager;
}
public static ProxyContainer getProxy() {
return getInstance().proxy;
}
public static PonyConfig getConfig() {
return getInstance().config;
}

View file

@ -1,21 +0,0 @@
package com.minelittlepony;
import com.minelittlepony.forge.IForgeHooks;
import com.minelittlepony.forge.MLPCommonProxy;
import javax.annotation.Nullable;
public class ProxyContainer extends MLPCommonProxy {
private IForgeHooks ponyArmors;
@Override
public void setForgeHooks(IForgeHooks armors) {
this.ponyArmors = armors;
}
@Nullable
public IForgeHooks getHooks() {
return ponyArmors;
}
}

View file

@ -1,20 +0,0 @@
package com.minelittlepony.forge;
import net.minecraft.client.model.ModelBase;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.ForgeHooksClient;
public class ForgePonyHooks implements IForgeHooks {
@Override
public String getArmorTexture(EntityLivingBase entity, ItemStack armor, String def, int slot, String type) {
return ForgeHooksClient.getArmorTexture(entity, armor, def, slot, type);
}
@Override
public ModelBase getArmorModel(EntityLivingBase entity, ItemStack item, int slot, ModelBase def) {
return ForgeHooksClient.getArmorModel(entity, item, slot, def);
}
}

View file

@ -1,12 +0,0 @@
package com.minelittlepony.forge;
import net.minecraft.client.model.ModelBase;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
public interface IForgeHooks {
String getArmorTexture(EntityLivingBase e, ItemStack item, String def, int slot, String type);
ModelBase getArmorModel(EntityLivingBase e, ItemStack item, int slot, ModelBase def);
}

View file

@ -1,16 +0,0 @@
package com.minelittlepony.forge;
public abstract class MLPCommonProxy {
private static MLPCommonProxy instance;
public static MLPCommonProxy getInstance() {
return instance;
}
public MLPCommonProxy() {
instance = this;
}
public abstract void setForgeHooks(IForgeHooks armors);
}

View file

@ -1,20 +0,0 @@
package com.minelittlepony.forge;
import com.minelittlepony.MineLittlePony;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
@Mod(
modid = "minelp_forge",
name = "MineLP Forge Hooks",
version = MineLittlePony.MOD_VERSION,
clientSideOnly = true)
public class MLPForge {
@SuppressWarnings("unused")
@EventHandler
public void init(FMLPostInitializationEvent init) {
MLPCommonProxy.getInstance().setForgeHooks(new ForgePonyHooks());
}
}

View file

@ -1,9 +1,8 @@
package com.minelittlepony.renderer.layer;
import com.google.common.collect.Maps;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.ForgeProxy;
import com.minelittlepony.ducks.IRenderPony;
import com.minelittlepony.forge.IForgeHooks;
import com.minelittlepony.model.AbstractPonyModel;
import com.minelittlepony.model.PlayerModel;
import com.minelittlepony.model.pony.ModelHumanPlayer;
@ -64,14 +63,18 @@ public class LayerPonyArmor implements LayerRenderer<EntityLivingBase> {
if (itemstack != null && itemstack.getItem() instanceof ItemArmor) {
ItemArmor itemarmor = (ItemArmor) itemstack.getItem();
boolean isLegs = armorSlot == EntityEquipmentSlot.LEGS;
AbstractPonyModel modelbase = isLegs ? pony.getArmor().modelArmor : pony.getArmor().modelArmorChestplate;
modelbase = getArmorModel(entity, itemstack, isLegs ? 2 : 1, modelbase);
AbstractPonyModel modelbase;
if (armorSlot == EntityEquipmentSlot.LEGS) {
modelbase = pony.getArmor().modelArmor;
} else {
modelbase = pony.getArmor().modelArmorChestplate;
}
modelbase = getArmorModel(entity, itemstack, armorSlot, modelbase);
modelbase.setModelAttributes(this.pony.getModel());
modelbase.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale, entity);
Tuple<ResourceLocation, Boolean> armors = getArmorTexture(entity, itemstack, isLegs ? 2 : 1, null);
Tuple<ResourceLocation, Boolean> armors = getArmorTexture(entity, itemstack, armorSlot, null);
prepareToRender((ModelPonyArmor) modelbase, armorSlot, armors.getSecond());
this.renderer.bindTexture(armors.getFirst());
@ -82,7 +85,7 @@ public class LayerPonyArmor implements LayerRenderer<EntityLivingBase> {
float f9 = (j & 255) / 255.0F;
GlStateManager.color(f7, f8, f9, 1);
modelbase.render(entity, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale);
armors = getArmorTexture(entity, itemstack, isLegs ? 2 : 1, "overlay");
armors = getArmorTexture(entity, itemstack, armorSlot, "overlay");
this.renderer.bindTexture(armors.getFirst());
}
GlStateManager.color(1, 1, 1, 1);
@ -94,7 +97,7 @@ public class LayerPonyArmor implements LayerRenderer<EntityLivingBase> {
}
}
private Tuple<ResourceLocation, Boolean> getArmorTexture(EntityLivingBase entity, ItemStack itemstack, int slot, String type) {
private Tuple<ResourceLocation, Boolean> getArmorTexture(EntityLivingBase entity, ItemStack itemstack, EntityEquipmentSlot slot, String type) {
ItemArmor item = (ItemArmor) itemstack.getItem();
String texture = item.getArmorMaterial().getName();
String domain = "minecraft";
@ -103,7 +106,7 @@ public class LayerPonyArmor implements LayerRenderer<EntityLivingBase> {
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 == 2 ? 2 : 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);
@ -230,22 +233,16 @@ public class LayerPonyArmor implements LayerRenderer<EntityLivingBase> {
return pony;
}
private static String getArmorTexture(EntityLivingBase entity, ItemStack item, String def, int slot, String type) {
IForgeHooks armor = MineLittlePony.getProxy().getHooks();
if (armor != null) {
return armor.getArmorTexture(entity, item, def, slot, type);
}
return def;
private static String getArmorTexture(EntityLivingBase entity, ItemStack item, String def, EntityEquipmentSlot slot, String type) {
return ForgeProxy.getArmorTexture(entity, item, def, slot, type);
}
private static AbstractPonyModel getArmorModel(EntityLivingBase entity, ItemStack itemstack, int slot, AbstractPonyModel def) {
IForgeHooks armor = MineLittlePony.getProxy().getHooks();
if (armor != null) {
ModelBase model = armor.getArmorModel(entity, itemstack, slot, def);
if (model instanceof ModelPonyArmor) {
return (AbstractPonyModel) model;
}
private static AbstractPonyModel getArmorModel(EntityLivingBase entity, ItemStack itemstack, EntityEquipmentSlot slot, AbstractPonyModel def) {
ModelBase model = ForgeProxy.getArmorModel(entity, itemstack, slot, def);
if (model instanceof ModelPonyArmor) {
return (AbstractPonyModel) model;
}
return def;
}