Search in sources :

Example 1 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project BluePower by Qmunity.

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 2 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project BluePower by Qmunity.

the class IOHelper method extract.

/**
     * Retrieves an item from the specified inventory. This item can be specified.
     *
     * @param tile
     * @param direction
     * @param requestedStack
     * @param useItemCount
     *            if true, it'll only retrieve the stack of the exact item count given. it'll look in multiple slots of the inventory. if false, the
     *            first matching stack, ignoring item count, will be returned.
     * @param simulate
     * @param fuzzySetting
     *            ,
     * @return
     */
public static ItemStack extract(TileEntity tile, ForgeDirection direction, ItemStack requestedStack, boolean useItemCount, boolean simulate, int fuzzySetting) {
    if (requestedStack == null)
        return requestedStack;
    IInventory inv = getInventoryForTE(tile);
    if (inv != null) {
        int[] accessibleSlots;
        if (inv instanceof ISidedInventory) {
            accessibleSlots = ((ISidedInventory) inv).getAccessibleSlotsFromSide(direction.ordinal());
        } else {
            accessibleSlots = new int[inv.getSizeInventory()];
            for (int i = 0; i < accessibleSlots.length; i++) accessibleSlots[i] = i;
        }
        int itemsFound = 0;
        for (int slot : accessibleSlots) {
            ItemStack stack = inv.getStackInSlot(slot);
            if (stack != null && ItemStackHelper.areStacksEqual(stack, requestedStack, fuzzySetting) && IOHelper.canExtractItemFromInventory(inv, requestedStack, slot, direction.ordinal())) {
                if (!useItemCount) {
                    if (!simulate) {
                        inv.setInventorySlotContents(slot, null);
                    }
                    return stack;
                }
                itemsFound += stack.stackSize;
            }
        }
        if (itemsFound >= requestedStack.stackSize) {
            ItemStack exportedStack = null;
            int itemsNeeded = requestedStack.stackSize;
            for (int slot : accessibleSlots) {
                ItemStack stack = inv.getStackInSlot(slot);
                if (stack != null && ItemStackHelper.areStacksEqual(stack, requestedStack, fuzzySetting) && IOHelper.canExtractItemFromInventory(inv, requestedStack, slot, direction.ordinal())) {
                    int itemsSubstracted = Math.min(itemsNeeded, stack.stackSize);
                    if (itemsSubstracted > 0)
                        exportedStack = stack;
                    itemsNeeded -= itemsSubstracted;
                    if (!simulate) {
                        stack.stackSize -= itemsSubstracted;
                        if (stack.stackSize == 0)
                            inv.setInventorySlotContents(slot, null);
                        tile.markDirty();
                    }
                }
            }
            exportedStack = exportedStack.copy();
            exportedStack.stackSize = requestedStack.stackSize;
            return exportedStack;
        }
    }
    return null;
}
Also used : IInventory(net.minecraft.inventory.IInventory) ISidedInventory(net.minecraft.inventory.ISidedInventory) ItemStack(net.minecraft.item.ItemStack)

Example 3 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project BluePower by Qmunity.

the class IOHelper method extractOneItem.

public static ItemStack extractOneItem(TileEntity tile, ForgeDirection dir) {
    IInventory inv = getInventoryForTE(tile);
    if (inv != null) {
        int[] accessibleSlots;
        if (inv instanceof ISidedInventory) {
            accessibleSlots = ((ISidedInventory) inv).getAccessibleSlotsFromSide(dir.ordinal());
        } else {
            accessibleSlots = new int[inv.getSizeInventory()];
            for (int i = 0; i < accessibleSlots.length; i++) accessibleSlots[i] = i;
        }
        for (int slot : accessibleSlots) {
            ItemStack stack = inv.getStackInSlot(slot);
            ItemStack retrievingStack = stack == null ? null : stack.copy().splitStack(1);
            if (stack != null && IOHelper.canExtractItemFromInventory(inv, retrievingStack, slot, dir.ordinal())) {
                ItemStack ret = stack.splitStack(1);
                if (stack.stackSize == 0)
                    inv.setInventorySlotContents(slot, null);
                tile.markDirty();
                return ret;
            }
        }
    }
    return null;
}
Also used : IInventory(net.minecraft.inventory.IInventory) ISidedInventory(net.minecraft.inventory.ISidedInventory) ItemStack(net.minecraft.item.ItemStack)

Example 4 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project BluePower by Qmunity.

the class TileRegulator method updateEntity.

