aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/api/util')
-rw-r--r--src/main/java/gregtech/api/util/GT_Utility.java4740
1 files changed, 2363 insertions, 2377 deletions
diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java
index 05b2ace461..fa7bd78c4d 100644
--- a/src/main/java/gregtech/api/util/GT_Utility.java
+++ b/src/main/java/gregtech/api/util/GT_Utility.java
@@ -1,2377 +1,2363 @@
-package gregtech.api.util;
-
-import cofh.api.transport.IItemDuct;
-import com.mojang.authlib.GameProfile;
-import cpw.mods.fml.common.FMLCommonHandler;
-import gregtech.api.GregTech_API;
-import gregtech.api.damagesources.GT_DamageSources;
-import gregtech.api.enchants.Enchantment_Radioactivity;
-import gregtech.api.enums.*;
-import gregtech.api.events.BlockScanningEvent;
-import gregtech.api.interfaces.IDebugableBlock;
-import gregtech.api.interfaces.IProjectileItem;
-import gregtech.api.interfaces.ITexture;
-import gregtech.api.interfaces.tileentity.*;
-import gregtech.api.items.GT_EnergyArmor_Item;
-import gregtech.api.items.GT_Generic_Item;
-import gregtech.api.net.GT_Packet_Sound;
-import gregtech.api.objects.GT_ItemStack;
-import gregtech.api.objects.ItemData;
-import gregtech.api.threads.GT_Runnable_Sound;
-import gregtech.common.GT_Proxy;
-import ic2.api.recipe.IRecipeInput;
-import ic2.api.recipe.RecipeInputItemStack;
-import ic2.api.recipe.RecipeInputOreDict;
-import ic2.api.recipe.RecipeOutput;
-import net.minecraft.block.Block;
-import net.minecraft.enchantment.Enchantment;
-import net.minecraft.enchantment.EnchantmentHelper;
-import net.minecraft.entity.*;
-import net.minecraft.entity.item.EntityItem;
-import net.minecraft.entity.player.EntityPlayer;
-import net.minecraft.entity.player.EntityPlayerMP;
-import net.minecraft.init.Blocks;
-import net.minecraft.init.Items;
-import net.minecraft.inventory.IInventory;
-import net.minecraft.inventory.ISidedInventory;
-import net.minecraft.item.Item;
-import net.minecraft.item.ItemStack;
-import net.minecraft.nbt.NBTBase;
-import net.minecraft.nbt.NBTBase.NBTPrimitive;
-import net.minecraft.nbt.NBTTagCompound;
-import net.minecraft.nbt.NBTTagList;
-import net.minecraft.nbt.NBTTagString;
-import net.minecraft.network.play.server.S07PacketRespawn;
-import net.minecraft.network.play.server.S1DPacketEntityEffect;
-import net.minecraft.network.play.server.S1FPacketSetExperience;
-import net.minecraft.potion.Potion;
-import net.minecraft.potion.PotionEffect;
-import net.minecraft.tileentity.TileEntity;
-import net.minecraft.tileentity.TileEntityChest;
-import net.minecraft.util.AxisAlignedBB;
-import net.minecraft.util.ChatComponentText;
-import net.minecraft.util.EnumChatFormatting;
-import net.minecraft.util.MathHelper;
-import net.minecraft.world.World;
-import net.minecraft.world.WorldServer;
-import net.minecraftforge.common.DimensionManager;
-import net.minecraftforge.common.MinecraftForge;
-import net.minecraftforge.common.util.BlockSnapshot;
-import net.minecraftforge.common.util.FakePlayer;
-import net.minecraftforge.common.util.FakePlayerFactory;
-import net.minecraftforge.common.util.ForgeDirection;
-import net.minecraftforge.event.ForgeEventFactory;
-import net.minecraftforge.event.world.BlockEvent;
-import net.minecraftforge.fluids.*;
-import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
-import java.text.NumberFormat;
-import java.util.*;
-import java.util.Map.Entry;
-
-import static gregtech.GT_Mod.GT_FML_LOGGER;
-import static gregtech.api.enums.GT_Values.*;
-import static gregtech.common.GT_Proxy.GTPOLLUTION;
-import static gregtech.common.GT_UndergroundOil.undergroundOilReadInformation;
-
-/**
- * NEVER INCLUDE THIS FILE IN YOUR MOD!!!
- * <p/>
- * Just a few Utility Functions I use.
- */
-public class GT_Utility {
- /**
- * 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<FluidContainerData>();
- private static final Map<GT_ItemStack, FluidContainerData> sFilledContainerToData = new /*Concurrent*/HashMap<GT_ItemStack, FluidContainerData>();
- private static final Map<GT_ItemStack, Map<Fluid, FluidContainerData>> sEmptyContainerToFluidToData = new /*Concurrent*/HashMap<GT_ItemStack, Map<Fluid, FluidContainerData>>();
- 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<GT_PlayedSound, Integer>();
- private static int sBookCount = 0;
-
- static {
- GregTech_API.sItemStackMappings.add(sFilledContainerToData);
- GregTech_API.sItemStackMappings.add(sEmptyContainerToFluidToData);
- }
-
- public static int safeInt(long number, int margin){
- return number>Integer.MAX_VALUE-margin ? Integer.MAX_VALUE-margin :(int)number;
- }
-
- public static int safeInt(long number){
- return number>GT_Values.V[GT_Values.V.length-1] ? safeInt(GT_Values.V[GT_Values.V.length-1],1) : number<Integer.MIN_VALUE ? Integer.MIN_VALUE : (int)number;
- }
-
- public static Field getPublicField(Object aObject, String aField) {
- Field rField = null;
- try {
- rField = aObject.getClass().getDeclaredField(aField);
- } catch (Throwable e) {/*Do nothing*/}
- return rField;
- }
-
- public static Field getField(Object aObject, String aField) {
- Field rField = null;
- try {
- rField = aObject.getClass().getDeclaredField(aField);
- rField.setAccessible(true);
- } catch (Throwable e) {/*Do nothing*/}
- return rField;
- }
-
- public static Field getField(Class aObject, String aField) {
- Field rField = null;
- try {
- rField = aObject.getDeclaredField(aField);
- rField.setAccessible(true);
- } catch (Throwable e) {/*Do nothing*/}
- return rField;
- }
-
- public static Method getMethod(Class aObject, String aMethod, Class<?>... aParameterTypes) {
- Method rMethod = null;
- try {
- rMethod = aObject.getMethod(aMethod, aParameterTypes);
- rMethod.setAccessible(true);
- } catch (Throwable e) {/*Do nothing*/}
- return rMethod;
- }
-
- public static Method getMethod(Object aObject, String aMethod, Class<?>... aParameterTypes) {
- Method rMethod = null;
- try {
- rMethod = aObject.getClass().getMethod(aMethod, aParameterTypes);
- rMethod.setAccessible(true);
- } catch (Throwable e) {/*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) : aObject.getClass().getDeclaredField(aField);
- if (aPrivate) tField.setAccessible(true);
- return tField;
- } catch (Throwable e) {
- if (aLogErrors) e.printStackTrace(GT_Log.err);
- }
- return null;
- }
-
- 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) : aObject.getClass().getDeclaredField(aField);
- if (aPrivate) tField.setAccessible(true);
- return tField.get(aObject instanceof Class || aObject instanceof String ? null : aObject);
- } catch (Throwable e) {
- if (aLogErrors) e.printStackTrace(GT_Log.err);
- }
- return null;
- }
-
- public static Object callPublicMethod(Object aObject, String aMethod, Object... aParameters) {
- return callMethod(aObject, aMethod, false, false, true, aParameters);
- }
-
- public static Object callPrivateMethod(Object aObject, String aMethod, Object... aParameters) {
- return callMethod(aObject, aMethod, true, false, true, 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++) {
- if (aParameters[i] instanceof Class) {
- tParameterTypes[i] = (Class) aParameters[i];
- aParameters[i] = null;
- } else {
- tParameterTypes[i] = aParameters[i].getClass();
- }
- if (!aUseUpperCasedDataTypes) {
- if (tParameterTypes[i] == Boolean.class) tParameterTypes[i] = boolean.class;
- else if (tParameterTypes[i] == Byte.class) tParameterTypes[i] = byte.class;
- else if (tParameterTypes[i] == Short.class) tParameterTypes[i] = short.class;
- else if (tParameterTypes[i] == Integer.class) tParameterTypes[i] = int.class;
- else if (tParameterTypes[i] == Long.class) tParameterTypes[i] = long.class;
- else if (tParameterTypes[i] == Float.class) tParameterTypes[i] = float.class;
- else if (tParameterTypes[i] == Double.class) tParameterTypes[i] = double.class;
- }
- }
-
- 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);
- } catch (Throwable e) {
- if (aLogErrors) e.printStackTrace(GT_Log.err);
- }
- return null;
- }
-
- public static Object callConstructor(String aClass, int aConstructorIndex, Object aReplacementObject, boolean aLogErrors, Object... aParameters) {
- if (aConstructorIndex < 0) {
- try {
- for (Constructor tConstructor : Class.forName(aClass).getConstructors()) {
- try {
- return tConstructor.newInstance(aParameters);
- } catch (Throwable e) {/*Do nothing*/}
- }
- } catch (Throwable e) {
- if (aLogErrors) e.printStackTrace(GT_Log.err);
- }
- } else {
- try {
- return Class.forName(aClass).getConstructors()[aConstructorIndex].newInstance(aParameters);
- } catch (Throwable e) {
- if (aLogErrors) e.printStackTrace(GT_Log.err);
- }
- }
- return aReplacementObject;
- }
-
- public static String capitalizeString(String aString) {
- if (aString != null && aString.length() > 0)
- return aString.substring(0, 1).toUpperCase() + aString.substring(1);
- return E;
- }
-
- public static boolean getPotion(EntityLivingBase aPlayer, int aPotionIndex) {
- try {
- Field tPotionHashmap = null;
-
- Field[] var3 = EntityLiving.class.getDeclaredFields();
- int var4 = var3.length;
-
- for (int var5 = 0; var5 < var4; ++var5) {
- Field var6 = var3[var5];
- if (var6.getType() == HashMap.class) {
- tPotionHashmap = var6;
- tPotionHashmap.setAccessible(true);
- break;
- }
- }
-
- if (tPotionHashmap != null)
- return ((HashMap) tPotionHashmap.get(aPlayer)).get(Integer.valueOf(aPotionIndex)) != null;
- } catch (Throwable e) {
- if (D1) e.printStackTrace(GT_Log.err);
- }
- return false;
- }
-
- public static String getClassName(Object aObject) {
- if (aObject == null) return "null";
- return aObject.getClass().getName().substring(aObject.getClass().getName().lastIndexOf(".") + 1);
- }
-
- public static void removePotion(EntityLivingBase aPlayer, int aPotionIndex) {
- try {
- Field tPotionHashmap = null;
-
- Field[] var3 = EntityLiving.class.getDeclaredFields();
- int var4 = var3.length;
-
- for (int var5 = 0; var5 < var4; ++var5) {
- Field var6 = var3[var5];
- if (var6.getType() == HashMap.class) {
- tPotionHashmap = var6;
- tPotionHashmap.setAccessible(true);
- break;
- }
- }
-
- if (tPotionHashmap != null) ((HashMap) tPotionHashmap.get(aPlayer)).remove(Integer.valueOf(aPotionIndex));
- } catch (Throwable e) {
- if (D1) e.printStackTrace(GT_Log.err);
- }
- }
-
- public static boolean getFullInvisibility(EntityPlayer aPlayer) {
- try {
- if (aPlayer.isInvisible()) {
- for (int i = 0; i < 4; i++) {
- if (aPlayer.inventory.armorInventory[i] != null) {
- if (aPlayer.inventory.armorInventory[i].getItem() instanceof GT_EnergyArmor_Item) {
- if ((((GT_EnergyArmor_Item) aPlayer.inventory.armorInventory[i].getItem()).mSpecials & 512) != 0) {
- if (GT_ModHandler.canUseElectricItem(aPlayer.inventory.armorInventory[i], 10000)) {
- return true;
- }
- }
- }
- }
- }
- }
- } catch (Throwable e) {
- if (D1) e.printStackTrace(GT_Log.err);
- }
- return false;
- }
-
- 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))) {
- if (!tItem.isDead) {
- aWorld.removeEntity(tItem);
- tItem.setDead();
- return tItem.getEntityItem();
- }
- }
- return null;
- }
-
- public static byte getOppositeSide(int aSide) {
- return (byte) ForgeDirection.getOrientation(aSide).getOpposite().ordinal();
- }
-
- public static byte getTier(long l) {
- byte i = -1;
- while (++i < V.length) if (l <= V[i]) return i;
- return i;
- }
-
- public static void sendChatToPlayer(EntityPlayer aPlayer, String aChatMessage) {
- if (aPlayer instanceof EntityPlayerMP && aChatMessage != null) {
- aPlayer.addChatComponentMessage(new ChatComponentText(aChatMessage));
- }
- }
-
- public static void checkAvailabilities() {
- if (CHECK_ALL) {
- try {
- Class tClass = IItemDuct.class;
- tClass.getCanonicalName();
- TE_CHECK = true;
- } catch (Throwable e) {/**/}
- try {
- Class tClass = buildcraft.api.transport.IPipeTile.class;
- tClass.getCanonicalName();
- BC_CHECK = true;
- } catch (Throwable e) {/**/}
- try {
- Class tClass = cofh.api.energy.IEnergyReceiver.class;
- tClass.getCanonicalName();
- RF_CHECK = true;
- } catch (Throwable e) {/**/}
- CHECK_ALL = false;
- }
- }
-
- public static boolean isConnectableNonInventoryPipe(Object aTileEntity, int aSide) {
- if (aTileEntity == null) return false;
- checkAvailabilities();
- if (TE_CHECK && aTileEntity instanceof IItemDuct) return true;
- if (BC_CHECK && aTileEntity instanceof buildcraft.api.transport.IPipeTile)
- return ((buildcraft.api.transport.IPipeTile) aTileEntity).isPipeConnected(ForgeDirection.getOrientation(aSide));
- if (GregTech_API.mTranslocator && aTileEntity instanceof codechicken.translocator.TileItemTranslocator) return true;
-
- return false;
- }
- /**
- * 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) {
- return moveStackIntoPipe(aTileEntity1, aTileEntity2, aGrabSlots, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, true);
- }
-
- /**
- * 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, boolean dropItem) {
- if (aTileEntity1 == null || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMaxMoveAtOnce <= 0 || aMinMoveAtOnce > aMaxMoveAtOnce)
- return 0;
- if (aTileEntity2 != null) {
- checkAvailabilities();
- if (TE_CHECK && aTileEntity2 instanceof IItemDuct) {
- for (int i = 0; i < aGrabSlots.length; i++) {
- if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabSlots[i]), true, aInvertFilter)) {
- if (isAllowedToTakeFromSlot(aTileEntity1, aGrabSlots[i], (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlots[i]))) {
- if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize) {
- ItemStack tStack = copyAmount(Math.min(aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), aTileEntity1.getStackInSlot(aGrabSlots[i]));
- ItemStack rStack = ((IItemDuct) aTileEntity2).insertItem(ForgeDirection.getOrientation(aPutTo), copy(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);
- aTileEntity1.decrStackSize(aGrabSlots[i], tMovedItemCount);
- aTileEntity1.markDirty();
- return tMovedItemCount;
- }
- }
- }
- }
- }
- return 0;
- }
- if (BC_CHECK && aTileEntity2 instanceof buildcraft.api.transport.IPipeTile) {
- for (int i = 0; i < aGrabSlots.length; i++) {
- if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabSlots[i]), true, aInvertFilter)) {
- if (isAllowedToTakeFromSlot(aTileEntity1, aGrabSlots[i], (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlots[i]))) {
- if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize) {
- ItemStack tStack = copyAmount(Math.min(aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), aTileEntity1.getStackInSlot(aGrabSlots[i]));
- byte tMovedItemCount = (byte) ((buildcraft.api.transport.IPipeTile) aTileEntity2).injectItem(copy(tStack), false, ForgeDirection.getOrientation(aPutTo));
- if (tMovedItemCount >= Math.max(aMinMoveAtOnce, aMinTargetStackSize)) {
- tMovedItemCount = (byte) (((buildcraft.api.transport.IPipeTile) aTileEntity2).injectItem(copyAmount(tMovedItemCount, tStack), true, ForgeDirection.getOrientation(aPutTo)));
- aTileEntity1.decrStackSize(aGrabSlots[i], tMovedItemCount);
- aTileEntity1.markDirty();
- return tMovedItemCount;
- }
- }
- }
- }
- }
- return 0;
- }
- }
-
- ForgeDirection tDirection = ForgeDirection.getOrientation(aGrabFrom);
- 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, tZ = ((TileEntity) aTileEntity1).zCoord + tDirection.offsetZ;
- if (!hasBlockHitBox(((TileEntity) aTileEntity1).getWorldObj(), tX, tY, tZ) && dropItem) {
- for (int i = 0; i < aGrabSlots.length; i++) {
- if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabSlots[i]), true, aInvertFilter)) {
- if (isAllowedToTakeFromSlot(aTileEntity1, aGrabSlots[i], (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlots[i]))) {
- if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize) {
- ItemStack tStack = copyAmount(Math.min(aTileEntity1.getStackInSlot(aGrabSlots[i]).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), aTileEntity1.getStackInSlot(aGrabSlots[i]));
- EntityItem tEntity = new EntityItem(((TileEntity) aTileEntity1).getWorldObj(), tX + 0.5, tY + 0.5, tZ + 0.5, tStack);
- tEntity.motionX = tEntity.motionY = tEntity.motionZ = 0;
- ((TileEntity) aTileEntity1).getWorldObj().spawnEntityInWorld(tEntity);
- aTileEntity1.decrStackSize(aGrabSlots[i], tStack.stackSize);
- aTileEntity1.markDirty();
- return (byte) tStack.stackSize;
- }
- }
- }
- }
- }
- }
- return 0;
- }
-
- /**
- * 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 || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMaxMoveAtOnce <= 0 || aMinMoveAtOnce > aMaxMoveAtOnce)
- return 0;
-
- ItemStack tStack1 = aTileEntity1.getStackInSlot(aGrabFrom), tStack2 = aTileEntity2.getStackInSlot(aPutTo), tStack3 = null;
- if (tStack1 != null) {
- if (tStack2 != null && !areStacksEqual(tStack1, tStack2)) return 0;
- tStack3 = copy(tStack1);
- aMaxTargetStackSize = (byte) Math.min(aMaxTargetStackSize, Math.min(tStack3.getMaxStackSize(), Math.min(tStack2 == null ? Integer.MAX_VALUE : tStack2.getMaxStackSize(), aTileEntity2.getInventoryStackLimit())));
- 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) && tStack3.stackSize >= aMinMoveAtOnce) {
- tStack3 = aTileEntity1.decrStackSize(aGrabFrom, tStack3.stackSize);
- aTileEntity1.markDirty();
- if (tStack3 != null) {
- if (tStack2 == null) {
- aTileEntity2.setInventorySlotContents(aPutTo, copy(tStack3));
- aTileEntity2.markDirty();
- } else {
- tStack2.stackSize += tStack3.stackSize;
- aTileEntity2.markDirty();
- }
- return (byte) tStack3.stackSize;
- }
- }
- }
- return 0;
- }
-
- public static boolean isAllowedToTakeFromSlot(IInventory aTileEntity, int aSlot, byte aSide, ItemStack aStack) {
- if (ForgeDirection.getOrientation(aSide) == ForgeDirection.UNKNOWN) {
- return isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 0, aStack)
- || isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 1, aStack)
- || isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 2, aStack)
- || isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 3, aStack)
- || isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 4, aStack)
- || isAllowedToTakeFromSlot(aTileEntity, aSlot, (byte) 5, aStack);
- }
- if (aTileEntity instanceof ISidedInventory)
- return ((ISidedInventory) aTileEntity).canExtractItem(aSlot, aStack, aSide);
- return true;
- }
-
- 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;
- if (ForgeDirection.getOrientation(aSide) == ForgeDirection.UNKNOWN) {
- return isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 0, aStack, aMaxStackSize)
- || isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 1, aStack, aMaxStackSize)
- || isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 2, aStack, aMaxStackSize)
- || isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 3, aStack, aMaxStackSize)
- || isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 4, aStack, aMaxStackSize)
- || isAllowedToPutIntoSlot(aTileEntity, aSlot, (byte) 5, aStack, aMaxStackSize);
- }
- if (aTileEntity instanceof ISidedInventory && !((ISidedInventory) aTileEntity).canInsertItem(aSlot, aStack, aSide))
- return false;
- return aSlot < aTileEntity.getSizeInventory() && aTileEntity.isItemValidForSlot(aSlot, aStack);
- }
-
- /**
- * Moves Stack from Inv-Side to Inv-Side.
- *
- * @return the Amount of moved Items
- */
- public static byte moveOneItemStack(Object aTileEntity1, Object aTileEntity2, byte aGrabFrom, byte aPutTo, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) {
- if (aTileEntity1 instanceof IInventory)
- return moveOneItemStack((IInventory) aTileEntity1, aTileEntity2, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, true);
- return 0;
- }
-
- /**
- * This is only because I needed an additional Parameter for the Double Chest Check.
- */
- private static byte moveOneItemStack(IInventory aTileEntity1, Object aTileEntity2, byte aGrabFrom, byte aPutTo, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce, boolean aDoCheckChests) {
- if (aTileEntity1 == null || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMaxMoveAtOnce <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMinMoveAtOnce > aMaxMoveAtOnce)
- return 0;
-
- int[] tGrabSlots = null;
- if (aTileEntity1 instanceof ISidedInventory)
- tGrabSlots = ((ISidedInventory) aTileEntity1).getAccessibleSlotsFromSide(aGrabFrom);
- if (tGrabSlots == null) {
- tGrabSlots = new int[aTileEntity1.getSizeInventory()];
- for (int i = 0; i < tGrabSlots.length; i++) tGrabSlots[i] = i;
- }
-
- if (aTileEntity2 != null && aTileEntity2 instanceof IInventory) {
- int[] tPutSlots = null;
- if (aTileEntity2 instanceof ISidedInventory)
- tPutSlots = ((ISidedInventory) aTileEntity2).getAccessibleSlotsFromSide(aPutTo);
-
- if (tPutSlots == null) {
- tPutSlots = new int[((IInventory) aTileEntity2).getSizeInventory()];
- for (int i = 0; i < tPutSlots.length; i++) tPutSlots[i] = i;
- }
-
- for (int i = 0; i < tGrabSlots.length; i++) {
- byte tMovedItemCount = 0;
- for (int j = 0; j < tPutSlots.length; j++) {
- if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(tGrabSlots[i]), true, aInvertFilter)) {
- if (isAllowedToTakeFromSlot(aTileEntity1, tGrabSlots[i], aGrabFrom, aTileEntity1.getStackInSlot(tGrabSlots[i]))) {
- if (isAllowedToPutIntoSlot((IInventory) aTileEntity2, tPutSlots[j], aPutTo, aTileEntity1.getStackInSlot(tGrabSlots[i]), aMaxTargetStackSize)) {
- tMovedItemCount += moveStackFromSlotAToSlotB(aTileEntity1, (IInventory) aTileEntity2, tGrabSlots[i], tPutSlots[j], aMaxTargetStackSize, aMinTargetStackSize, (byte) (aMaxMoveAtOnce - tMovedItemCount), aMinMoveAtOnce);
- if (tMovedItemCount >= aMaxMoveAtOnce) {
- return tMovedItemCount;
-
- }
- }
- }
- }
- }
- if (tMovedItemCount > 0) return tMovedItemCount;
- }
-
- if (aDoCheckChests && aTileEntity1 instanceof TileEntityChest) {
- TileEntityChest tTileEntity1 = (TileEntityChest) aTileEntity1;
- if (tTileEntity1.adjacentChestChecked) {
- byte tAmount = 0;
- if (tTileEntity1.adjacentChestXNeg != null) {
- tAmount = moveOneItemStack(tTileEntity1.adjacentChestXNeg, aTileEntity2, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false);
- } else if (tTileEntity1.adjacentChestZNeg != null) {
- tAmount = moveOneItemStack(tTileEntity1.adjacentChestZNeg, aTileEntity2, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false);
- } else if (tTileEntity1.adjacentChestXPos != null) {
- tAmount = moveOneItemStack(tTileEntity1.adjacentChestXPos, aTileEntity2, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false);
- } else if (tTileEntity1.adjacentChestZPos != null) {
- tAmount = moveOneItemStack(tTileEntity1.adjacentChestZPos, aTileEntity2, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false);
- }
- if (tAmount != 0) return tAmount;
- }
- }
- if (aDoCheckChests && aTileEntity2 instanceof TileEntityChest) {
- TileEntityChest tTileEntity2 = (TileEntityChest) aTileEntity2;
- if (tTileEntity2.adjacentChestChecked) {
- byte tAmount = 0;
- if (tTileEntity2.adjacentChestXNeg != null) {
- tAmount = moveOneItemStack(aTileEntity1, tTileEntity2.adjacentChestXNeg, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false);
- } else if (tTileEntity2.adjacentChestZNeg != null) {
- tAmount = moveOneItemStack(aTileEntity1, tTileEntity2.adjacentChestZNeg, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false);
- } else if (tTileEntity2.adjacentChestXPos != null) {
- tAmount = moveOneItemStack(aTileEntity1, tTileEntity2.adjacentChestXPos, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false);
- } else if (tTileEntity2.adjacentChestZPos != null) {
- tAmount = moveOneItemStack(aTileEntity1, tTileEntity2.adjacentChestZPos, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, false);
- }
- if (tAmount != 0) return tAmount;
- }
- }
- }
-
- return moveStackIntoPipe(aTileEntity1, aTileEntity2, tGrabSlots, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce, aDoCheckChests);
- }
-
- /**
- * Moves Stack from Inv-Side to Inv-Slot.
- *
- * @return the Amount of moved Items
- */
- public static byte moveOneItemStackIntoSlot(Object aTileEntity1, Object aTileEntity2, byte aGrabFrom, int aPutTo, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) {
- if (aTileEntity1 == null || !(aTileEntity1 instanceof IInventory) || aPutTo < 0 || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMaxMoveAtOnce <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMinMoveAtOnce > aMaxMoveAtOnce)
- return 0;
-
- int[] tGrabSlots = null;
- if (aTileEntity1 instanceof ISidedInventory)
- tGrabSlots = ((ISidedInventory) aTileEntity1).getAccessibleSlotsFromSide(aGrabFrom);
- if (tGrabSlots == null) {
- tGrabSlots = new int[((IInventory) aTileEntity1).getSizeInventory()];
- for (int i = 0; i < tGrabSlots.length; i++) tGrabSlots[i] = i;
- }
-
- if (aTileEntity2 instanceof IInventory) {
- for (int i = 0; i < tGrabSlots.length; i++) {
- if (listContainsItem(aFilter, ((IInventory) aTileEntity1).getStackInSlot(tGrabSlots[i]), true, aInvertFilter)) {
- if (isAllowedToTakeFromSlot((IInventory) aTileEntity1, tGrabSlots[i], aGrabFrom, ((IInventory) aTileEntity1).getStackInSlot(tGrabSlots[i]))) {
- if (isAllowedToPutIntoSlot((IInventory) aTileEntity2, aPutTo, (byte) 6, ((IInventory) aTileEntity1).getStackInSlot(tGrabSlots[i]), aMaxTargetStackSize)) {
- byte tMovedItemCount = moveStackFromSlotAToSlotB((IInventory) aTileEntity1, (IInventory) aTileEntity2, tGrabSlots[i], aPutTo, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce);
- if (tMovedItemCount > 0) return tMovedItemCount;
- }
- }
- }
- }
- }
-
- moveStackIntoPipe(((IInventory) aTileEntity1), aTileEntity2, tGrabSlots, aGrabFrom, aPutTo, aFilter, aInvertFilter, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce);
- return 0;
- }
-
- /**
- * Moves Stack from Inv-Slot to Inv-Slot.
- *
- * @return the Amount of moved Items
- */
- public static byte moveFromSlotToSlot(IInventory aTileEntity1, IInventory aTileEntity2, int aGrabFrom, int aPutTo, List<ItemStack> aFilter, boolean aInvertFilter, byte aMaxTargetStackSize, byte aMinTargetStackSize, byte aMaxMoveAtOnce, byte aMinMoveAtOnce) {
- if (aTileEntity1 == null || aTileEntity2 == null || aGrabFrom < 0 || aPutTo < 0 || aMaxTargetStackSize <= 0 || aMinTargetStackSize <= 0 || aMaxMoveAtOnce <= 0 || aMinTargetStackSize > aMaxTargetStackSize || aMinMoveAtOnce > aMaxMoveAtOnce)
- return 0;
- if (listContainsItem(aFilter, aTileEntity1.getStackInSlot(aGrabFrom), true, aInvertFilter)) {
- if (isAllowedToTakeFromSlot(aTileEntity1, aGrabFrom, (byte) 6, aTileEntity1.getStackInSlot(aGrabFrom))) {
- if (isAllowedToPutIntoSlot(aTileEntity2, aPutTo, (byte) 6, aTileEntity1.getStackInSlot(aGrabFrom), aMaxTargetStackSize)) {
- byte tMovedItemCount = moveStackFromSlotAToSlotB(aTileEntity1, aTileEntity2, aGrabFrom, aPutTo, aMaxTargetStackSize, aMinTargetStackSize, aMaxMoveAtOnce, aMinMoveAtOnce);
- if (tMovedItemCount > 0) return tMovedItemCount;
- }
- }
- }
- return 0;
- }
-
- public static boolean listContainsItem(Collection<ItemStack> aList, ItemStack aStack, boolean aTIfListEmpty, boolean aInvertFilter) {
- if (aStack == null || aStack.stackSize < 1) return false;
- if (aList == null) return aTIfListEmpty;
- while (aList.contains(null)) aList.remove(null);
- if (aList.size() < 1) return aTIfListEmpty;
- Iterator<ItemStack> tIterator = aList.iterator();
- ItemStack tStack = null;
- while (tIterator.hasNext())
- if ((tStack = tIterator.next()) != null && areStacksEqual(aStack, tStack)) return !aInvertFilter;
- return aInvertFilter;
- }
-
- public static boolean areStacksOrToolsEqual(ItemStack aStack1, ItemStack aStack2) {
- if (aStack1 != null && aStack2 != null && aStack1.getItem() == aStack2.getItem()) {
- if (aStack1.getItem().isDamageable()) return true;
- return ((aStack1.getTagCompound() == null) == (aStack2.getTagCompound() == null)) && (aStack1.getTagCompound() == null || aStack1.getTagCompound().equals(aStack2.getTagCompound())) && (Items.feather.getDamage(aStack1) == Items.feather.getDamage(aStack2) || Items.feather.getDamage(aStack1) == W || Items.feather.getDamage(aStack2) == W);
- }
- return false;
- }
-
- public static boolean areFluidsEqual(FluidStack aFluid1, FluidStack aFluid2) {
- return areFluidsEqual(aFluid1, aFluid2, false);
- }
-
- public static boolean areFluidsEqual(FluidStack aFluid1, FluidStack aFluid2, boolean aIgnoreNBT) {
- return aFluid1 != null && aFluid2 != null && aFluid1.getFluid() == aFluid2.getFluid() && (aIgnoreNBT || ((aFluid1.tag == null) == (aFluid2.tag == null)) && (aFluid1.tag == null || aFluid1.tag.equals(aFluid2.tag)));
- }
-
- public static boolean areStacksEqual(ItemStack aStack1, ItemStack aStack2) {
- return areStacksEqual(aStack1, aStack2, false);
- }
-
- public static boolean areStacksEqual(ItemStack aStack1, ItemStack aStack2, boolean aIgnoreNBT) {
- return aStack1 != null && aStack2 != null && aStack1.getItem() == aStack2.getItem() && (aIgnoreNBT || ((aStack1.getTagCompound() == null) == (aStack2.getTagCompound() == null)) && (aStack1.getTagCompound() == null || aStack1.getTagCompound().equals(aStack2.getTagCompound()))) && (Items.feather.getDamage(aStack1) == Items.feather.getDamage(aStack2) || Items.feather.getDamage(aStack1) == W || Items.feather.getDamage(aStack2) == W);
- }
-
- public static boolean areUnificationsEqual(ItemStack aStack1, ItemStack aStack2) {
- return areUnificationsEqual(aStack1, aStack2, false);
- }
-
- public static boolean areUnificationsEqual(ItemStack aStack1, ItemStack aStack2, boolean aIgnoreNBT) {
- return areStacksEqual(GT_OreDictUnificator.get(aStack1), GT_OreDictUnificator.get(aStack2), aIgnoreNBT);
- }
-
- public static String getFluidName(Fluid aFluid, boolean aLocalized) {
- if (aFluid == null) return E;
- String rName = aLocalized ? aFluid.getLocalizedName(new FluidStack(aFluid, 0)) : aFluid.getUnlocalizedName();
- if (rName.contains("fluid.") || rName.contains("tile."))
- return capitalizeString(rName.replaceAll("fluid.", E).replaceAll("tile.", E));
- return rName;
- }
-
- public static String getFluidName(FluidStack aFluid, boolean aLocalized) {
- if (aFluid == null) return E;
- return getFluidName(aFluid.getFluid(), aLocalized);
- }
-
- public static void reInit() {
- sFilledContainerToData.clear();
- sEmptyContainerToFluidToData.clear();
- for (FluidContainerData tData : sFluidContainerList) {
- sFilledContainerToData.put(new GT_ItemStack(tData.filledContainer), tData);
- Map<Fluid, FluidContainerData> tFluidToContainer = sEmptyContainerToFluidToData.get(new GT_ItemStack(tData.emptyContainer));
- if (tFluidToContainer == null) {
- sEmptyContainerToFluidToData.put(new GT_ItemStack(tData.emptyContainer), tFluidToContainer = new /*Concurrent*/HashMap<Fluid,