Added a failsafe for invalid Modular armour components.
This commit is contained in:
parent
2d8df8d145
commit
c4b245af9b
1 changed files with 32 additions and 21 deletions
|
@ -2,6 +2,7 @@ package gregtech.common.items.armor.components;
|
||||||
|
|
||||||
import cpw.mods.fml.common.registry.GameRegistry;
|
import cpw.mods.fml.common.registry.GameRegistry;
|
||||||
import gregtech.api.GregTech_API;
|
import gregtech.api.GregTech_API;
|
||||||
|
import gregtech.api.util.GT_Log;
|
||||||
import gregtech.api.util.GT_Utility;
|
import gregtech.api.util.GT_Utility;
|
||||||
import gregtech.common.items.armor.ArmorData;
|
import gregtech.common.items.armor.ArmorData;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -18,27 +19,37 @@ public abstract class ArmorComponent implements IArmorComponent {
|
||||||
public static Map<String, ArmorComponent> mStacks = new HashMap<String, ArmorComponent>();
|
public static Map<String, ArmorComponent> mStacks = new HashMap<String, ArmorComponent>();
|
||||||
public Map<StatType,Float> mStat = new HashMap<StatType,Float>();
|
public Map<StatType,Float> mStat = new HashMap<StatType,Float>();
|
||||||
public Map<StatType,Boolean> mBStat = new HashMap<StatType,Boolean>();
|
public Map<StatType,Boolean> mBStat = new HashMap<StatType,Boolean>();
|
||||||
|
|
||||||
public ArmorComponent(String aName, String aOreDict, boolean aElectric, float aWeight){
|
public ArmorComponent(String aName, String aOreDict, boolean aElectric, float aWeight){
|
||||||
mConfigName = aName;
|
try {
|
||||||
if(!GregTech_API.sModularArmor.get( mConfigName, "Enabled", true))return;
|
mConfigName = aName;
|
||||||
mOreDict = GregTech_API.sModularArmor.get( mConfigName, "OreDict", aOreDict);
|
if(!GregTech_API.sModularArmor.get( mConfigName, "Enabled", true))return;
|
||||||
mBStat.put(StatType.ELECTRIC, aElectric);
|
mOreDict = GregTech_API.sModularArmor.get( mConfigName, "OreDict", aOreDict);
|
||||||
mOreDicts.put(aOreDict, this);
|
mBStat.put(StatType.ELECTRIC, aElectric);
|
||||||
for(ItemStack tStack : OreDictionary.getOres(aOreDict))if(tStack!=null)mStacks.put(tStack.getUnlocalizedName(), this);
|
mOreDicts.put(aOreDict, this);
|
||||||
mStat.put(StatType.WEIGHT, (float) GregTech_API.sModularArmor.get( mConfigName, "Weight", aWeight));
|
for(ItemStack tStack : OreDictionary.getOres(aOreDict))if(tStack!=null)mStacks.put(tStack.getUnlocalizedName(), this);
|
||||||
|
mStat.put(StatType.WEIGHT, (float) GregTech_API.sModularArmor.get( mConfigName, "Weight", aWeight));
|
||||||
|
}
|
||||||
|
catch (Throwable t){
|
||||||
|
GT_Log.out.println("Tried adding "+aName+" as a modular armour component, however it failed.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArmorComponent(String aName, ItemStack aStack, boolean aElectric, float aWeight){
|
public ArmorComponent(String aName, ItemStack aStack, boolean aElectric, float aWeight){
|
||||||
mConfigName = aName;
|
try {
|
||||||
String tStackName = GregTech_API.sModularArmor.get( mConfigName, "Stack", GameRegistry.findUniqueIdentifierFor(aStack.getItem()).toString()+(aStack.getItemDamage()==0 ? "" : ":"+aStack.getItemDamage()));
|
mConfigName = aName;
|
||||||
mStack = GameRegistry.findItemStack(tStackName.split(":")[0], tStackName.split(":")[1], 1);
|
String tStackName = GregTech_API.sModularArmor.get( mConfigName, "Stack", GameRegistry.findUniqueIdentifierFor(aStack.getItem()).toString()+(aStack.getItemDamage()==0 ? "" : ":"+aStack.getItemDamage()));
|
||||||
if(tStackName.split(":").length>2)mStack.setItemDamage(Integer.parseInt(tStackName.split(":")[2]));
|
mStack = GameRegistry.findItemStack(tStackName.split(":")[0], tStackName.split(":")[1], 1);
|
||||||
if(!GregTech_API.sModularArmor.get( mConfigName, "Enabled", true))return;
|
if(tStackName.split(":").length>2)mStack.setItemDamage(Integer.parseInt(tStackName.split(":")[2]));
|
||||||
mStack = aStack;
|
if(!GregTech_API.sModularArmor.get( mConfigName, "Enabled", true))return;
|
||||||
mBStat.put(StatType.ELECTRIC, aElectric);
|
mStack = aStack;
|
||||||
mStacks.put(aStack.getUnlocalizedName(), this);
|
mBStat.put(StatType.ELECTRIC, aElectric);
|
||||||
mStat.put(StatType.WEIGHT, (float) GregTech_API.sModularArmor.get( mConfigName, "Weight", aWeight));
|
mStacks.put(aStack.getUnlocalizedName(), this);
|
||||||
|
mStat.put(StatType.WEIGHT, (float) GregTech_API.sModularArmor.get( mConfigName, "Weight", aWeight));
|
||||||
|
}
|
||||||
|
catch (Throwable t){
|
||||||
|
GT_Log.out.println("Tried adding "+aName+" as a modular armour component, however it failed.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -49,12 +60,12 @@ public abstract class ArmorComponent implements IArmorComponent {
|
||||||
if(GT_Utility.areStacksEqual(tStack, aStack, true))return true;}
|
if(GT_Utility.areStacksEqual(tStack, aStack, true))return true;}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addVal(StatType aType, ArmorData aArmorData){
|
public void addVal(StatType aType, ArmorData aArmorData){
|
||||||
float tArmorDef = 0.0f;
|
float tArmorDef = 0.0f;
|
||||||
if(aArmorData.mStat.containsKey(aType)){
|
if(aArmorData.mStat.containsKey(aType)){
|
||||||
tArmorDef = aArmorData.mStat.get(aType);
|
tArmorDef = aArmorData.mStat.get(aType);
|
||||||
aArmorData.mStat.remove(aType);}
|
aArmorData.mStat.remove(aType);}
|
||||||
aArmorData.mStat.put(aType, tArmorDef + mStat.get(aType));
|
aArmorData.mStat.put(aType, tArmorDef + mStat.get(aType));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue