Search in sources :

Example 6 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)

Example 7 with ISidedInventory

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

the class SlotFinderNumberPacket method processPacket.

@Override
@SuppressWarnings("unchecked")
public void processPacket(EntityPlayer player) {
    IInventory inv = this.getTile(player.worldObj, IInventory.class);
    if (inv instanceof ISidedInventory) {
        inv = new SidedInventoryMinecraftAdapter((ISidedInventory) inv, ForgeDirection.UNKNOWN, false);
    }
    IInventoryUtil util = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(inv);
    Slot result = null;
    if (((List<Slot>) player.openContainer.inventorySlots).get(inventorySlot).slotNumber == inventorySlot) {
        result = ((List<Slot>) player.openContainer.inventorySlots).get(inventorySlot);
    }
    if (result == null) {
        for (Slot slotObject : (List<Slot>) player.openContainer.inventorySlots) {
            if (slotObject.slotNumber == inventorySlot) {
                result = slotObject;
                break;
            }
        }
    }
    if (result == null) {
        player.addChatComponentMessage(new ChatComponentTranslation("lp.chat.slotnotfound"));
    }
    int resultIndex = -1;
    if (resultIndex == -1) {
        ItemStack content = result.getStack();
        if (content != null) {
            for (int i = 0; i < util.getSizeInventory(); i++) {
                if (content == util.getStackInSlot(i)) {
                    resultIndex = i;
                    break;
                }
            }
        } else {
            ItemStack dummyStack = new ItemStack(Blocks.stone, 0, 0);
            NBTTagCompound nbt = new NBTTagCompound();
            //Make it unique
            nbt.setBoolean("LPStackFinderBoolean", true);
            dummyStack.setTagCompound(nbt);
            result.putStack(dummyStack);
            for (int i = 0; i < util.getSizeInventory(); i++) {
                if (dummyStack == util.getStackInSlot(i)) {
                    resultIndex = i;
                    break;
                }
            }
            if (resultIndex == -1) {
                for (int i = 0; i < util.getSizeInventory(); i++) {
                    ItemStack stack = util.getStackInSlot(i);
                    if (stack == null) {
                        continue;
                    }
                    if (ItemIdentifier.get(stack).equals(ItemIdentifier.get(dummyStack)) && stack.stackSize == dummyStack.stackSize) {
                        resultIndex = i;
                        break;
                    }
                }
            }
            result.putStack(null);
        }
    }
    if (resultIndex == -1) {
        player.addChatComponentMessage(new ChatComponentTranslation("lp.chat.slotnotfound"));
    } else {
        //Copy pipe to coordinates to use the getPipe method
        setPosX(getPipePosX());
        setPosY(getPipePosY());
        setPosZ(getPipePosZ());
        ModuleActiveSupplier module = this.getLogisticsModule(player, ModuleActiveSupplier.class);
        if (module != null) {
            module.slotArray[slot] = resultIndex;
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ISidedInventory(net.minecraft.inventory.ISidedInventory) ModuleActiveSupplier(logisticspipes.modules.ModuleActiveSupplier) SidedInventoryMinecraftAdapter(logisticspipes.utils.SidedInventoryMinecraftAdapter) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Slot(net.minecraft.inventory.Slot) List(java.util.List) ItemStack(net.minecraft.item.ItemStack)

Example 8 with ISidedInventory

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

the class DroneEntityAIInventoryExport method export.

private boolean export(ChunkPosition pos, boolean simulate) {
    IInventory inv = IOHelper.getInventoryForTE(drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
    if (inv != null) {
        for (int i = 0; i < drone.getInventory().getSizeInventory(); i++) {
            ItemStack droneStack = drone.getInventory().getStackInSlot(i);
            if (droneStack != null) {
                if (widget.isItemValidForFilters(droneStack)) {
                    for (int side = 0; side < 6; side++) {
                        droneStack = drone.getInventory().getStackInSlot(i);
                        if (((ISidedWidget) widget).getSides()[side] && droneStack != null) {
                            droneStack = droneStack.copy();
                            int oldCount = droneStack.stackSize;
                            if (((ICountWidget) widget).useCount())
                                droneStack.stackSize = Math.min(droneStack.stackSize, getRemainingCount());
                            ItemStack remainder = IOHelper.insert(inv, droneStack.copy(), side, simulate);
                            int stackSize = drone.getInventory().getStackInSlot(i).stackSize - (remainder == null ? droneStack.stackSize : droneStack.stackSize - remainder.stackSize);
                            droneStack.stackSize = stackSize;
                            int exportedItems = oldCount - stackSize;
                            if (!simulate) {
                                drone.getInventory().setInventorySlotContents(i, stackSize > 0 ? droneStack : null);
                                decreaseCount(exportedItems);
                            }
                            if (simulate && exportedItems > 0)
                                return true;
                            //doing it for every side for no side sensitive inventories would be a waste.
                            if (!(inv instanceof ISidedInventory))
                                break;
                        }
                    }
                    if (droneStack == null && !simulate)
                        drone.addAir(null, -PneumaticValues.DRONE_USAGE_INV);
                    else
                        drone.addDebugEntry("gui.progWidget.inventoryExport.debug.filledToMax", pos);
                } else {
                    drone.addDebugEntry("gui.progWidget.inventoryExport.debug.stackdoesntPassFilter", pos);
                }
            }
        }
    } else {
        drone.addDebugEntry("gui.progWidget.inventory.debug.noInventory", pos);
    }
    return false;
}
Also used : IInventory(net.minecraft.inventory.IInventory) ISidedInventory(net.minecraft.inventory.ISidedInventory) ISidedWidget(pneumaticCraft.common.progwidgets.ISidedWidget) ICountWidget(pneumaticCraft.common.progwidgets.ICountWidget) ItemStack(net.minecraft.item.ItemStack)

Example 9 with ISidedInventory

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

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 && stack.stackSize > 0 && stack.isItemEqual(requestedStack) && IOHelper.canExtractItemFromInventory(inv, stack, 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 && stack.isItemEqual(requestedStack) && IOHelper.canExtractItemFromInventory(inv, stack, 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 10 with ISidedInventory

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

the class IOHelper method extractOneItem.

public static ItemStack extractOneItem(TileEntity tile, ForgeDirection dir, boolean simulate) {
    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);
            if (stack != null && stack.stackSize > 0 && IOHelper.canExtractItemFromInventory(inv, stack, slot, dir.ordinal())) {
                if (simulate) {
                    ItemStack ret = stack.copy();
                    ret.stackSize = 1;
                    return ret;
                }
                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)

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