Search in sources :

Example 11 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project ArsMagica2 by Mithion.

the class InventoryUtilities method inventoryHasRoomFor.

public static boolean inventoryHasRoomFor(IInventory inventory, ItemStack stack, int qty, int side) {
    if (inventory instanceof ISidedInventory) {
        ISidedInventory sidedInventory = (ISidedInventory) inventory;
        int[] slots = sidedInventory.getAccessibleSlotsFromSide(side);
        for (int i = 0; i < slots.length; i++) {
            ItemStack invStack = inventory.getStackInSlot(slots[i]);
            if (invStack == null)
                return true;
            if (compareItemStacks(invStack, stack, true, false, true, true) && invStack.getMaxStackSize() - invStack.stackSize >= qty)
                return true;
        }
        return false;
    } else {
        return inventoryHasRoomFor(inventory, stack, qty);
    }
}
Also used : ISidedInventory(net.minecraft.inventory.ISidedInventory) ItemStack(net.minecraft.item.ItemStack)

Example 12 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project PneumaticCraft by MineMaarten.

the class IOHelper method insert.

public static ItemStack insert(IInventory inventory, ItemStack itemStack, int side, boolean simulate) {
    if (inventory instanceof ISidedInventory && side > -1) {
        ISidedInventory isidedinventory = (ISidedInventory) inventory;
        int[] aint = isidedinventory.getAccessibleSlotsFromSide(side);
        for (int j = 0; j < aint.length && itemStack != null && itemStack.stackSize > 0; ++j) {
            itemStack = insert(inventory, itemStack, aint[j], side, simulate);
        }
    } else if (inventory != null) {
        int k = inventory.getSizeInventory();
        for (int l = 0; l < k && itemStack != null && itemStack.stackSize > 0; ++l) {
            itemStack = insert(inventory, itemStack, l, side, simulate);
        }
    }
    if (itemStack != null && itemStack.stackSize == 0) {
        itemStack = null;
    }
    return itemStack;
}
Also used : ISidedInventory(net.minecraft.inventory.ISidedInventory)

Example 13 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project NewHorizonsCoreMod by GTNewHorizons.

the class GT_CustomMetaPipeEntity_Item method onPostTick.