@Override
public void updateEntity() {
    super.updateEntity();
    if (!worldObj.isRemote && isBufferEmpty()) {
        boolean ratiosMatch = true;
        for (int i = 0; i < 9; i++) {
            if (inventory[i] != null) {
                int inputFilterItems = getItemsInSection(inventory[i], EnumSection.INPUT_FILTER);
                int bufferItems = getItemsInSection(inventory[i], EnumSection.BUFFER);
                if (bufferItems < inputFilterItems) {
                    ratiosMatch = false;
                    break;
                }
            }
        }
        if (ratiosMatch && !isEjecting())
            checkIndividualOutputFilterAndEject();
        if (mode == 1 && !isEjecting()) {
            // supply mode
            IInventory inv = IOHelper.getInventoryForTE(getTileCache(getOutputDirection()));
            if (inv != null) {
                int[] accessibleSlots;
                if (inv instanceof ISidedInventory) {
                    accessibleSlots = ((ISidedInventory) inv).getAccessibleSlotsFromSide(getFacingDirection().ordinal());
                } else {
                    accessibleSlots = new int[inv.getSizeInventory()];
                    for (int i = 0; i < accessibleSlots.length; i++) accessibleSlots[i] = i;
                }
                for (int i = 18; i < 27; i++) {
                    if (inventory[i] != null) {
                        int outputFilterItems = getItemsInSection(inventory[i], EnumSection.OUTPUT_FILTER);
                        int supplyingInvCount = 0;
                        for (int slot : accessibleSlots) {
                            ItemStack stackInSlot = inv.getStackInSlot(slot);
                            if (stackInSlot != null && ItemStackHelper.areStacksEqual(stackInSlot, inventory[i], fuzzySetting) && IOHelper.canInsertItemToInventory(inv, inventory[i], slot, getFacingDirection().ordinal())) {
                                supplyingInvCount += stackInSlot.stackSize;
                            }
                        }
                        if (supplyingInvCount < outputFilterItems) {
                            ItemStack requestedStack = inventory[i].copy();
                            requestedStack.stackSize = outputFilterItems - supplyingInvCount;
                            // try
                            ItemStack bufferItems = IOHelper.extract(this, ForgeDirection.UNKNOWN, requestedStack, true, false, fuzzySetting);
                            // the buffer.
                            if (bufferItems != null) {
                                // insert into
                                ItemStack remainder = IOHelper.insert(inv, bufferItems, getFacingDirection().ordinal(), false);
                                // supplying inv.
                                if (remainder != null) {
                                    // when not every item can be supplied, return
                                    IOHelper.insert(this, remainder, ForgeDirection.UNKNOWN, false);
                                // those to the buffer.
                                }
                            }
                        }
                    }
                }
            }
        }
        boolean shouldEmitRedstone = isSatisfied() || animationTicker >= 0;
        if (isEjecting() != shouldEmitRedstone) {
            setOutputtingRedstone(shouldEmitRedstone);
            sendUpdatePacket();
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ISidedInventory(net.minecraft.inventory.ISidedInventory) ItemStack(net.minecraft.item.ItemStack)

Example 5 with ISidedInventory

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

the class ModuleCrafter method spaceFor.

protected int spaceFor(ItemIdentifier item, boolean includeInTransit) {
    Pair<String, ItemIdentifier> key = new Pair<>("spaceFor", item);
    Object cache = _service.getCacheHolder().getCacheFor(CacheTypes.Inventory, key);
    if (cache != null) {
        int count = (Integer) cache;
        if (includeInTransit) {
            count -= _service.countOnRoute(item);
        }
        return count;
    }
    WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(getWorld(), _service.getX(), _service.getY(), _service.getZ());
    //@formatter:off
    int count = worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).map(adjacent -> new Pair<>((IInventory) adjacent.tileEntity, adjacent.direction)).map(invDirPair -> {
        if (invDirPair.getValue1() instanceof ISidedInventory) {
            invDirPair.setValue1(new SidedInventoryMinecraftAdapter((ISidedInventory) invDirPair.getValue1(), invDirPair.getValue2().getOpposite(), false));
        }
        if (getUpgradeManager().hasSneakyUpgrade()) {
            invDirPair.setValue2(getUpgradeManager().getSneakyOrientation());
        }
        IInventoryUtil inv = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(invDirPair.getValue1(), invDirPair.getValue2());
        return inv.roomForItem(item, 9999);
    }).reduce(Integer::sum).orElse(0);
    _service.getCacheHolder().setCache(CacheTypes.Inventory, key, count);
    if (includeInTransit) {
        count -= _service.countOnRoute(item);
    }
    return count;
}
Also used : IInventory(net.minecraft.inventory.IInventory) FluidCraftingPipeAdvancedSatellitePrevPacket(logisticspipes.network.packets.pipe.FluidCraftingPipeAdvancedSatellitePrevPacket) CraftingPipeNextAdvancedSatellitePacket(logisticspipes.network.packets.block.CraftingPipeNextAdvancedSatellitePacket) CPipeSatelliteImportBack(logisticspipes.network.packets.cpipe.CPipeSatelliteImportBack) CraftingAdvancedSatelliteId(logisticspipes.network.packets.cpipe.CraftingAdvancedSatelliteId) Constants(net.minecraftforge.common.util.Constants) MainProxy(logisticspipes.proxy.MainProxy) FluidCraftingAmount(logisticspipes.network.packets.pipe.FluidCraftingAmount) SinkReply(logisticspipes.utils.SinkReply) Block(net.minecraft.block.Block) HUDStopModuleWatchingPacket(logisticspipes.network.packets.hud.HUDStopModuleWatchingPacket) ItemCraftingTemplate(logisticspipes.request.ItemCraftingTemplate) Map(java.util.Map) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) CPipeSatelliteId(logisticspipes.network.packets.cpipe.CPipeSatelliteId) FluidCraftingAdvancedSatelliteId(logisticspipes.network.packets.pipe.FluidCraftingAdvancedSatelliteId) NewGuiHandler(logisticspipes.network.NewGuiHandler) SideOnly(cpw.mods.fml.relauncher.SideOnly) CPipeNextSatellite(logisticspipes.network.packets.cpipe.CPipeNextSatellite) FluidCraftingPipeAdvancedSatelliteNextPacket(logisticspipes.network.packets.pipe.FluidCraftingPipeAdvancedSatelliteNextPacket) LogisticsExtraPromise(logisticspipes.routing.LogisticsExtraPromise) LogisticsManager(logisticspipes.logistics.LogisticsManager) LogisticsGuiModule(logisticspipes.modules.abstractmodules.LogisticsGuiModule) Set(java.util.Set) PacketHandler(logisticspipes.network.PacketHandler) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ExitRoute(logisticspipes.routing.ExitRoute) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) IFilter(logisticspipes.interfaces.routing.IFilter) LogisticsCraftingTableTileEntity(logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity) BufferMode(logisticspipes.utils.SinkReply.BufferMode) ICraftingRecipeProvider(logisticspipes.proxy.interfaces.ICraftingRecipeProvider) CraftingModuleInHand(logisticspipes.network.guis.module.inhand.CraftingModuleInHand) CraftingPipeOpenConnectedGuiPacket(logisticspipes.network.packets.cpipe.CraftingPipeOpenConnectedGuiPacket) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) CraftingModuleSlot(logisticspipes.network.guis.module.inpipe.CraftingModuleSlot) IWorldProvider(logisticspipes.interfaces.IWorldProvider) LogisticsDictPromise(logisticspipes.routing.LogisticsDictPromise) World(net.minecraft.world.World) CraftingPipePrevAdvancedSatellitePacket(logisticspipes.network.packets.block.CraftingPipePrevAdvancedSatellitePacket) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) CraftingPipePriorityDownPacket(logisticspipes.network.packets.pipe.CraftingPipePriorityDownPacket) LogisticsExtraDictPromise(logisticspipes.routing.LogisticsExtraDictPromise) DelayedGeneric(logisticspipes.utils.DelayedGeneric) ItemSendMode(logisticspipes.pipes.basic.CoreRoutedPipe.ItemSendMode) CPipeSatelliteImport(logisticspipes.network.packets.cpipe.CPipeSatelliteImport) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity) IIcon(net.minecraft.util.IIcon) HUDStartModuleWatchingPacket(logisticspipes.network.packets.hud.HUDStartModuleWatchingPacket) IResource(logisticspipes.request.resources.IResource) ChassiTargetInformation(logisticspipes.pipes.PipeLogisticsChassi.ChassiTargetInformation) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) TileEntity(net.minecraft.tileentity.TileEntity) ItemBlock(net.minecraft.item.ItemBlock) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) ModuleInHandGuiProvider(logisticspipes.network.abstractguis.ModuleInHandGuiProvider) PipeItemsSatelliteLogistics(logisticspipes.pipes.PipeItemsSatelliteLogistics) IRouter(logisticspipes.routing.IRouter) IRequestFluid(logisticspipes.interfaces.routing.IRequestFluid) ItemUpgrade(logisticspipes.items.ItemUpgrade) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) ICraftingTemplate(logisticspipes.request.ICraftingTemplate) Particles(logisticspipes.pipefxhandlers.Particles) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) DictCraftingTemplate(logisticspipes.request.DictCraftingTemplate) NBTTagList(net.minecraft.nbt.NBTTagList) FluidIdentifier(logisticspipes.utils.FluidIdentifier) SidedInventoryMinecraftAdapter(logisticspipes.utils.SidedInventoryMinecraftAdapter) ICraftItems(logisticspipes.interfaces.routing.ICraftItems) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation) IIconRegister(net.minecraft.client.renderer.texture.IIconRegister) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ModernPacket(logisticspipes.network.abstractpackets.ModernPacket) Side(cpw.mods.fml.relauncher.Side) ConnectionPipeType(logisticspipes.routing.pathfinder.IPipeInformationProvider.ConnectionPipeType) FluidResource(logisticspipes.request.resources.FluidResource) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) IFuzzyRecipeProvider(logisticspipes.proxy.interfaces.IFuzzyRecipeProvider) RequestTreeNode(logisticspipes.request.RequestTreeNode) DictResource(logisticspipes.request.resources.DictResource) Collectors(java.util.stream.Collectors) TransportMode(logisticspipes.logisticspipes.IRoutedItem.TransportMode) IItemSpaceControl(logisticspipes.interfaces.routing.IItemSpaceControl) List(java.util.List) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) CacheTypes(logisticspipes.utils.CacheHolder.CacheTypes) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Pair(logisticspipes.utils.tuples.Pair) IHUDModuleHandler(logisticspipes.interfaces.IHUDModuleHandler) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) IPromise(logisticspipes.request.IPromise) PipeItemsCraftingLogistics(logisticspipes.pipes.PipeItemsCraftingLogistics) ItemResource(logisticspipes.request.resources.ItemResource) Getter(lombok.Getter) ModuleCoordinatesGuiProvider(logisticspipes.network.abstractguis.ModuleCoordinatesGuiProvider) CPipePrevSatellite(logisticspipes.network.packets.cpipe.CPipePrevSatellite) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) IReqCraftingTemplate(logisticspipes.request.IReqCraftingTemplate) ResourceType(logisticspipes.routing.order.IOrderInfoProvider.ResourceType) CoordinatesPacket(logisticspipes.network.abstractpackets.CoordinatesPacket) IRequestItems(logisticspipes.interfaces.routing.IRequestItems) CraftingPipePriorityUpPacket(logisticspipes.network.packets.pipe.CraftingPipePriorityUpPacket) IModuleWatchReciver(logisticspipes.interfaces.IModuleWatchReciver) ISlotUpgradeManager(logisticspipes.interfaces.ISlotUpgradeManager) DelayQueue(java.util.concurrent.DelayQueue) WeakReference(java.lang.ref.WeakReference) PipeFluidSatellite(logisticspipes.pipes.PipeFluidSatellite) CraftingPriority(logisticspipes.network.packets.pipe.CraftingPriority) IHUDModuleRenderer(logisticspipes.interfaces.IHUDModuleRenderer) FixedPriority(logisticspipes.utils.SinkReply.FixedPriority) CraftingPipeUpdatePacket(logisticspipes.network.packets.pipe.CraftingPipeUpdatePacket) LogisticsPromise(logisticspipes.routing.LogisticsPromise) RequestTree(logisticspipes.request.RequestTree) ISidedInventory(net.minecraft.inventory.ISidedInventory) IInventory(net.minecraft.inventory.IInventory) SidedInventoryMinecraftAdapter(logisticspipes.utils.SidedInventoryMinecraftAdapter) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) ISidedInventory(net.minecraft.inventory.ISidedInventory) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) Pair(logisticspipes.utils.tuples.Pair)

Aggregations

ISidedInventory (net.minecraft.inventory.ISidedInventory)45 ItemStack (net.minecraft.item.ItemStack)30 IInventory (net.minecraft.inventory.IInventory)21 IItemHandler (net.minecraftforge.items.IItemHandler)7 TileEntity (net.minecraft.tileentity.TileEntity)6 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)4 SidedInvWrapper (net.minecraftforge.items.wrapper.SidedInvWrapper)3 Pos (com.builtbroken.mc.lib.transform.vector.Pos)2 ArrayList (java.util.ArrayList)2 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)2 ISlotUpgradeManager (logisticspipes.interfaces.ISlotUpgradeManager)2 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)2 TileEntityChest (net.minecraft.tileentity.TileEntityChest)2 EnumFacing (net.minecraft.util.EnumFacing)2 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)2 EntityTemporalItem (arekkuusu.solar.common.entity.EntityTemporalItem)1 IItemTransactor (buildcraft.api.inventory.IItemTransactor)1 Pair (com.builtbroken.jlib.type.Pair)1 IExtendedStorage (com.builtbroken.mc.api.tile.IExtendedStorage)1 Side (cpw.mods.fml.relauncher.Side)1