diff options
| author | Jason Mitchell <mitchej@gmail.com> | 2023-01-30 10:56:42 -0800 |
|---|---|---|
| committer | Jason Mitchell <mitchej@gmail.com> | 2023-01-30 10:56:42 -0800 |
| commit | 0d9aab72aa570f13dc3e32e0d32b3f3a95f95e0a (patch) | |
| tree | 1e2c649f3a6ce3f6b2babd0098a5f4819e9cd0b6 /src/main/java/gregtech/api/util/GT_Utility.java | |
| parent | f8cc82edeb9810c45cba762d733a2c909a302faa (diff) | |
| download | GT5-Unofficial-0d9aab72aa570f13dc3e32e0d32b3f3a95f95e0a.tar.gz GT5-Unofficial-0d9aab72aa570f13dc3e32e0d32b3f3a95f95e0a.tar.bz2 GT5-Unofficial-0d9aab72aa570f13dc3e32e0d32b3f3a95f95e0a.zip | |
[ci skip] spotlessApply with the new settings
Diffstat (limited to 'src/main/java/gregtech/api/util/GT_Utility.java')
| -rw-r--r-- | src/main/java/gregtech/api/util/GT_Utility.java | 1781 |
1 files changed, 888 insertions, 893 deletions
diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index f1cdde1d48..2134d94253 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -12,50 +12,6 @@ import static gregtech.api.enums.GT_Values.W; import static gregtech.api.enums.Materials.FLUID_MAP; import static gregtech.common.GT_UndergroundOil.undergroundOilReadInformation; -import cofh.api.transport.IItemDuct; -import com.google.auto.value.AutoValue; -import com.google.common.base.Suppliers; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import com.gtnewhorizon.structurelib.alignment.IAlignment; -import com.gtnewhorizon.structurelib.alignment.IAlignmentProvider; -import com.mojang.authlib.GameProfile; -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.registry.GameRegistry; -import gregtech.api.GregTech_API; -import gregtech.api.damagesources.GT_DamageSources; -import gregtech.api.damagesources.GT_DamageSources.DamageSourceHotItem; -import gregtech.api.enchants.Enchantment_Hazmat; -import gregtech.api.enchants.Enchantment_Radioactivity; -import gregtech.api.enums.*; -import gregtech.api.events.BlockScanningEvent; -import gregtech.api.interfaces.IBlockContainer; -import gregtech.api.interfaces.IDebugableBlock; -import gregtech.api.interfaces.IHasIndexedTexture; -import gregtech.api.interfaces.IProjectileItem; -import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.tileentity.IBasicEnergyContainer; -import gregtech.api.interfaces.tileentity.ICoverable; -import gregtech.api.interfaces.tileentity.IGregTechDeviceInformation; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.interfaces.tileentity.IMachineProgress; -import gregtech.api.interfaces.tileentity.IUpgradableMachine; -import gregtech.api.items.GT_EnergyArmor_Item; -import gregtech.api.items.GT_Generic_Item; -import gregtech.api.items.GT_MetaGenerated_Tool; -import gregtech.api.net.GT_Packet_Sound; -import gregtech.api.objects.CollectorUtils; -import gregtech.api.objects.GT_ItemStack; -import gregtech.api.objects.GT_ItemStack2; -import gregtech.api.objects.ItemData; -import gregtech.api.threads.GT_Runnable_Sound; -import gregtech.api.util.extensions.ArrayExt; -import gregtech.common.GT_Pollution; -import gregtech.common.blocks.GT_Block_Ores_Abstract; -import ic2.api.recipe.IRecipeInput; -import ic2.api.recipe.RecipeInputItemStack; -import ic2.api.recipe.RecipeInputOreDict; -import ic2.api.recipe.RecipeOutput; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -68,7 +24,9 @@ import java.util.Map.Entry; import java.util.function.Function; import java.util.function.IntFunction; import java.util.function.Supplier; + import javax.annotation.Nullable; + import net.minecraft.block.Block; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; @@ -120,23 +78,73 @@ import net.minecraftforge.fluids.IFluidContainerItem; import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.oredict.OreDictionary; +import cofh.api.transport.IItemDuct; + +import com.google.auto.value.AutoValue; +import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; +import com.gtnewhorizon.structurelib.alignment.IAlignment; +import com.gtnewhorizon.structurelib.alignment.IAlignmentProvider; +import com.mojang.authlib.GameProfile; + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.GregTech_API; +import gregtech.api.damagesources.GT_DamageSources; +import gregtech.api.damagesources.GT_DamageSources.DamageSourceHotItem; +import gregtech.api.enchants.Enchantment_Hazmat; +import gregtech.api.enchants.Enchantment_Radioactivity; +import gregtech.api.enums.*; +import gregtech.api.events.BlockScanningEvent; +import gregtech.api.interfaces.IBlockContainer; +import gregtech.api.interfaces.IDebugableBlock; +import gregtech.api.interfaces.IHasIndexedTexture; +import gregtech.api.interfaces.IProjectileItem; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IBasicEnergyContainer; +import gregtech.api.interfaces.tileentity.ICoverable; +import gregtech.api.interfaces.tileentity.IGregTechDeviceInformation; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.interfaces.tileentity.IMachineProgress; +import gregtech.api.interfaces.tileentity.IUpgradableMachine; +import gregtech.api.items.GT_EnergyArmor_Item; +import gregtech.api.items.GT_Generic_Item; +import gregtech.api.items.GT_MetaGenerated_Tool; +import gregtech.api.net.GT_Packet_Sound; +import gregtech.api.objects.CollectorUtils; +import gregtech.api.objects.GT_ItemStack; +import gregtech.api.objects.GT_ItemStack2; +import gregtech.api.objects.ItemData; +import gregtech.api.threads.GT_Runnable_Sound; +import gregtech.api.util.extensions.ArrayExt; +import gregtech.common.GT_Pollution; +import gregtech.common.blocks.GT_Block_Ores_Abstract; +import ic2.api.recipe.IRecipeInput; +import ic2.api.recipe.RecipeInputItemStack; +import ic2.api.recipe.RecipeInputOreDict; +import ic2.api.recipe.RecipeOutput; + /** * NEVER INCLUDE THIS FILE IN YOUR MOD!!! * <p/> * Just a few Utility Functions I use. */ public class GT_Utility { + /** Formats a number with group separator and at most 2 fraction digits. */ private static final Map<Locale, DecimalFormat> decimalFormatters = new HashMap<>(); /** - * Forge screwed the Fluid Registry up again, so I make my own, which is also much more efficient than the stupid Stuff over there. + * Forge screwed the Fluid Registry up again, so I make my own, which is also much more efficient than the stupid + * Stuff over there. */ private static final List<FluidContainerData> sFluidContainerList = new ArrayList<>(); - private static final Map<GT_ItemStack, FluidContainerData> sFilledContainerToData = new /*Concurrent*/ HashMap<>(); - private static final Map<GT_ItemStack, Map<Fluid, FluidContainerData>> sEmptyContainerToFluidToData = - new /*Concurrent*/ HashMap<>(); + private static final Map<GT_ItemStack, FluidContainerData> sFilledContainerToData = new /* Concurrent */ HashMap<>(); + private static final Map<GT_ItemStack, Map<Fluid, FluidContainerData>> sEmptyContainerToFluidToData = new /* + * Concurrent + */ HashMap<>(); private static final Map<Fluid, List<ItemStack>> sFluidToContainers = new HashMap<>(); private static final Map<String, Fluid> sFluidUnlocalizedNameToFluid = new HashMap<>(); /** Must use {@code Supplier} here because the ore prefixes have not yet been registered at class load time. */ @@ -145,10 +153,10 @@ public class GT_Utility { private static final Map<Integer, Boolean> sOreTable = new HashMap<>(); public static volatile int VERSION = 509; public static boolean TE_CHECK = false, BC_CHECK = false, CHECK_ALL = true, RF_CHECK = false; - public static Map<GT_PlayedSound, Integer> sPlayedSoundMap = new /*Concurrent*/ HashMap<>(); + public static Map<GT_PlayedSound, Integer> sPlayedSoundMap = new /* Concurrent */ HashMap<>(); private static int sBookCount = 0; - public static UUID defaultUuid = - null; // maybe default non-null? UUID.fromString("00000000-0000-0000-0000-000000000000"); + public static UUID defaultUuid = null; // maybe default non-null? + // UUID.fromString("00000000-0000-0000-0000-000000000000"); static { GregTech_API.sItemStackMappings.add(sFilledContainerToData); @@ -156,8 +164,8 @@ public class GT_Utility { // 1 is the magic index to get the cobblestone block. // See: GT_Block_Stones.java, GT_Block_Granites.java - Function<Materials, Supplier<ItemStack>> materialToCobble = m -> Suppliers.memoize( - () -> GT_OreDictUnificator.getOres(OrePrefixes.stone, m).get(1))::get; + Function<Materials, Supplier<ItemStack>> materialToCobble = m -> Suppliers + .memoize(() -> GT_OreDictUnificator.getOres(OrePrefixes.stone, m).get(1))::get; sOreToCobble.put(OrePrefixes.oreBlackgranite, materialToCobble.apply(Materials.GraniteBlack)); sOreToCobble.put(OrePrefixes.oreRedgranite, materialToCobble.apply(Materials.GraniteRed)); sOreToCobble.put(OrePrefixes.oreMarble, materialToCobble.apply(Materials.Marble)); @@ -171,8 +179,7 @@ public class GT_Utility { } public static int safeInt(long number) { - return number > V[V.length - 1] - ? safeInt(V[V.length - 1], 1) + return number > V[V.length - 1] ? safeInt(V[V.length - 1], 1) : number < Integer.MIN_VALUE ? Integer.MIN_VALUE : (int) number; } @@ -181,7 +188,7 @@ public class GT_Utility { try { rField = aObject.getClass().getDeclaredField(aField); } catch (Throwable e) { - /*Do nothing*/ + /* Do nothing */ } return rField; } @@ -192,7 +199,7 @@ public class GT_Utility { rField = aObject.getClass().getDeclaredField(aField); rField.setAccessible(true); } catch (Throwable e) { - /*Do nothing*/ + /* Do nothing */ } return rField; } @@ -203,7 +210,7 @@ public class GT_Utility { rField = aObject.getDeclaredField(aField); rField.setAccessible(true); } catch (Throwable e) { - /*Do nothing*/ + /* Do nothing */ } return rField; } @@ -214,7 +221,7 @@ public class GT_Utility { rMethod = aObject.getMethod(aMethod, aParameterTypes); rMethod.setAccessible(true); } catch (Throwable e) { - /*Do nothing*/ + /* Do nothing */ } return rMethod; } @@ -225,17 +232,15 @@ public class GT_Utility { rMethod = aObject.getClass().getMethod(aMethod, aParameterTypes); rMethod.setAccessible(true); } catch (Throwable e) { - /*Do nothing*/ + /* Do nothing */ } return rMethod; } public static Field getField(Object aObject, String aField, boolean aPrivate, boolean aLogErrors) { try { - Field tField = (aObject instanceof Class) - ? ((Class) aObject).getDeclaredField(aField) - : (aObject instanceof String) - ? Class.forName((String) aObject).getDeclaredField(aField) + Field tField = (aObject instanceof Class) ? ((Class) aObject).getDeclaredField(aField) + : (aObject instanceof String) ? Class.forName((String) aObject).getDeclaredField(aField) : aObject.getClass().getDeclaredField(aField); if (aPrivate) tField.setAccessible(true); return tField; @@ -247,10 +252,8 @@ public class GT_Utility { public static Object getFieldContent(Object aObject, String aField, boolean aPrivate, boolean aLogErrors) { try { - Field tField = (aObject instanceof Class) - ? ((Class) aObject).getDeclaredField(aField) - : (aObject instanceof String) - ? Class.forName((String) aObject).getDeclaredField(aField) + Field tField = (aObject instanceof Class) ? ((Class) aObject).getDeclaredField(aField) + : (aObject instanceof String) ? Class.forName((String) aObject).getDeclaredField(aField) : aObject.getClass().getDeclaredField(aField); if (aPrivate) tField.setAccessible(true); return tField.get(aObject instanceof Class || aObject instanceof String ? null : aObject); @@ -268,13 +271,8 @@ public class GT_Utility { return callMethod(aObject, aMethod, true, false, true, aParameters); } - public static Object callMethod( - Object aObject, - String aMethod, - boolean aPrivate, - boolean aUseUpperCasedDataTypes, - boolean aLogErrors, - Object... aParameters) { + public static Object callMethod(Object aObject, String aMethod, boolean aPrivate, boolean aUseUpperCasedDataTypes, + boolean aLogErrors, Object... aParameters) { try { Class<?>[] tParameterTypes = new Class<?>[aParameters.length]; for (byte i = 0; i < aParameters.length; i++) { @@ -295,8 +293,7 @@ public class GT_Utility { } } - Method tMethod = (aObject instanceof Class) - ? ((Class) aObject).getMethod(aMethod, tParameterTypes) + Method tMethod = (aObject instanceof Class) ? ((Class) aObject).getMethod(aMethod, tParameterTypes) : aObject.getClass().getMethod(aMethod, tParameterTypes); if (aPrivate) tMethod.setAccessible(true); return tMethod.invoke(aObject, aParameters); @@ -306,34 +303,29 @@ public class GT_Utility { return null; } - public static Object callConstructor( - String aClass, - int aConstructorIndex, - Object aReplacementObject, - boolean aLogErrors, - Object... aParameters) { + public static Object callConstructor(String aClass, int aConstructorIndex, Object aReplacementObject, + boolean aLogErrors, Object... aParameters) { try { return callConstructor( - Class.forName(aClass), aConstructorIndex, aReplacementObject, aLogErrors, aParameters); + Class.forName(aClass), + aConstructorIndex, + aReplacementObject, + aLogErrors, + aParameters); } catch (Throwable e) { if (aLogErrors) e.printStackTrace(GT_Log.err); } return aReplacementObject; } - public static Object callConstructor( - Class<?> aClass, - int aConstructorIndex, - Object aReplacementObject, - boolean aLogErrors, - Object... aParameters) { + public static Object callConstructor(Class<?> aClass, int aConstructorIndex, Object aReplacementObject, + boolean aLogErrors, Object... aParameters) { if (aConstructorIndex < 0) { try { for (Constructor<?> tConstructor : aClass.getConstructors()) { try { return tConstructor.newInstance(aParameters); - } catch (Throwable ignored) { - } + } catch (Throwable ignored) {} } } catch (Throwable e) { if (aLogErrors) e.printStackTrace(GT_Log.err); @@ -377,9 +369,7 @@ public class GT_Utility { public static String getClassName(Object aObject) { if (aObject == null) return "null"; - return aObject.getClass() - .getName() - .substring(aObject.getClass().getName().lastIndexOf(".") + 1); + return aObject.getClass().getName().substring(aObject.getClass().getName().lastIndexOf(".") + 1); } public static void removePotion(EntityLivingBase aPlayer, int aPotionIndex) { @@ -424,10 +414,11 @@ public class GT_Utility { return false; } - public static ItemStack suckOneItemStackAt( - World aWorld, double aX, double aY, double aZ, double aL, double aH, double aW) { + public static ItemStack suckOneItemStackAt(World aWorld, double aX, double aY, double aZ, double aL, double aH, + double aW) { for (EntityItem tItem : (ArrayList<EntityItem>) aWorld.getEntitiesWithinAABB( - EntityItem.class, AxisAlignedBB.getBoundingBox(aX, aY, aZ, aX + aL, aY + aH, aZ + aW))) { + EntityItem.class, + AxisAlignedBB.getBoundingBox(aX, aY, aZ, aX + aL, aY + aH, aZ + aW))) { if (!tItem.isDead) { aWorld.removeEntity(tItem); tItem.setDead(); @@ -497,23 +488,15 @@ public class GT_Utility { .isPipeConnected(ForgeDirection.getOrientation(aSide)); return GregTech_API.mTranslocator && aTileEntity instanceof codechicken.translocator.TileItemTranslocator; } + /** * Moves Stack from Inv-Slot to Inv-Slot, without checking if its even allowed. * * @return the Amount of moved Items */ - public static byte moveStackIntoPipe( - IInventory aTileEntity1, - Object aTileEntity2, - int[] aGrabSlots, - int aGrabFrom, - int aPutTo, - List<ItemStack> aFilter, - boolean aInvertFilter, - byte aMaxTargetStackSize, - byte aMinTargetStackSize, - byte aMaxMoveAtOnce, - byte aMinMoveAtOnce) { + public static byte moveStackIntoPipe(IInventory aTileEntity1, Object aTileEntity2, int[] aGrabSlots, int aGrabFrom, + int aPutTo, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, + byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) { return moveStackIntoPipe( aTileEntity1, aTileEntity2, @@ -534,32 +517,25 @@ public class GT_Utility { * * @return the Amount of moved Items */ - public static byte moveStackIntoPipe( - IInventory aTileEntity1, - Object aTileEntity2, - int[] aGrabSlots, - int aGrabFrom, - int aPutTo, - List<ItemStack> aFilter, - boolean aInvertFilter, - byte aMaxTargetStackSize, - byte aMinTargetStackSize, - byte aMaxMoveAtOnce, - byte aMinMoveAtOnce, - boolean dropItem) { - if (aTileEntity1 == null - || aMaxTargetStackSize <= 0 + public static byte moveStackIntoPipe(IInventory aTileEntity1, Object aTileEntity2, int[] aGrabSlots, int aGrabFrom, + int aPutTo, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, + byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce, boolean dropItem) { + if (aTileEntity1 == null || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMaxMoveAtOnce <= 0 - || aMinMoveAtOnce > aMaxMoveAtOnce) return 0; + || aMinMoveAtOnce > aMaxMoveAtOnce) + return 0; if (aTileEntity2 != null) { checkAvailabilities(); if (TE_CHECK && aTileEntity2 instanceof IItemDuct) { for (int aGrabSlot : aGrabSlots) { if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabSlot), true, aInvertFilter)) { if (isAllowedToTakeFromSlot( - aTileEntity1, aGrabSlot, (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlot))) { + aTileEntity1, + aGrabSlot, + (byte) aGrabFrom, + aTileEntity1.getStackInSlot(aGrabSlot))) { if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlot).stackSize) { ItemStack tStack = copyAmount( @@ -569,10 +545,11 @@ public class GT_Utility { aTileEntity1.getStackInSlot(aGrabSlot)); ItemStack rStack = ((IItemDuct) aTileEntity2) .insertItem(ForgeDirection.getOrientation(aPutTo), copyOrNull(tStack)); - byte tMovedItemCount = - (byte) (tStack.stackSize - (rStack == null ? 0 : rStack.stackSize)); - if (tMovedItemCount >= 1 /*Math.max(aMinMoveAtOnce, aMinTargetStackSize)*/) { - // ((cofh.api.transport.IItemConduit)aTileEntity2).insertItem(ForgeDirection.getOrientation(aPutTo), copyAmount(tMovedItemCount, tStack), F); + byte tMovedItemCount = (byte) (tStack.stackSize + - (rStack == null ? 0 : rStack.stackSize)); + if (tMovedItemCount >= 1 /* Math.max(aMinMoveAtOnce, aMinTargetStackSize) */) { + // ((cofh.api.transport.IItemConduit)aTileEntity2).insertItem(ForgeDirection.getOrientation(aPutTo), + // copyAmount(tMovedItemCount, tStack), F); aTileEntity1.decrStackSize(aGrabSlot, tMovedItemCount); aTileEntity1.markDirty(); return tMovedItemCount; @@ -587,7 +564,10 @@ public class GT_Utility { for (int aGrabSlot : aGrabSlots) { if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabSlot), true, aInvertFilter)) { if (isAllowedToTakeFromSlot( - aTileEntity1, aGrabSlot, (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlot))) { + aTileEntity1, + aGrabSlot, + (byte) aGrabFrom, + aTileEntity1.getStackInSlot(aGrabSlot))) { if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlot).stackSize) { ItemStack tStack = copyAmount( @@ -616,8 +596,7 @@ public class GT_Utility { } ForgeDirection tDirection = ForgeDirection.getOrientation(aGrabFrom); - if (aTileEntity1 instanceof TileEntity - && tDirection != ForgeDirection.UNKNOWN + if (aTileEntity1 instanceof TileEntity && tDirection != ForgeDirection.UNKNOWN && tDirection.getOpposite() == ForgeDirection.getOrientation(aPutTo)) { int tX = ((TileEntity) aTileEntity1).xCoord + tDirection.offsetX, tY = ((TileEntity) aTileEntity1).yCoord + tDirection.offsetY, @@ -626,7 +605,10 @@ public class GT_Utility { for (int aGrabSlot : aGrabSlots) { if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabSlot), true, aInvertFilter)) { if (isAllowedToTakeFromSlot( - aTileEntity1, aGrabSlot, (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlot))) { + aTileEntity1, + aGrabSlot, + (byte) aGrabFrom, + aTileEntity1.getStackInSlot(aGrabSlot))) { if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlot).stackSize) { ItemStack tStack = copyAmount( @@ -655,29 +637,22 @@ public class GT_Utility { } /** - * Moves Stack from Inv-Slot to Inv-Slot, without checking if its even allowed. (useful for internal Inventory Operations) + * Moves Stack from Inv-Slot to Inv-Slot, without checking if its even allowed. (useful for internal Inventory + * Operations) * * @return the Amount of moved Items */ - public static byte moveStackFromSlotAToSlotB( - IInventory aTileEntity1, - IInventory aTileEntity2, - int aGrabFrom, - int aPutTo, - byte aMaxTargetStackSize, - byte aMinTargetStackSize, - byte aMaxMoveAtOnce, - byte aMinMoveAtOnce) { - if (aTileEntity1 == null - || aTileEntity2 == null + public static byte moveStackFromSlotAToSlotB(IInventory aTileEntity1, IInventory aTileEntity2, int aGrabFrom, + int aPutTo, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) { + if (aTileEntity1 == null || aTileEntity2 == null || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMaxMoveAtOnce <= 0 - || aMinMoveAtOnce > aMaxMoveAtOnce) return 0; + || aMinMoveAtOnce > aMaxMoveAtOnce) + return 0; - ItemStack tStack1 = aTileEntity1.getStackInSlot(aGrabFrom), - tStack2 = aTileEntity2.getStackInSlot(aPutTo), + ItemStack tStack1 = aTileEntity1.getStackInSlot(aGrabFrom), tStack2 = aTileEntity2.getStackInSlot(aPutTo), tStack3 = null; if (tStack1 != null) { if (tStack2 != null && !areStacksEqual(tStack1, tStack2)) return 0; @@ -689,11 +664,11 @@ public class GT_Utility { Math.min( tStack2 == null ? Integer.MAX_VALUE : tStack2.getMaxStackSize(), aTileEntity2.getInventoryStackLimit()))); - tStack3.stackSize = - Math.min(tStack3.stackSize, aMaxTargetStackSize - (tStack2 == null ? 0 : tStack2.stackSize)); + tStack3.stackSize = Math + .min(tStack3.stackSize, aMaxTargetStackSize - (tStack2 == null ? 0 : tStack2.stackSize)); if (tStack3.stackSize > aMaxMoveAtOnce) tStack3.stackSize = aMaxMoveAtOnce; if (tStack3.stackSize + (tStack2 == null ? 0 : tStack2.stackSize) - >= Math.min(tStack3.getMaxStackSize(), aMinTargetStackSize) + >= Math.min(tStack3.getMaxStackSize(), aMinTargetStackSize) && tStack3.stackSize >= aMinMoveAtOnce) { tStack3 = aTileEntity1.decrStackSize(aGrabFrom, tStack3.stackSize); aTileEntity1.markDirty(); @@ -725,8 +700,8 @@ public class GT_Utility { return true; } - public static boolean isAllowedToPutIntoSlot( - IInventory aTileEntity, int aSlot, byte aSide, ItemStack aStack, byte aMaxStackSize) { + public static boolean isAllowedToPutIntoSlot(IInventory aTileEntity, int aSlot, byte aSide, ItemStack aStack, + byte aMaxStackSize) { ItemStack tStack = aTileEntity.getStackInSlot(aSlot); if (tStack != null && (!areStacksEqual(tStack, aStack) || tStack.stackSize >= tStack.getMaxStackSize())) return false; @@ -739,7 +714,8 @@ public class GT_Utility { || isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 5, aStack, aMaxStackSize); } if (aTileEntity instanceof ISidedInventory - && !((ISidedInventory) aTileEntity).canInsertItem(aSlot, aStack, aSide)) return false; + && !((ISidedInventory) aTileEntity).canInsertItem(aSlot, aStack, aSide)) + return false; return aSlot < aTileEntity.getSizeInventory() && aTileEntity.isItemValidForSlot(aSlot, aStack); } @@ -748,55 +724,35 @@ public class GT_Utility { * * @return the Amount of moved Items */ - public static int moveMultipleItemStacks( - Object aTileEntity1, - Object aTileEntity2, - byte aGrabFrom, - byte aPutTo, - List<ItemStack> aFilter, - boolean aInvertFilter, - byte aMaxTargetStackSize, - byte aMinTargetStackSize, - byte aMaxMoveAtOnce, - byte aMinMoveAtOnce, - int aStackAmount) { - if (aTileEntity1 instanceof IInventory) - return moveMultipleItemStacks( - (IInventory) aTileEntity1, - aTileEntity2, - aGrabFrom, - aPutTo, - aFilter, - aInvertFilter, - aMaxTargetStackSize, - aMinTargetStackSize, - aMaxMoveAtOnce, - aMinMoveAtOnce, - aStackAmount, - true); + public static int moveMultipleItemStacks(Object aTileEntity1, Object aTileEntity2, byte aGrabFrom, byte aPutTo, + List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, + byte aMaxMoveAtOnce, byte aMinMoveAtOnce, int aStackAmount) { + if (aTileEntity1 instanceof IInventory) return moveMultipleItemStacks( + (IInventory) aTileEntity1, + aTileEntity2, + aGrabFrom, + aPutTo, + aFilter, + aInvertFilter, + aMaxTargetStackSize, + aMinTargetStackSize, + aMaxMoveAtOnce, + aMinMoveAtOnce, + aStackAmount, + true); return 0; } - public static int moveMultipleItemStacks( - IInventory aTileEntity1, - Object aTileEntity2, - byte aGrabFrom, - byte aPutTo, - List<ItemStack> aFilter, - boolean aInvertFilter, - byte aMaxTargetStackSize, - byte aMinTargetStackSize, - byte aMaxMoveAtOnce, - byte aMinMoveAtOnce, - int aMaxStackTransfer, - boolean aDoCheckChests) { - if (aTileEntity1 == null - || aMaxTargetStackSize <= 0 + public static int moveMultipleItemStacks(IInventory aTileEntity1, Object aTileEntity2, byte aGrabFrom, byte aPutTo, + List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, + byte aMaxMoveAtOnce, byte aMinMoveAtOnce, int aMaxStackTransfer, boolean aDoCheckChests) { + if (aTileEntity1 == null || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMaxMoveAtOnce <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMinMoveAtOnce > aMaxMoveAtOnce - || aMaxStackTransfer == 0) return 0; + || aMaxStackTransfer == 0) + return 0; // find where to take from final int[] tGrabSlots = new int[aTileEntity1.getSizeInventory()]; @@ -804,10 +760,10 @@ public class GT_Utility { if (aTileEntity1 instanceof ISidedInventory) { for (int i : ((ISidedInventory) aTileEntity1).getAccessibleSlotsFromSide(aGrabFrom)) { final ItemStack s = aTileEntity1.getStackInSlot(i); - if (s == null - || !isAllowedToTakeFromSlot(aTileEntity1, i, aGrabFrom, s) + if (s == null || !isAllowedToTakeFromSlot(aTileEntity1, i, aGrabFrom, s) || s.stackSize < aMinMoveAtOnce - || !listContainsItem(aFilter, s, true, aInvertFilter)) continue; + || !listContainsItem(aFilter, s, true, aInvertFilter)) + continue; tGrabSlots[tGrabSlotsSize++] = i; } } else { @@ -822,19 +778,18 @@ public class GT_Utility { // no source, bail out if (tGrabSlotsSize == 0) { // maybe source is a double chest. check it - if (aDoCheckChests && aTileEntity1 instanceof TileEntityChest) - return moveFromAdjacentChests( - (TileEntityChest) aTileEntity1, - aTileEntity2, - aGrabFrom, - aPutTo, - aFilter, - aInvertFilter, - aMaxTargetStackSize, - aMinTargetStackSize, - aMaxMoveAtOnce, - aMinMoveAtOnce, - aMaxStackTransfer); + if (aDoCheckChests && aTileEntity1 instanceof TileEntityChest) return moveFromAdjacentChests( + (TileEntityChest) aTileEntity1, + aTileEntity2, + aGrabFrom, + aPutTo, + aFilter, + aInvertFilter, + aMaxTargetStackSize, + aMinTargetStackSize, + aMaxMoveAtOnce, + aMinMoveAtOnce, + aMaxStackTransfer); return 0; } @@ -865,31 +820,31 @@ public class GT_Utility { tPutFreeSlots.add(slot); } else if ((s.stackSize < s.getMaxStackSize() && s.stackSize < tPutInventory.getInventoryStackLimit()) && aMinMoveAtOnce <= s.getMaxStackSize() - s.stackSize) { - ItemId sID = ItemId.createNoCopy(s); - tPutItems.merge( - sID, - (Math.min(s.getMaxStackSize(), tPutInventory.getInventoryStackLimit()) - s.stackSize), - Integer::sum); - tPutItemStacks.computeIfAbsent(sID, k -> new ArrayList<>()).add(s); - } + ItemId sID = ItemId.createNoCopy(s); + tPutItems.merge( + sID, + (Math.min(s.getMaxStackSize(), tPutInventory.getInventoryStackLimit()) + - s.stackSize), + Integer::sum); + tPutItemStacks.computeIfAbsent(sID, k -> new ArrayList<>()).add(s); + } } // target completely filled, bail out if (tPutItems.isEmpty() && tPutFreeSlots.isEmpty()) { // maybe target is a double chest. check it. - if (aDoCheckChests && aTileEntity2 instanceof TileEntityChest) - return moveToAdjacentChests( - aTileEntity1, - (TileEntityChest) aTileEntity2, - aGrabFrom, - aPutTo, - aFilter, - aInvertFilter, - aMaxTargetStackSize, - aMinTargetStackSize, - aMaxMoveAtOnce, - aMinMoveAtOnce, - aMaxStackTransfer); + if (aDoCheckChests && aTileEntity2 instanceof TileEntityChest) return moveToAdjacentChests( + aTileEntity1, + (TileEntityChest) aTileEntity2, + aGrabFrom, + aPutTo, + aFilter, + aInvertFilter, + aMaxTargetStackSize, + aMinTargetStackSize, + aMaxMoveAtOnce, + aMinMoveAtOnce, + aMaxStackTransfer); return 0; } @@ -971,17 +926,15 @@ public class GT_Utility { if (s != null) { // s might be null if tPutInventory is very special, e.g. infinity chest // if s is null, we will not mark this slot as target candidate for anything - final int spare = - Math.min(s.getMaxStackSize(), tPutInventory.getInventoryStackLimit()) - - s.stackSize; + final int spare = Math + .min(s.getMaxStackSize(), tPutInventory.getInventoryStackLimit()) + - s.stackSize; if (spare > 0) { final ItemId ssID = ItemId.createNoCopy(s); // add back to spare space count tPutItems.merge(ssID, spare, Integer::sum); // add to partially filled slot list - tPutItemStacks - .computeIfAbsent(ssID, k -> new ArrayList<>()) - .add(s); + tPutItemStacks.computeIfAbsent(ssID, k -> new ArrayList<>()).add(s); } // this is no longer free tPutFreeSlots.remove(i); @@ -1002,8 +955,8 @@ public class GT_Utility { // check if we have moved enough stacks if (++tStacksMoved >= aMaxStackTransfer) return tTotalItemsMoved; } - } while (tMovedItems > 0 - && tStackSize > 0); // support inventories that store more than a stack in a slot + } while (tMovedItems > 0 && tStackSize > 0); // support inventories that store more than a stack in a + // slot } // check if source is a double chest, if yes, try move from the adjacent as well @@ -1066,18 +1019,9 @@ public class GT_Utility { return 0; } - private static int moveToAdjacentChests( - IInventory aTileEntity1, - TileEntityChest aTargetChest, - byte aGrabFrom, - byte aPutTo, - List<ItemStack> aFilter, - boolean aInvertFilter, - byte aMaxTargetStackSize, - byte aMinTargetStackSize, - byte aMaxMoveAtOnce, - byte aMinMoveAtOnce, - int aMaxStackTransfer) { + private static int moveToAdjacentChests(IInventory aTileEntity1, TileEntityChest aTargetChest, byte aGrabFrom, + byte aPutTo, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, + byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce, int aMaxStackTransfer) { if (aTargetChest.adjacentChestChecked) { if (aTargetChest.adjacentChestXNeg != null) { return moveMultipleItemStacks( @@ -1140,18 +1084,9 @@ public class GT_Utility { return 0; } |
