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 gregtech.api.GregTech_API;
|
||||
import gregtech.api.util.GT_Log;
|
||||
import gregtech.api.util.GT_Utility;
|
||||
import gregtech.common.items.armor.ArmorData;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -20,25 +21,35 @@ public abstract class ArmorComponent implements IArmorComponent {
|
|||
public Map<StatType,Boolean> mBStat = new HashMap<StatType,Boolean>();
|
||||
|
||||
public ArmorComponent(String aName, String aOreDict, boolean aElectric, float aWeight){
|
||||
mConfigName = aName;
|
||||
if(!GregTech_API.sModularArmor.get( mConfigName, "Enabled", true))return;
|
||||
mOreDict = GregTech_API.sModularArmor.get( mConfigName, "OreDict", aOreDict);
|
||||
mBStat.put(StatType.ELECTRIC, aElectric);
|
||||
mOreDicts.put(aOreDict, this);
|
||||
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));
|
||||
try {
|
||||
mConfigName = aName;
|
||||
if(!GregTech_API.sModularArmor.get( mConfigName, "Enabled", true))return;
|
||||
mOreDict = GregTech_API.sModularArmor.get( mConfigName, "OreDict", aOreDict);
|
||||
mBStat.put(StatType.ELECTRIC, aElectric);
|
||||
mOreDicts.put(aOreDict, this);
|
||||
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){
|
||||
mConfigName = aName;
|
||||
String tStackName = GregTech_API.sModularArmor.get( mConfigName, "Stack", GameRegistry.findUniqueIdentifierFor(aStack.getItem()).toString()+(aStack.getItemDamage()==0 ? "" : ":"+aStack.getItemDamage()));
|
||||
mStack = GameRegistry.findItemStack(tStackName.split(":")[0], tStackName.split(":")[1], 1);
|
||||
if(tStackName.split(":").length>2)mStack.setItemDamage(Integer.parseInt(tStackName.split(":")[2]));
|
||||
if(!GregTech_API.sModularArmor.get( mConfigName, "Enabled", true))return;
|
||||
mStack = aStack;
|
||||
mBStat.put(StatType.ELECTRIC, aElectric);
|
||||
mStacks.put(aStack.getUnlocalizedName(), this);
|
||||
mStat.put(StatType.WEIGHT, (float) GregTech_API.sModularArmor.get( mConfigName, "Weight", aWeight));
|
||||
try {
|
||||
mConfigName = aName;
|
||||
String tStackName = GregTech_API.sModularArmor.get( mConfigName, "Stack", GameRegistry.findUniqueIdentifierFor(aStack.getItem()).toString()+(aStack.getItemDamage()==0 ? "" : ":"+aStack.getItemDamage()));
|
||||
mStack = GameRegistry.findItemStack(tStackName.split(":")[0], tStackName.split(":")[1], 1);
|
||||
if(tStackName.split(":").length>2)mStack.setItemDamage(Integer.parseInt(tStackName.split(":")[2]));
|
||||
if(!GregTech_API.sModularArmor.get( mConfigName, "Enabled", true))return;
|
||||
mStack = aStack;
|
||||
mBStat.put(StatType.ELECTRIC, aElectric);
|
||||
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
|
||||
|
@ -53,8 +64,8 @@ public abstract class ArmorComponent implements IArmorComponent {
|
|||
public void addVal(StatType aType, ArmorData aArmorData){
|
||||
float tArmorDef = 0.0f;
|
||||
if(aArmorData.mStat.containsKey(aType)){
|
||||
tArmorDef = aArmorData.mStat.get(aType);
|
||||
aArmorData.mStat.remove(aType);}
|
||||
tArmorDef = aArmorData.mStat.get(aType);
|
||||
aArmorData.mStat.remove(aType);}
|
||||
aArmorData.mStat.put(aType, tArmorDef + mStat.get(aType));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue