mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-26 06:18:00 +01:00
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:
parent
9fc2650f44
commit
f09a76b152
11 changed files with 51 additions and 148 deletions
|
@ -1,17 +1,19 @@
|
||||||
package net.minecraftforge.client;
|
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.entity.EntityLivingBase;
|
||||||
|
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
// stub
|
// stub
|
||||||
public class ForgeHooksClient {
|
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;
|
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;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +0,0 @@
|
||||||
package net.minecraftforge.fml.common.event;
|
|
||||||
|
|
||||||
// stub
|
|
||||||
public class FMLPostInitializationEvent {}
|
|
27
src/main/java/com/minelittlepony/ForgeProxy.java
Normal file
27
src/main/java/com/minelittlepony/ForgeProxy.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -46,7 +46,6 @@ public class MineLittlePony {
|
||||||
|
|
||||||
private PonyConfig config;
|
private PonyConfig config;
|
||||||
private PonyManager ponyManager;
|
private PonyManager ponyManager;
|
||||||
private ProxyContainer proxy;
|
|
||||||
|
|
||||||
private Map<Class<? extends Entity>, Render<?>> renderMap = Maps.newHashMap();
|
private Map<Class<? extends Entity>, Render<?>> renderMap = Maps.newHashMap();
|
||||||
|
|
||||||
|
@ -59,7 +58,6 @@ public class MineLittlePony {
|
||||||
|
|
||||||
this.config = new PonyConfig();
|
this.config = new PonyConfig();
|
||||||
this.ponyManager = new PonyManager(config);
|
this.ponyManager = new PonyManager(config);
|
||||||
this.proxy = new ProxyContainer();
|
|
||||||
|
|
||||||
LiteLoader.getInstance().registerExposable(config, null);
|
LiteLoader.getInstance().registerExposable(config, null);
|
||||||
|
|
||||||
|
@ -159,10 +157,6 @@ public class MineLittlePony {
|
||||||
return this.ponyManager;
|
return this.ponyManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ProxyContainer getProxy() {
|
|
||||||
return getInstance().proxy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PonyConfig getConfig() {
|
public static PonyConfig getConfig() {
|
||||||
return getInstance().config;
|
return getInstance().config;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -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());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +1,8 @@
|
||||||
package com.minelittlepony.renderer.layer;
|
package com.minelittlepony.renderer.layer;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.minelittlepony.MineLittlePony;
|
import com.minelittlepony.ForgeProxy;
|
||||||
import com.minelittlepony.ducks.IRenderPony;
|
import com.minelittlepony.ducks.IRenderPony;
|
||||||
import com.minelittlepony.forge.IForgeHooks;
|
|
||||||
import com.minelittlepony.model.AbstractPonyModel;
|
import com.minelittlepony.model.AbstractPonyModel;
|
||||||
import com.minelittlepony.model.PlayerModel;
|
import com.minelittlepony.model.PlayerModel;
|
||||||
import com.minelittlepony.model.pony.ModelHumanPlayer;
|
import com.minelittlepony.model.pony.ModelHumanPlayer;
|
||||||
|
@ -64,14 +63,18 @@ public class LayerPonyArmor implements LayerRenderer<EntityLivingBase> {
|
||||||
if (itemstack != null && itemstack.getItem() instanceof ItemArmor) {
|
if (itemstack != null && itemstack.getItem() instanceof ItemArmor) {
|
||||||
|
|
||||||
ItemArmor itemarmor = (ItemArmor) itemstack.getItem();
|
ItemArmor itemarmor = (ItemArmor) itemstack.getItem();
|
||||||
boolean isLegs = armorSlot == EntityEquipmentSlot.LEGS;
|
|
||||||
|
|
||||||
AbstractPonyModel modelbase = isLegs ? pony.getArmor().modelArmor : pony.getArmor().modelArmorChestplate;
|
AbstractPonyModel modelbase;
|
||||||
modelbase = getArmorModel(entity, itemstack, isLegs ? 2 : 1, 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.setModelAttributes(this.pony.getModel());
|
||||||
modelbase.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale, entity);
|
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());
|
prepareToRender((ModelPonyArmor) modelbase, armorSlot, armors.getSecond());
|
||||||
|
|
||||||
this.renderer.bindTexture(armors.getFirst());
|
this.renderer.bindTexture(armors.getFirst());
|
||||||
|
@ -82,7 +85,7 @@ public class LayerPonyArmor implements LayerRenderer<EntityLivingBase> {
|
||||||
float f9 = (j & 255) / 255.0F;
|
float f9 = (j & 255) / 255.0F;
|
||||||
GlStateManager.color(f7, f8, f9, 1);
|
GlStateManager.color(f7, f8, f9, 1);
|
||||||
modelbase.render(entity, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale);
|
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());
|
this.renderer.bindTexture(armors.getFirst());
|
||||||
}
|
}
|
||||||
GlStateManager.color(1, 1, 1, 1);
|
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();
|
ItemArmor item = (ItemArmor) itemstack.getItem();
|
||||||
String texture = item.getArmorMaterial().getName();
|
String texture = item.getArmorMaterial().getName();
|
||||||
String domain = "minecraft";
|
String domain = "minecraft";
|
||||||
|
@ -103,7 +106,7 @@ public class LayerPonyArmor implements LayerRenderer<EntityLivingBase> {
|
||||||
domain = texture.substring(0, idx);
|
domain = texture.substring(0, idx);
|
||||||
texture = texture.substring(idx + 1);
|
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));
|
type == null ? "" : String.format("_%s", type));
|
||||||
s1 = getArmorTexture(entity, itemstack, s1, slot, type);
|
s1 = getArmorTexture(entity, itemstack, s1, slot, type);
|
||||||
ResourceLocation human = getHumanResource(s1);
|
ResourceLocation human = getHumanResource(s1);
|
||||||
|
@ -230,22 +233,16 @@ public class LayerPonyArmor implements LayerRenderer<EntityLivingBase> {
|
||||||
return pony;
|
return pony;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getArmorTexture(EntityLivingBase entity, ItemStack item, String def, int slot, String type) {
|
private static String getArmorTexture(EntityLivingBase entity, ItemStack item, String def, EntityEquipmentSlot slot, String type) {
|
||||||
IForgeHooks armor = MineLittlePony.getProxy().getHooks();
|
return ForgeProxy.getArmorTexture(entity, item, def, slot, type);
|
||||||
if (armor != null) {
|
|
||||||
return armor.getArmorTexture(entity, item, def, slot, type);
|
|
||||||
}
|
|
||||||
return def;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AbstractPonyModel getArmorModel(EntityLivingBase entity, ItemStack itemstack, int slot, AbstractPonyModel def) {
|
private static AbstractPonyModel getArmorModel(EntityLivingBase entity, ItemStack itemstack, EntityEquipmentSlot slot, AbstractPonyModel def) {
|
||||||
IForgeHooks armor = MineLittlePony.getProxy().getHooks();
|
ModelBase model = ForgeProxy.getArmorModel(entity, itemstack, slot, def);
|
||||||
if (armor != null) {
|
if (model instanceof ModelPonyArmor) {
|
||||||
ModelBase model = armor.getArmorModel(entity, itemstack, slot, def);
|
return (AbstractPonyModel) model;
|
||||||
if (model instanceof ModelPonyArmor) {
|
|
||||||
return (AbstractPonyModel) model;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue