Fix crash when SmartRenderer not installed.

This commit is contained in:
Leon 2016-11-21 19:12:17 -05:00
parent ee386d1158
commit eb3f4aa016
6 changed files with 53 additions and 42 deletions

View file

@ -5,6 +5,5 @@ import net.machinemuse.api.electricity.IModularItem;
/**
* Ported to Java by lehjr on 11/4/16.
*/
public interface IArmorTraits extends IModularItem, IApiaristArmor
{
public interface IArmorTraits extends IModularItem, IApiaristArmor {
}

View file

@ -1,26 +1,28 @@
package net.machinemuse.powersuits.client.render.item;
import net.machinemuse.numina.general.MuseLogger;
import net.machinemuse.powersuits.common.ModCompatibility;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.nbt.NBTTagCompound;
/**
* Author: MachineMuse (Claire Semple)
* Created: 10:01 PM, 11/07/13
*/
public class ArmorModelInstance {
private static ModelBiped instance = null;
private static NBTTagCompound renderSpec;
public static ModelBiped getInstance() {
// TODO: Actual (skinned) vanilla model as low bandwitdth alternative
if (instance == null) {
try {
MuseLogger.logInfo("Attempting to load Smart Moving armor model.");
instance = SMovingArmorModel.getInstance();
MuseLogger.logInfo("Smart Moving armor model loaded successfully!");
} catch (Throwable e) {
MuseLogger.logInfo("Smart Moving armor model did not load successfully. Either Smart Moving is not installed, or there was another problem.");
if ( ModCompatibility.isRenderPlayerAPILoaded()) {
try {
MuseLogger.logInfo("Attempting to load SmartMoving armor model.");
instance = Class.forName("net.machinemuse.powersuits.client.render.item.SMovingArmorModel").asSubclass(ModelBiped.class).newInstance();
MuseLogger.logInfo("SmartMoving armor model loaded successfully!");
} catch (Exception e) {
MuseLogger.logInfo("Smart Moving armor model did not load successfully. Either Smart Moving is not installed, or there was another problem.");
instance = VanillaArmorModel.getInstance();
}
} else {
instance = VanillaArmorModel.getInstance();
}
}

View file

@ -1,6 +1,7 @@
package net.machinemuse.powersuits.client.render.item;
import api.player.model.ModelPlayer;
import cpw.mods.fml.common.Optional;
import net.machinemuse.powersuits.client.render.modelspec.RenderPart;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
@ -24,7 +25,7 @@ public class SMovingArmorModel extends ModelPlayer implements IArmorModel {
public static int visibleSection = 0;
private SmartRenderModelPlayerBase renderPlayerBase = SmartRender.getPlayerBase(this);
private SMovingArmorModel() {
public SMovingArmorModel() {
super(0);
SmartRenderModel model = renderPlayerBase.getRenderModel();

View file

@ -86,6 +86,9 @@ public class Config {
/**
* Called in post-init. Extracts recipes if the configuration value is not found.
*/
// TODO: a better idea might be to extract all of the recipes and then only read the ones that are valid.
// This would save on requests for recipe downloads
public static void extractRecipes() {
String key = "Auto-extract recipes";
if (!config.hasKey(Configuration.CATEGORY_GENERAL, key) || config.get(Configuration.CATEGORY_GENERAL, key, false).getBoolean()) {

View file

@ -1,7 +1,9 @@
package net.machinemuse.powersuits.common;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModAPIManager;
import cpw.mods.fml.relauncher.Side;
import net.machinemuse.api.ModuleManager;
import net.machinemuse.api.electricity.IModularItem;
import net.machinemuse.numina.general.MuseLogger;
@ -81,6 +83,10 @@ public class ModCompatibility {
return Loader.isModLoaded("CompactMachines");
}
public static boolean isRenderPlayerAPILoaded() {
return Loader.isModLoaded("RenderPlayerAPI");
}
public static boolean enableThaumGogglesModule() {
boolean defaultval = isThaumCraftLoaded();
return Config.getConfig().get("Special Modules", "Thaumcraft Goggles Module", defaultval).getBoolean(defaultval);

View file

@ -37,17 +37,17 @@ import java.util.UUID;
* Ported to Java by lehjr on 11/4/16.
*/
public abstract class ItemPowerArmor extends ItemElectricArmor implements ISpecialArmor, IArmorTraits {
public ItemPowerArmor(final int renderIndex, final int armorType) {
public ItemPowerArmor(int renderIndex, int armorType) {
super(ItemArmor.ArmorMaterial.IRON, renderIndex, armorType);
this.setMaxStackSize(1);
this.setCreativeTab(Config.getCreativeTab());
}
public ISpecialArmor.ArmorProperties getProperties(final EntityLivingBase player, final ItemStack armor, final DamageSource source, final double damage, final int slot) {
final int priority = 0;
public ISpecialArmor.ArmorProperties getProperties(EntityLivingBase player, ItemStack armor, DamageSource source, double damage, int slot) {
int priority = 0;
Label_0057: {
if (source.isFireDamage()) {
final DamageSource overheatDamage = MuseHeatUtils.overheatDamage;
DamageSource overheatDamage = MuseHeatUtils.overheatDamage;
if (source == null) {
if (overheatDamage == null) {
break Label_0057;
@ -69,7 +69,7 @@ public abstract class ItemPowerArmor extends ItemElectricArmor implements ISpeci
else {
armorDouble2 = 2.0;
}
final double armorDouble = armorDouble2;
double armorDouble = armorDouble2;
double absorbRatio = 0.04 * armorDouble;
int absorbMax = (int)armorDouble * 75;
if (source.isUnblockable()) {
@ -79,18 +79,18 @@ public abstract class ItemPowerArmor extends ItemElectricArmor implements ISpeci
return new ISpecialArmor.ArmorProperties(priority, absorbRatio, absorbMax);
}
public String getArmorTexture(final ItemStack itemstack, final Entity entity, final int slot, final int layer) {
public String getArmorTexture(ItemStack itemstack, Entity entity, int slot, int layer) {
return Config.BLANK_ARMOR_MODEL_PATH;
}
public int getColor(final ItemStack stack) {
final Colour c = this.getColorFromItemStack(stack);
public int getColor(ItemStack stack) {
Colour c = this.getColorFromItemStack(stack);
return c.getInt();
}
@SideOnly(Side.CLIENT)
public ModelBiped getArmorModel(final EntityLivingBase entity, final ItemStack itemstack, final int armorSlot) {
final ModelBiped model = ArmorModelInstance.getInstance();
public ModelBiped getArmorModel(EntityLivingBase entity, ItemStack itemstack, int armorSlot) {
ModelBiped model = ArmorModelInstance.getInstance();
((IArmorModel)model).setVisibleSection(armorSlot);
if (itemstack != null) {
if (entity instanceof EntityPlayer) {
@ -111,8 +111,8 @@ public abstract class ItemPowerArmor extends ItemElectricArmor implements ISpeci
return (ModelBiped)model;
}
public Multimap<?, ?> getAttributeModifiers(final ItemStack stack) {
final Multimap parent = super.getAttributeModifiers(stack);
public Multimap<?, ?> getAttributeModifiers(ItemStack stack) {
Multimap parent = super.getAttributeModifiers(stack);
parent.put((Object)"generic.knockbackResistance", (Object)new AttributeModifier(UUID.fromString("448ef0e9-9b7c-4e56-bf3a-6b52aeabff8d"), "generic.knockbackResistance", 0.25, 0));
return (Multimap<?, ?>)parent;
}
@ -121,27 +121,27 @@ public abstract class ItemPowerArmor extends ItemElectricArmor implements ISpeci
return 0;
}
public boolean hasColor(final ItemStack stack) {
final NBTTagCompound itemTag = MuseItemUtils.getMuseItemTag(stack);
public boolean hasColor(ItemStack stack) {
NBTTagCompound itemTag = MuseItemUtils.getMuseItemTag(stack);
return ModuleManager.tagHasModule(itemTag, "Red Tint") || ModuleManager.tagHasModule(itemTag, "Green Tint") || ModuleManager.tagHasModule(itemTag, "Blue Tint");
}
public int getArmorDisplay(final EntityPlayer player, final ItemStack armor, final int slot) {
public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot) {
return (int)this.getArmorDouble(player, armor);
}
public double getHeatResistance(final EntityPlayer player, final ItemStack stack) {
public double getHeatResistance(EntityPlayer player, ItemStack stack) {
return MuseHeatUtils.getMaxHeat(stack);
}
@Override
public double getArmorDouble(final EntityPlayer player, final ItemStack stack) {
public double getArmorDouble(EntityPlayer player, ItemStack stack) {
double totalArmor = 0.0;
final NBTTagCompound props = MuseItemUtils.getMuseItemTag(stack);
final double energy = ElectricItemUtils.getPlayerEnergy(player);
final double physArmor = ModuleManager.computeModularProperty(stack, MuseCommonStrings.ARMOR_VALUE_PHYSICAL);
final double enerArmor = ModuleManager.computeModularProperty(stack, MuseCommonStrings.ARMOR_VALUE_ENERGY);
final double enerConsum = ModuleManager.computeModularProperty(stack, MuseCommonStrings.ARMOR_ENERGY_CONSUMPTION);
NBTTagCompound props = MuseItemUtils.getMuseItemTag(stack);
double energy = ElectricItemUtils.getPlayerEnergy(player);
double physArmor = ModuleManager.computeModularProperty(stack, MuseCommonStrings.ARMOR_VALUE_PHYSICAL);
double enerArmor = ModuleManager.computeModularProperty(stack, MuseCommonStrings.ARMOR_VALUE_ENERGY);
double enerConsum = ModuleManager.computeModularProperty(stack, MuseCommonStrings.ARMOR_ENERGY_CONSUMPTION);
totalArmor += physArmor;
if (energy > enerConsum) {
totalArmor += enerArmor;
@ -154,10 +154,10 @@ public abstract class ItemPowerArmor extends ItemElectricArmor implements ISpeci
* Inherited from ISpecialArmor, allows us to customize how the armor
* handles being damaged.
*/
public void damageArmor(final EntityLivingBase entity, final ItemStack stack, final DamageSource source, final int damage, final int slot) {
final NBTTagCompound itemProperties = MuseItemUtils.getMuseItemTag(stack);
public void damageArmor(EntityLivingBase entity, ItemStack stack, DamageSource source, int damage, int slot) {
NBTTagCompound itemProperties = MuseItemUtils.getMuseItemTag(stack);
if (entity instanceof EntityPlayer) {
final DamageSource overheatDamage = MuseHeatUtils.overheatDamage;
DamageSource overheatDamage = MuseHeatUtils.overheatDamage;
if (source == null) {
if (overheatDamage == null) {
return;
@ -167,14 +167,14 @@ public abstract class ItemPowerArmor extends ItemElectricArmor implements ISpeci
return;
}
if (source.isFireDamage()) {
final EntityPlayer player = (EntityPlayer)entity;
EntityPlayer player = (EntityPlayer)entity;
if (!source.equals(DamageSource.onFire) || MuseHeatUtils.getPlayerHeat(player) < MuseHeatUtils.getMaxHeat(player)) {
MuseHeatUtils.heatPlayer(player, damage);
}
}
else {
final double enerConsum = ModuleManager.computeModularProperty(stack, MuseCommonStrings.ARMOR_ENERGY_CONSUMPTION);
final double drain = enerConsum * damage;
double enerConsum = ModuleManager.computeModularProperty(stack, MuseCommonStrings.ARMOR_ENERGY_CONSUMPTION);
double drain = enerConsum * damage;
if (entity instanceof EntityPlayer) {
ElectricItemUtils.drainPlayerEnergy((EntityPlayer)entity, drain);
}
@ -186,12 +186,12 @@ public abstract class ItemPowerArmor extends ItemElectricArmor implements ISpeci
}
@Optional.Method(modid = "Forestry")
public boolean protectPlayer(final EntityPlayer player, final ItemStack armor, final String cause, final boolean doProtect) {
public boolean protectPlayer(EntityPlayer player, ItemStack armor, String cause, boolean doProtect) {
return ApiaristArmor.getInstance().protectPlayer(player, armor, cause, doProtect);
}
@Optional.Method(modid = "Forestry")
public boolean protectEntity(final EntityLivingBase player, final ItemStack armor, final String cause, final boolean doProtect) {
public boolean protectEntity(EntityLivingBase player, ItemStack armor, String cause, boolean doProtect) {
return ApiaristArmor.getInstance().protectEntity(player, armor, cause, doProtect);
}
}