diff options
author | â€huajijam <strhuaji@gmail.com> | 2019-04-30 22:52:55 +0800 |
---|---|---|
committer | â€huajijam <strhuaji@gmail.com> | 2019-04-30 22:52:55 +0800 |
commit | e18a5f0e793ac8cf256d17b44910ecc0b7fdb094 (patch) | |
tree | 2cb080a99d07318a7f86c4afe2bfbb551de2766c /src/Java/gtPlusPlus/core/util | |
parent | 913bb1c0a34045b1aa11901f49107322b1c03b57 (diff) | |
parent | 47d2b68b66fb9958b57c3ff81f1e73e8f6afd91b (diff) | |
download | GT5-Unofficial-e18a5f0e793ac8cf256d17b44910ecc0b7fdb094.tar.gz GT5-Unofficial-e18a5f0e793ac8cf256d17b44910ecc0b7fdb094.tar.bz2 GT5-Unofficial-e18a5f0e793ac8cf256d17b44910ecc0b7fdb094.zip |
Automatic synchronization
Diffstat (limited to 'src/Java/gtPlusPlus/core/util')
-rw-r--r-- | src/Java/gtPlusPlus/core/util/Utils.java | 25 | ||||
-rw-r--r-- | src/Java/gtPlusPlus/core/util/minecraft/EnergyUtils.java | 15 | ||||
-rw-r--r-- | src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java | 12 |
3 files changed, 31 insertions, 21 deletions
diff --git a/src/Java/gtPlusPlus/core/util/Utils.java b/src/Java/gtPlusPlus/core/util/Utils.java index 3b3ba88e88..bb1d9064e8 100644 --- a/src/Java/gtPlusPlus/core/util/Utils.java +++ b/src/Java/gtPlusPlus/core/util/Utils.java @@ -928,24 +928,19 @@ public class Utils { return false; } - public static ItemList getValueOfItemList(String string, ItemList aOther) { - try { - Method method = ItemList.class.getDeclaredMethod("values"); - Object obj = method.invoke(null); - String y = Arrays.toString((Object[]) obj); - String[] aCurrentItemsInList = y.split(","); - boolean found = false; - for (String g : aCurrentItemsInList) { - if (g.equals(string)) { - found = true; - break; + public static ItemList getValueOfItemList(String string, ItemList aOther) { + ItemList[] aListValues = ItemList.class.getEnumConstants(); + for (ItemList aItem : aListValues) { + if (aItem != null) { + if (aItem.name().equals(string) || aItem.name().toLowerCase().equals(string.toLowerCase())) { + return aItem; } } - if (found) { - return ItemList.valueOf(string); - } } - catch (Throwable t) {} + Logger.INFO("Tried to obtain '"+string+"' from the GT ItemList, however it does not exist."); + if (aOther != null) { + Logger.INFO("Using fallback option instead - "+aOther.name()); + } return aOther; } diff --git a/src/Java/gtPlusPlus/core/util/minecraft/EnergyUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/EnergyUtils.java index 51bedaf64b..ef68436f21 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/EnergyUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/EnergyUtils.java @@ -1,6 +1,9 @@ package gtPlusPlus.core.util.minecraft; +import gregtech.api.enums.GT_Values; import gregtech.api.util.GT_ModHandler; +import gtPlusPlus.api.objects.Logger; +import ic2.api.item.ElectricItem; import ic2.api.item.IElectricItem; import ic2.api.item.IElectricItemManager; import ic2.api.item.ISpecialElectricItem; @@ -33,8 +36,16 @@ public class EnergyUtils { return 0 != GT_ModHandler.chargeElectricItem(aStack, aEnergyToInsert, aTier, true, false); } - public static boolean discharge(ItemStack aStack, int aEnergyToInsert, int aTier) { - return 0 != GT_ModHandler.dischargeElectricItem(aStack, -aEnergyToInsert, aTier, true, false, true); + public static boolean discharge(ItemStack aStack, int aEnergyToDrain, int aTier) { + if (isElectricItem(aStack)) { + int tTier = ((IElectricItem) aStack.getItem()).getTier(aStack); + int aDischargeValue = GT_ModHandler.dischargeElectricItem(aStack, aEnergyToDrain, tTier, true, false, false); + Logger.INFO("Trying to drain "+aDischargeValue); + return aDischargeValue > 0; + } + else { + return false; + } } public static long getMaxStorage(ItemStack aStack) { diff --git a/src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java index 8f12d20494..aaa81a0057 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java @@ -17,10 +17,14 @@ public class InventoryUtils { public static void dropInventoryItems(World world, int x, int y, int z, Block block) { TileEntity tileentity = world.getTileEntity(x, y, z); - if (tileentity != null && tileentity instanceof IInventory - && ((IInventory) tileentity).getSizeInventory() > 0) { - for (int i1 = 0; i1 < ((IInventory) tileentity).getSizeInventory(); ++i1) { - ItemStack itemstack = ((IInventory) tileentity).getStackInSlot(i1); + if (tileentity != null && tileentity instanceof IInventory && ((IInventory) tileentity).getSizeInventory() > 0) { + + IInventory aTileInv = (IInventory) tileentity; + int aMinSlot = 0; + int aMaxSlot = aTileInv.getSizeInventory()-1; + + for (int i1 = aMinSlot; i1 < aMaxSlot; ++i1) { + ItemStack itemstack = aTileInv.getStackInSlot(i1); if (itemstack != null) { float f = mRandom.nextFloat() * 0.8F + 0.1F; |