@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
    if (aBaseMetaTileEntity.isServerSide() && aTick % 10 == 0) {
        mConnections = 0;
        if (aTick % mCustomTickTime == 0)
            mTransferredItems = 0;
        for (byte i = 0; i < 6; i++) {
            TileEntity tTileEntity = aBaseMetaTileEntity.getTileEntityAtSide(i);
            if (tTileEntity != null) {
                boolean temp = GT_Utility.isConnectableNonInventoryPipe(tTileEntity, GT_Utility.getOppositeSide(i));
                if (tTileEntity instanceof IGregTechTileEntity) {
                    temp = true;
                    if (((IGregTechTileEntity) tTileEntity).getMetaTileEntity() == null)
                        continue;
                    if (aBaseMetaTileEntity.getColorization() >= 0) {
                        byte tColor = ((IGregTechTileEntity) tTileEntity).getColorization();
                        if (tColor >= 0 && tColor != aBaseMetaTileEntity.getColorization()) {
                            continue;
                        }
                    }
                    if (((IGregTechTileEntity) tTileEntity).getMetaTileEntity().connectsToItemPipe(GT_Utility.getOppositeSide(i))) {
                        mConnections |= (1 << i);
                        continue;
                    }
                }
                if (tTileEntity instanceof IInventory) {
                    temp = true;
                    if (((IInventory) tTileEntity).getSizeInventory() <= 0) {
                        continue;
                    }
                }
                if (tTileEntity instanceof ISidedInventory) {
                    temp = true;
                    int[] tSlots = ((ISidedInventory) tTileEntity).getAccessibleSlotsFromSide(GT_Utility.getOppositeSide(i));
                    if (tSlots == null || tSlots.length <= 0) {
                        continue;
                    }
                }
                if (temp) {
                    if (tTileEntity instanceof ICoverable && ((ICoverable) tTileEntity).getCoverBehaviorAtSide(GT_Utility.getOppositeSide(i)).alwaysLookConnected(GT_Utility.getOppositeSide(i), ((ICoverable) tTileEntity).getCoverIDAtSide(GT_Utility.getOppositeSide(i)), ((ICoverable) tTileEntity).getCoverDataAtSide(GT_Utility.getOppositeSide(i)), ((ICoverable) tTileEntity))) {
                        mConnections |= (1 << i);
                        continue;
                    }
                    if (aBaseMetaTileEntity.getCoverBehaviorAtSide(i).alwaysLookConnected(i, aBaseMetaTileEntity.getCoverIDAtSide(i), aBaseMetaTileEntity.getCoverDataAtSide(i), aBaseMetaTileEntity)) {
                        mConnections |= (1 << i);
                        continue;
                    }
                    if (aBaseMetaTileEntity.getCoverBehaviorAtSide(i).letsItemsIn(i, aBaseMetaTileEntity.getCoverIDAtSide(i), aBaseMetaTileEntity.getCoverDataAtSide(i), -1, aBaseMetaTileEntity)) {
                        mConnections |= (1 << i);
                        continue;
                    }
                    if (aBaseMetaTileEntity.getCoverBehaviorAtSide(i).letsItemsOut(i, aBaseMetaTileEntity.getCoverIDAtSide(i), aBaseMetaTileEntity.getCoverDataAtSide(i), -1, aBaseMetaTileEntity)) {
                        mConnections |= (1 << i);
                        continue;
                    }
                }
            }
        }
        if (oLastReceivedFrom == mLastReceivedFrom) {
            doTickProfilingInThisTick = false;
            ArrayList<IMetaTileEntityItemPipe> tPipeList = new ArrayList<IMetaTileEntityItemPipe>();
            for (boolean temp = true; temp && !isInventoryEmpty() && pipeCapacityCheck(); ) {
                temp = false;
                tPipeList.clear();
                for (IMetaTileEntityItemPipe tTileEntity : GT_Utility.sortMapByValuesAcending(IMetaTileEntityItemPipe.Util.scanPipes(this, new HashMap<IMetaTileEntityItemPipe, Long>(), 0, false, false)).keySet()) {
                    if (temp)
                        break;
                    tPipeList.add(tTileEntity);
                    while (!temp && !isInventoryEmpty() && tTileEntity.sendItemStack(aBaseMetaTileEntity)) for (IMetaTileEntityItemPipe tPipe : tPipeList) if (!tPipe.incrementTransferCounter(1))
                        temp = true;
                }
            }
        }
        if (isInventoryEmpty())
            mLastReceivedFrom = 6;
        oLastReceivedFrom = mLastReceivedFrom;
    } else if (aBaseMetaTileEntity.isClientSide() && GT_Client.changeDetected == 4)
        aBaseMetaTileEntity.issueTextureUpdate();
}
Also used : IInventory(net.minecraft.inventory.IInventory) ICoverable(gregtech.api.interfaces.tileentity.ICoverable) IGregTechTileEntity(gregtech.api.interfaces.tileentity.IGregTechTileEntity) IMetaTileEntityItemPipe(gregtech.api.interfaces.metatileentity.IMetaTileEntityItemPipe) ArrayList(java.util.ArrayList) IGregTechTileEntity(gregtech.api.interfaces.tileentity.IGregTechTileEntity) IMetaTileEntity(gregtech.api.interfaces.metatileentity.IMetaTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ISidedInventory(net.minecraft.inventory.ISidedInventory)

Example 14 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project PneumaticCraft by MineMaarten.

the class IOHelper method extract.

public static ItemStack extract(IInventory inventory, ForgeDirection direction, boolean simulate) {
    if (inventory instanceof ISidedInventory) {
        ISidedInventory isidedinventory = (ISidedInventory) inventory;
        int[] accessibleSlotsFromSide = isidedinventory.getAccessibleSlotsFromSide(direction.ordinal());
        for (int anAccessibleSlotsFromSide : accessibleSlotsFromSide) {
            ItemStack stack = extract(inventory, direction, anAccessibleSlotsFromSide, simulate);
            if (stack != null)
                return stack;
        }
    } else {
        int j = inventory.getSizeInventory();
        for (int k = 0; k < j; ++k) {
            ItemStack stack = extract(inventory, direction, k, simulate);
            if (stack != null)
                return stack;
        }
    }
    return null;
}
Also used : ISidedInventory(net.minecraft.inventory.ISidedInventory) ItemStack(net.minecraft.item.ItemStack)

Example 15 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project LogisticsPipes by RS485.

the class PipeTransportLogistics method handleTileReachedServer_internal.

protected final void handleTileReachedServer_internal(LPTravelingItemServer arrivingItem, TileEntity tile, ForgeDirection dir) {
    if (isRouted && getPipe().container.tilePart.getBCPipePluggable(dir) != null && getPipe().container.tilePart.getBCPipePluggable(dir).isAcceptingItems(arrivingItem)) {
        LPTravelingItemServer remainingItem = getPipe().container.tilePart.getBCPipePluggable(dir).handleItem(arrivingItem);
        if (remainingItem != null) {
            getRoutedPipe().getRouter().update(true, getRoutedPipe());
            this.injectItem(remainingItem, dir);
        }
        return;
    }
    if (getPipe() instanceof PipeItemsFluidSupplier) {
        ((PipeItemsFluidSupplier) getPipe()).endReached(arrivingItem, tile);
        if (arrivingItem.getItemIdentifierStack().getStackSize() <= 0) {
            return;
        }
    }
    markChunkModified(tile);
    if (MainProxy.isServer(getWorld()) && arrivingItem.getInfo() != null && arrivingItem.getArrived() && isRouted) {
        getRoutedPipe().notifyOfItemArival(arrivingItem.getInfo());
    }
    if (getPipe() instanceof FluidRoutedPipe) {
        if (((FluidRoutedPipe) getPipe()).endReached(arrivingItem, tile)) {
            return;
        }
    }
    boolean isSpecialConnectionInformationTransition = false;
    if (MainProxy.isServer(getWorld())) {
        if (SimpleServiceLocator.specialtileconnection.needsInformationTransition(tile)) {
            isSpecialConnectionInformationTransition = true;
            SimpleServiceLocator.specialtileconnection.transmit(tile, arrivingItem);
        }
    }
    if (SimpleServiceLocator.pipeInformationManager.isItemPipe(tile)) {
        if (passToNextPipe(arrivingItem, tile)) {
            return;
        }
    } else if (tile instanceof IInventory && isRouted) {
        getRoutedPipe().getCacheHolder().trigger(CacheTypes.Inventory);
        // items.scheduleRemoval(arrivingItem);
        if (MainProxy.isServer(getWorld())) {
            // destroy the item on exit if it isn't exitable
            if (!isSpecialConnectionInformationTransition && !isItemExitable(arrivingItem.getItemIdentifierStack())) {
                return;
            }
            // last chance for chassi to back out
            if (arrivingItem != null) {
                if (arrivingItem.getTransportMode() != TransportMode.Active && !getRoutedPipe().getTransportLayer().stillWantItem(arrivingItem)) {
                    reverseItem(arrivingItem);
                    return;
                }
            }
            ISlotUpgradeManager slotManager;
            {
                ModulePositionType slot = null;
                int positionInt = -1;
                if (arrivingItem.getInfo().targetInfo instanceof ChassiTargetInformation) {
                    positionInt = ((ChassiTargetInformation) arrivingItem.getInfo().targetInfo).getModuleSlot();
                    slot = ModulePositionType.SLOT;
                } else if (LPConstants.DEBUG && container.pipe instanceof PipeLogisticsChassi) {
                    System.out.println(arrivingItem);
                    new RuntimeException("[ItemInsertion] Information weren't ment for a chassi pipe").printStackTrace();
                }
                slotManager = getRoutedPipe().getUpgradeManager(slot, positionInt);
            }
            boolean tookSome = false;
            if (arrivingItem.getAdditionalTargetInformation() instanceof ITargetSlotInformation) {
                ITargetSlotInformation information = (ITargetSlotInformation) arrivingItem.getAdditionalTargetInformation();
                IInventory inv = (IInventory) tile;
                if (inv instanceof ISidedInventory) {
                    inv = new SidedInventoryMinecraftAdapter((ISidedInventory) inv, ForgeDirection.UNKNOWN, false);
                }
                IInventoryUtil util = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(inv);
                if (util instanceof ISpecialInsertion) {
                    int slot = information.getTargetSlot();
                    int amount = information.getAmount();
                    if (util.getSizeInventory() > slot) {
                        ItemStack content = util.getStackInSlot(slot);
                        ItemStack toAdd = arrivingItem.getItemIdentifierStack().makeNormalStack();
                        toAdd.stackSize = Math.min(toAdd.stackSize, Math.max(0, amount - (content != null ? content.stackSize : 0)));
                        if (toAdd.stackSize > 0) {
                            if (util.getSizeInventory() > slot) {
                                int added = ((ISpecialInsertion) util).addToSlot(toAdd, slot);
                                arrivingItem.getItemIdentifierStack().lowerStackSize(added);
                                if (added > 0) {
                                    tookSome = true;
                                }
                            }
                        }
                    }
                    if (information.isLimited()) {
                        if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
                            reverseItem(arrivingItem);
                        }
                        return;
                    }
                }
            }
            // sneaky insertion
            if (!getRoutedPipe().getUpgradeManager().hasCombinedSneakyUpgrade() || slotManager.hasOwnSneakyUpgrade()) {
                ForgeDirection insertion = arrivingItem.output.getOpposite();
                if (slotManager.hasSneakyUpgrade()) {
                    insertion = slotManager.getSneakyOrientation();
                }
                ItemStack added = InventoryHelper.getTransactorFor(tile, insertion).add(arrivingItem.getItemIdentifierStack().makeNormalStack(), insertion, true);
                arrivingItem.getItemIdentifierStack().lowerStackSize(added.stackSize);
                if (added.stackSize > 0 && arrivingItem instanceof IRoutedItem) {
                    tookSome = true;
                    arrivingItem.setBufferCounter(0);
                }
                ItemRoutingInformation info;
                if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
                    // we have some leftovers, we are splitting the stack, we need to clone the info
                    info = arrivingItem.getInfo().clone();
                    // For InvSysCon
                    info.getItem().setStackSize(added.stackSize);
                    insertedItemStack(info, tile);
                } else {
                    info = arrivingItem.getInfo();
                    info.getItem().setStackSize(added.stackSize);
                    // For InvSysCon
                    insertedItemStack(info, tile);
                    // every item has been inserted.
                    return;
                }
            } else {
                ForgeDirection[] dirs = getRoutedPipe().getUpgradeManager().getCombinedSneakyOrientation();
                for (ForgeDirection insertion : dirs) {
                    if (insertion == null) {
                        continue;
                    }
                    ItemStack added = InventoryHelper.getTransactorFor(tile, insertion).add(arrivingItem.getItemIdentifierStack().makeNormalStack(), insertion, true);
                    arrivingItem.getItemIdentifierStack().lowerStackSize(added.stackSize);
                    if (added.stackSize > 0) {
                        tookSome = true;
                        arrivingItem.setBufferCounter(0);
                    }
                    ItemRoutingInformation info;
                    if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
                        // we have some leftovers, we are splitting the stack, we need to clone the info
                        info = arrivingItem.getInfo().clone();
                        // For InvSysCon
                        info.getItem().setStackSize(added.stackSize);
                        insertedItemStack(info, tile);
                    } else {
                        info = arrivingItem.getInfo();
                        info.getItem().setStackSize(added.stackSize);
                        // For InvSysCon
                        insertedItemStack(info, tile);
                        // every item has been inserted.
                        return;
                    }
                }
            }
            if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
                reverseItem(arrivingItem);
            }
        }
        // the item is handled
        return;
    }
    // end of insert into IInventory
    dropItem(arrivingItem);
}
Also used : IInventory(net.minecraft.inventory.IInventory) ITargetSlotInformation(logisticspipes.interfaces.routing.ITargetSlotInformation) SidedInventoryMinecraftAdapter(logisticspipes.utils.SidedInventoryMinecraftAdapter) FluidRoutedPipe(logisticspipes.pipes.basic.fluid.FluidRoutedPipe) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) ModulePositionType(logisticspipes.modules.abstractmodules.LogisticsModule.ModulePositionType) ISidedInventory(net.minecraft.inventory.ISidedInventory) PipeItemsFluidSupplier(logisticspipes.pipes.PipeItemsFluidSupplier) ISpecialInsertion(logisticspipes.interfaces.ISpecialInsertion) ChassiTargetInformation(logisticspipes.pipes.PipeLogisticsChassi.ChassiTargetInformation) PipeLogisticsChassi(logisticspipes.pipes.PipeLogisticsChassi) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack) ISlotUpgradeManager(logisticspipes.interfaces.ISlotUpgradeManager) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)

Aggregations

ISidedInventory (net.minecraft.inventory.ISidedInventory)21 ItemStack (net.minecraft.item.ItemStack)18 IInventory (net.minecraft.inventory.IInventory)13 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)4 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)3 SidedInventoryMinecraftAdapter (logisticspipes.utils.SidedInventoryMinecraftAdapter)3 TileEntity (net.minecraft.tileentity.TileEntity)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ISlotUpgradeManager (logisticspipes.interfaces.ISlotUpgradeManager)2 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 Side (cpw.mods.fml.relauncher.Side)1 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 IMetaTileEntity (gregtech.api.interfaces.metatileentity.IMetaTileEntity)1 IMetaTileEntityItemPipe (gregtech.api.interfaces.metatileentity.IMetaTileEntityItemPipe)1 ICoverable (gregtech.api.interfaces.tileentity.ICoverable)1 IGregTechTileEntity (gregtech.api.interfaces.tileentity.IGregTechTileEntity)1 WeakReference (java.lang.ref.WeakReference)1 Map (java.util.Map)1