diff options
author | Alkalus <Draknyte1@hotmail.com> | 2020-05-30 21:31:52 +0100 |
---|---|---|
committer | Alkalus <Draknyte1@hotmail.com> | 2020-05-30 21:31:52 +0100 |
commit | 4ded21b4e901630a72fe2ccf7fd8dff56e744bb7 (patch) | |
tree | 99a8351468e1bf62fa8ee32f159b5c446c1c670a /src | |
parent | 664c388b944e87125a9305fbbdda6a374854e0b5 (diff) | |
download | GT5-Unofficial-4ded21b4e901630a72fe2ccf7fd8dff56e744bb7.tar.gz GT5-Unofficial-4ded21b4e901630a72fe2ccf7fd8dff56e744bb7.tar.bz2 GT5-Unofficial-4ded21b4e901630a72fe2ccf7fd8dff56e744bb7.zip |
$ Fixed minor oversight in RC ASM.
$ Fixed bug where PSS would generate power due to an integer overflow.
Diffstat (limited to 'src')
3 files changed, 130 insertions, 12 deletions
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/NBTUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/NBTUtils.java index b0623d429d..7ed4d887cc 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/NBTUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/NBTUtils.java @@ -2,6 +2,7 @@ package gtPlusPlus.core.util.minecraft; import static gtPlusPlus.core.item.ModItems.ZZZ_Empty; +import java.util.HashMap; import java.util.Map; import net.minecraft.entity.Entity; @@ -413,6 +414,107 @@ public class NBTUtils { return false; } + public static Map getTagMap(NBTTagCompound aNBT) { + Map tagMap = new HashMap(); + if (!aNBT.hasNoTags()) { + Map<?, ?> mInternalMap = ReflectionUtils.getField(aNBT, "tagMap"); + if (mInternalMap != null && !mInternalMap.isEmpty()) { + tagMap.putAll(mInternalMap); + } + } + return tagMap; + } + + public static boolean isTagString(NBTTagCompound aNBT, String aTagName) { + Map<?, ?> aTagMap = getTagMap(aNBT); + if (aTagMap != null && !aTagMap.isEmpty()) { + for (Map.Entry<?, ?> e : aTagMap.entrySet()) { + if (e.getKey().equals(aTagName)) { + Object aValue = e.getValue(); + if (aValue instanceof String) { + return true; + } + } + } + } + return false; + } + + public static boolean isTagInteger(NBTTagCompound aNBT, String aTagName) { + Map<?, ?> aTagMap = getTagMap(aNBT); + if (aTagMap != null && !aTagMap.isEmpty()) { + for (Map.Entry<?, ?> e : aTagMap.entrySet()) { + if (e.getKey().equals(aTagName)) { + Object aValue = e.getValue(); + if (int.class.isInstance(aValue) || aValue instanceof Integer) { + return true; + } + } + } + } + return false; + } + + public static boolean isTagLong(NBTTagCompound aNBT, String aTagName) { + Map<?, ?> aTagMap = getTagMap(aNBT); + if (aTagMap != null && !aTagMap.isEmpty()) { + for (Map.Entry<?, ?> e : aTagMap.entrySet()) { + if (e.getKey().equals(aTagName)) { + Object aValue = e.getValue(); + if (long.class.isInstance(aValue) || aValue instanceof Long) { + return true; + } + } + } + } + return false; + } + + public static boolean isTagFloat(NBTTagCompound aNBT, String aTagName) { + Map<?, ?> aTagMap = getTagMap(aNBT); + if (aTagMap != null && !aTagMap.isEmpty()) { + for (Map.Entry<?, ?> e : aTagMap.entrySet()) { + if (e.getKey().equals(aTagName)) { + Object aValue = e.getValue(); + if (float.class.isInstance(aValue) || aValue instanceof Float) { + return true; + } + } + } + } + return false; + } + + public static boolean isTagDouble(NBTTagCompound aNBT, String aTagName) { + Map<?, ?> aTagMap = getTagMap(aNBT); + if (aTagMap != null && !aTagMap.isEmpty()) { + for (Map.Entry<?, ?> e : aTagMap.entrySet()) { + if (e.getKey().equals(aTagName)) { + Object aValue = e.getValue(); + if (double.class.isInstance(aValue) || aValue instanceof Double) { + return true; + } + } + } + } + return false; + } + + public static boolean isTagBoolean(NBTTagCompound aNBT, String aTagName) { + Map<?, ?> aTagMap = getTagMap(aNBT); + if (aTagMap != null && !aTagMap.isEmpty()) { + for (Map.Entry<?, ?> e : aTagMap.entrySet()) { + if (e.getKey().equals(aTagName)) { + Object aValue = e.getValue(); + if (boolean.class.isInstance(aValue) || aValue instanceof Boolean) { + return true; + } + } + } + } + return false; + } + public static boolean tryCloneTagCompoundDataIntoSubTag(ItemStack aStack, NBTTagCompound aTagCompound) { try { NBTTagCompound aNBT = aTagCompound; diff --git a/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_Railcraft_InvTools.java b/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_Railcraft_InvTools.java index 30ee37d7b3..75896c1c0f 100644 --- a/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_Railcraft_InvTools.java +++ b/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_Railcraft_InvTools.java @@ -34,16 +34,19 @@ public class ClassTransformer_Railcraft_InvTools { if (stack == null) { return GT_Values.NI; } else { - if (stack.stackSize <= 1) { + if (stack.stackSize == 0) { + return GT_Values.NI; + } + else if (stack.stackSize == 1) { ItemStack container = stack.getItem().getContainerItem(stack); if (container != null) { return container; } else { return GT_Values.NI; } - } else { - ItemUtils.depleteStack(stack); - return stack; + } + else { + return ItemUtils.depleteStack(stack); } } } @@ -85,11 +88,11 @@ public class ClassTransformer_Railcraft_InvTools { } if (obfuscated && devEnv) { - + } else { - - + + } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java index 3eabcf517e..6619bc1253 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java @@ -19,6 +19,7 @@ import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.lib.LoadedMods; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.NBTUtils; import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.preloader.asm.AsmConfig; import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_PowerSubStation; @@ -36,7 +37,7 @@ import net.minecraftforge.common.util.ForgeDirection; public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMeta_MultiBlockBase { - protected int mAverageEuUsage = 0; + protected long mAverageEuUsage = 0; protected long mTotalEnergyAdded = 0; protected long mTotalEnergyConsumed = 0; protected long mTotalEnergyLost = 0; @@ -366,7 +367,7 @@ public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMe //mTotalEnergyAdded @Override public void saveNBTData(NBTTagCompound aNBT) { - aNBT.setInteger("mAverageEuUsage", this.mAverageEuUsage); + aNBT.setLong("mAverageEuUsage", this.mAverageEuUsage); //Usage Stats aNBT.setLong("mTotalEnergyAdded", this.mTotalEnergyAdded); @@ -380,7 +381,17 @@ public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMe @Override public void loadNBTData(NBTTagCompound aNBT) { - this.mAverageEuUsage = aNBT.getInteger("mAverageEuUsage"); + + // Best not to get a long if the Tag Map is holding an int + if (aNBT.hasKey("mAverageEuUsage")) { + if (NBTUtils.isTagInteger(aNBT, "mAverageEuUsage")) { + int aAverageTag = aNBT.getInteger("mAverageEuUsage"); + this.mAverageEuUsage = aAverageTag; + } + else { + this.mAverageEuUsage = aNBT.getLong("mAverageEuUsage"); + } + } //Usage Stats this.mTotalEnergyAdded = aNBT.getLong("mTotalEnergyAdded"); @@ -421,7 +432,9 @@ public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMe long stored = aHatch.getEUVar(); long voltage = aHatch.maxEUInput() * aHatch.maxAmperesIn(); - if (voltage > stored) return; + if (voltage > stored) { + return; + } if (this.getBaseMetaTileEntity().increaseStoredEnergyUnits(voltage, false)) { aHatch.setEUVar((stored - voltage)); @@ -449,7 +462,7 @@ public class GregtechMetaTileEntity_PowerSubStationController extends GregtechMe // Increase tax up to 2x if machine is not fully repaired mTax = mTax * (1f + (10000f - mEfficiency) / 10000f); - return MathUtils.roundToClosestInt(mTax); + return MathUtils.roundToClosestLong(mTax); } |