Added updateArmorStats method which includes additional checks to ensure that values are not null and the key in question exists in mStats

Removed player.closeScreen call in mouseClicked to prevent display glitch when switching armor gui tabs; (mouse focus from returning to 2x2 crafting grid)
This commit is contained in:
Doug Gabehart 2016-12-14 11:12:07 -06:00
parent 248b88e8bc
commit df00993c0d
2 changed files with 53 additions and 22 deletions

View file

@ -43,7 +43,7 @@ public class ArmorData {
public Map<StatType,Float> mStat = new HashMap<StatType,Float>();
public Map<StatType,Boolean> mBStat = new HashMap<StatType,Boolean>();
static ArrayList<StatType> updateArmorStatTypeList;
// public boolean fullArmor;
// public boolean fullRadiationDef;
// public boolean fullElectricDef;
@ -94,6 +94,14 @@ public class ArmorData {
// public int antiGravMaxWeight;
public ArmorData(EntityPlayer player, ItemStack stack, int type, int tier) {
if(updateArmorStatTypeList == null)
{
updateArmorStatTypeList = new ArrayList<StatType>();
updateArmorStatTypeList.add(StatType.MAGNET);
updateArmorStatTypeList.add(StatType.THORNS);
updateArmorStatTypeList.add(StatType.PROCESSINGPOWER);
updateArmorStatTypeList.add(StatType.PROCESSINGPOWERUSED);
}
this.type = type;
this.armorTier = tier;
ContainerModularArmor tmp = new ContainerBasicArmor((EntityPlayer) player, new InventoryArmor(ModularArmor_Item.class, stack));
@ -259,29 +267,30 @@ public class ArmorData {
set(mBStat, StatType.THORNS, 0);
set(mBStat, StatType.PROCESSINGPOWER, 0);
set(mBStat, StatType.PROCESSINGPOWERUSED, 0);
if (helmet != null) {
change(mStat, StatType.MAGNET, helmet.mStat.get(StatType.MAGNET));
change(mStat, StatType.THORNS, helmet.mStat.get(StatType.THORNS));
change(mStat, StatType.PROCESSINGPOWER, helmet.mStat.get(StatType.PROCESSINGPOWER));
change(mStat, StatType.PROCESSINGPOWERUSED, helmet.mStat.get(StatType.PROCESSINGPOWERUSED));
if (helmet != null) {
updateArmorStats(helmet,updateArmorStatTypeList );
}
if (chestplate != null) {
change(mStat, StatType.MAGNET, chestplate.mStat.get(StatType.MAGNET));
change(mStat, StatType.THORNS, chestplate.mStat.get(StatType.THORNS));
change(mStat, StatType.PROCESSINGPOWER, chestplate.mStat.get(StatType.PROCESSINGPOWER));
change(mStat, StatType.PROCESSINGPOWERUSED, chestplate.mStat.get(StatType.PROCESSINGPOWERUSED));
updateArmorStats(chestplate,updateArmorStatTypeList );
// change(mStat, StatType.MAGNET, chestplate.mStat.get(StatType.MAGNET));
// change(mStat, StatType.THORNS, chestplate.mStat.get(StatType.THORNS));
// change(mStat, StatType.PROCESSINGPOWER, chestplate.mStat.get(StatType.PROCESSINGPOWER));
// change(mStat, StatType.PROCESSINGPOWERUSED, chestplate.mStat.get(StatType.PROCESSINGPOWERUSED));
}
if (leggings != null) {
change(mStat, StatType.MAGNET, leggings.mStat.get(StatType.MAGNET));
change(mStat, StatType.THORNS, leggings.mStat.get(StatType.THORNS));
change(mStat, StatType.PROCESSINGPOWER, leggings.mStat.get(StatType.PROCESSINGPOWER));
change(mStat, StatType.PROCESSINGPOWERUSED, leggings.mStat.get(StatType.PROCESSINGPOWERUSED));
updateArmorStats(leggings,updateArmorStatTypeList );
// change(mStat, StatType.MAGNET, leggings.mStat.get(StatType.MAGNET));
// change(mStat, StatType.THORNS, leggings.mStat.get(StatType.THORNS));
// change(mStat, StatType.PROCESSINGPOWER, leggings.mStat.get(StatType.PROCESSINGPOWER));
// change(mStat, StatType.PROCESSINGPOWERUSED, leggings.mStat.get(StatType.PROCESSINGPOWERUSED));
}
if (boots != null) {
change(mStat, StatType.MAGNET, boots.mStat.get(StatType.MAGNET));
change(mStat, StatType.THORNS, boots.mStat.get(StatType.THORNS));
change(mStat, StatType.PROCESSINGPOWER, boots.mStat.get(StatType.PROCESSINGPOWER));
change(mStat, StatType.PROCESSINGPOWERUSED, boots.mStat.get(StatType.PROCESSINGPOWERUSED));
updateArmorStats(boots,updateArmorStatTypeList );
// change(mStat, StatType.MAGNET, boots.mStat.get(StatType.MAGNET));
// change(mStat, StatType.THORNS, boots.mStat.get(StatType.THORNS));
// change(mStat, StatType.PROCESSINGPOWER, boots.mStat.get(StatType.PROCESSINGPOWER));
// change(mStat, StatType.PROCESSINGPOWERUSED, boots.mStat.get(StatType.PROCESSINGPOWERUSED));
}
isTopItem = false;
if (type == 0) {
@ -306,6 +315,23 @@ public class ArmorData {
maxWeight += boots.mStat.get(StatType.WEIGHT);
}
}
private void updateArmorStats(ArmorData armorData, ArrayList<StatType> statTypes) {
for (StatType statType : statTypes) {
if(armorData == null || armorData.mStat == null || !armorData.mStat.containsKey(statType))
continue;
// if(armorData != null && armorData.mStat != null && armorData.mStat.containsKey(statType))
// {
change(mStat, statType, armorData.mStat.get(statType));
// }
/*change(mStat, StatType.MAGNET, armorData.mStat.get(StatType.MAGNET));
change(mStat, StatType.THORNS, armorData.mStat.get(StatType.THORNS));
change(mStat, StatType.PROCESSINGPOWER, armorData.mStat.get(StatType.PROCESSINGPOWER));
change(mStat, StatType.PROCESSINGPOWERUSED, armorData.mStat.get(StatType.PROCESSINGPOWERUSED));*/
}
}
public void set(Map aMap, StatType aType, boolean aSet){
if(aMap.containsKey(aType))aMap.remove(aType);

View file

@ -151,10 +151,15 @@ public class GuiElectricArmor1 extends GuiContainer {
if(tab>2){tab=0;}
if(tab<0){tab=2;}
if(xStart>72&&xStart<112){
if(xStart>72&&xStart<81&&cont.mInvArmor.data.helmet!=null){cont.mInvArmor.data.helmet.openGui=true;player.closeScreen();}
if(xStart>82&&xStart<91&&cont.mInvArmor.data.chestplate!=null){cont.mInvArmor.data.chestplate.openGui=true;player.closeScreen();}
if(xStart>92&&xStart<101&&cont.mInvArmor.data.leggings!=null){cont.mInvArmor.data.leggings.openGui=true;player.closeScreen();}
if(xStart>102&&xStart<112&&cont.mInvArmor.data.boots!=null){cont.mInvArmor.data.boots.openGui=true;player.closeScreen();}
if(xStart>72&&xStart<81&&cont.mInvArmor.data.helmet!=null){cont.mInvArmor.data.helmet.openGui=true;}
if(xStart>82&&xStart<91&&cont.mInvArmor.data.chestplate!=null){cont.mInvArmor.data.chestplate.openGui=true;}
if(xStart>92&&xStart<101&&cont.mInvArmor.data.leggings!=null){cont.mInvArmor.data.leggings.openGui=true;}
if(xStart>102&&xStart<112&&cont.mInvArmor.data.boots!=null){cont.mInvArmor.data.boots.openGui=true;}
// if(xStart>72&&xStart<81&&cont.mInvArmor.data.helmet!=null){cont.mInvArmor.data.helmet.openGui=true;player.closeScreen();}
// if(xStart>82&&xStart<91&&cont.mInvArmor.data.chestplate!=null){cont.mInvArmor.data.chestplate.openGui=true;player.closeScreen();}
// if(xStart>92&&xStart<101&&cont.mInvArmor.data.leggings!=null){cont.mInvArmor.data.leggings.openGui=true;player.closeScreen();}
// if(xStart>102&&xStart<112&&cont.mInvArmor.data.boots!=null){cont.mInvArmor.data.boots.openGui=true;player.closeScreen();}
}
}
// Slot slot = getSlotAtPosition(mouseX, mouseY);