More stability improvements. (Null value and checks to ensure keys exist)

This commit is contained in:
Doug Gabehart 2016-12-14 20:35:43 -06:00
parent 6ceff6d783
commit 6364378437
2 changed files with 7 additions and 5 deletions

View file

@ -397,7 +397,9 @@ public class ArmorData {
public void change(Map aMap, StatType aType, float aChange){
float tChange = 0;
if(aMap==null)System.out.println("changeMapnull");
if(aMap.containsKey(aType)){tChange = (float) aMap.get(aType);
if(aMap.containsKey(aType)){
Object value = aMap.get(aType);
tChange = value != null ? (float) aMap.get(aType) : 0.0f;
aMap.remove(aType);
}
aMap.put(aType, (tChange + aChange));

View file

@ -102,12 +102,12 @@ public class GuiElectricArmor1 extends GuiContainer {
default:
break;
}
if(cont.mInvArmor.data.mStat.get(StatType.TANKCAP)>0){
float tankCap = cont.mInvArmor.data.mStat.containsKey(StatType.TANKCAP) ? cont.mInvArmor.data.mStat.get(StatType.TANKCAP) :0.0f;
if(tankCap>0){
drawTexturedModalRect(xStart + 94, yStart + 32, 231, 69, 16, 34);
}
int bar = (int) Math.floor(18 * (cont.mInvArmor.data.mStat.get(StatType.WEIGHT)/(float)1000));
float weight = cont.mInvArmor.data.mStat.containsKey(StatType.WEIGHT) ? cont.mInvArmor.data.mStat.get(StatType.WEIGHT) : 0.0f;
int bar = (int) Math.floor(18 * (weight)/(float)1000);
drawTexturedModalRect(xStart + 15, yStart + 7, 217, 26, bar, 5);
drawTexturedModalRect(xStart + bar + 15, yStart + 7, 197+bar, 26, 18-bar, 5);