Search in sources :

Example 31 with IInventory

use of net.minecraft.inventory.IInventory 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 32 with IInventory

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

the class TileSortingMachine method triggerSorting.

private void triggerSorting() {
    if (isBufferEmpty()) {
        ForgeDirection dir = getOutputDirection().getOpposite();
        // might need opposite
        TileEntity inputTE = getTileCache(dir);
        if (inputTE instanceof IInventory) {
            IInventory inputInv = (IInventory) inputTE;
            int[] accessibleSlots;
            if (inputInv instanceof ISidedInventory) {
                accessibleSlots = ((ISidedInventory) inputInv).getAccessibleSlotsFromSide(dir.getOpposite().ordinal());
            } else {
                accessibleSlots = new int[inputInv.getSizeInventory()];
                for (int i = 0; i < accessibleSlots.length; i++) accessibleSlots[i] = i;
            }
            for (int slot : accessibleSlots) {
                ItemStack stack = inputInv.getStackInSlot(slot);
                if (stack != null && IOHelper.canExtractItemFromInventory(inputInv, stack, slot, dir.getOpposite().ordinal())) {
                    if (tryProcessItem(stack, false)) {
                        if (stack.stackSize == 0)
                            inputInv.setInventorySlotContents(slot, null);
                        return;
                    }
                }
            }
            if (sortMode == SortMode.ANYSTACK_SEQUENTIAL) {
                for (int i = curColumn; i < inventory.length; i += 8) {
                    ItemStack filterStack = inventory[i];
                    if (filterStack != null) {
                        ItemStack extractedStack = IOHelper.extract(inputTE, dir.getOpposite(), filterStack, true, false);
                        if (extractedStack != null) {
                            addItemToOutputBuffer(extractedStack.copy(), colors[curColumn]);
                            gotoNextNonEmptyColumn();
                            break;
                        }
                    }
                }
            } else if (sortMode == SortMode.ALLSTACK_SEQUENTIAL) {
                if (matchAndProcessColumn(inputInv, accessibleSlots, curColumn)) {
                    gotoNextNonEmptyColumn();
                }
            } else if (sortMode == SortMode.RANDOM_ALLSTACKS) {
                for (int i = 0; i < 8; i++) {
                    if (matchAndProcessColumn(inputInv, accessibleSlots, i)) {
                        break;
                    }
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) ISidedInventory(net.minecraft.inventory.ISidedInventory) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack)

Example 33 with IInventory

use of net.minecraft.inventory.IInventory 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 34 with IInventory

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

the class ModuleSatellite method spaceFor.

private int spaceFor(ItemIdentifier item, boolean includeInTransit) {
    WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(pipe.container);
    //@formatter:off
    int count = worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).map(adjacent -> {
        IInventory inv = (IInventory) adjacent.tileEntity;
        if (inv instanceof net.minecraft.inventory.ISidedInventory) {
            inv = new SidedInventoryMinecraftAdapter((net.minecraft.inventory.ISidedInventory) inv, adjacent.direction.getOpposite(), false);
        }
        IInventoryUtil util = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(inv, adjacent.direction);
        return util.roomForItem(item, 9999);
    }).reduce(Integer::sum).orElse(0);
    if (includeInTransit) {
        count -= pipe.countOnRoute(item);
    }
    return count;
}
Also used : IIconRegister(net.minecraft.client.renderer.texture.IIconRegister) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Side(cpw.mods.fml.relauncher.Side) ConnectionPipeType(logisticspipes.routing.pathfinder.IPipeInformationProvider.ConnectionPipeType) SideOnly(cpw.mods.fml.relauncher.SideOnly) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) Collection(java.util.Collection) FixedPriority(logisticspipes.utils.SinkReply.FixedPriority) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) IIcon(net.minecraft.util.IIcon) SinkReply(logisticspipes.utils.SinkReply) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) SidedInventoryMinecraftAdapter(logisticspipes.utils.SidedInventoryMinecraftAdapter) IWorldProvider(logisticspipes.interfaces.IWorldProvider) IInventory(net.minecraft.inventory.IInventory) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) IInventory(net.minecraft.inventory.IInventory) SidedInventoryMinecraftAdapter(logisticspipes.utils.SidedInventoryMinecraftAdapter) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper)

Example 35 with IInventory

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

the class ModuleCrafterMK3 method tick.

@Override
public void tick() {
    super.tick();
    if (inv.isEmpty()) {
        return;
    }
    if (!_service.isNthTick(6)) {
        return;
    }
    //Add from internal buffer
    List<AdjacentTileEntity> crafters = locateCrafters();
    boolean change = false;
    for (AdjacentTileEntity adjacent : crafters) {
        for (int i = inv.getSizeInventory() - 1; i >= 0; i--) {
            ItemIdentifierStack slot = inv.getIDStackInSlot(i);
            if (slot == null) {
                continue;
            }
            ForgeDirection insertion = adjacent.direction.getOpposite();
            if (getUpgradeManager().hasSneakyUpgrade()) {
                insertion = getUpgradeManager().getSneakyOrientation();
            }
            ItemIdentifierStack toadd = slot.clone();
            toadd.setStackSize(Math.min(toadd.getStackSize(), toadd.getItem().getMaxStackSize()));
            if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING)) {
                toadd.setStackSize(Math.min(toadd.getStackSize(), ((IInventory) adjacent.tileEntity).getInventoryStackLimit()));
                ItemStack added = InventoryHelper.getTransactorFor(adjacent.tileEntity, adjacent.direction.getOpposite()).add(toadd.makeNormalStack(), insertion, true);
                slot.setStackSize(slot.getStackSize() - added.stackSize);
                if (added.stackSize != 0) {
                    change = true;
                }
            } else {
                _service.queueRoutedItem(SimpleServiceLocator.routedItemHelper.createNewTravelItem(toadd), adjacent.direction.getOpposite());
                slot.setStackSize(slot.getStackSize() - toadd.getStackSize());
                change = true;
            }
            if (slot.getStackSize() <= 0) {
                inv.clearInventorySlotContents(i);
            } else {
                inv.setInventorySlotContents(i, slot);
            }
        }
    }
    if (change) {
        inv.markDirty();
        _service.getCacheHolder().trigger(CacheTypes.Inventory);
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ItemStack(net.minecraft.item.ItemStack) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity)

Aggregations

IInventory (net.minecraft.inventory.IInventory)129 ItemStack (net.minecraft.item.ItemStack)80 TileEntity (net.minecraft.tileentity.TileEntity)59 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)21 ArrayList (java.util.ArrayList)18 ISidedInventory (net.minecraft.inventory.ISidedInventory)13 EntityItem (net.minecraft.entity.item.EntityItem)12 EntityPlayer (net.minecraft.entity.player.EntityPlayer)12 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)10 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)9 WorldCoordinatesWrapper (network.rs485.logisticspipes.world.WorldCoordinatesWrapper)9 AMVector3 (am2.api.math.AMVector3)8 List (java.util.List)8 SidedInventoryMinecraftAdapter (logisticspipes.utils.SidedInventoryMinecraftAdapter)8 SinkReply (logisticspipes.utils.SinkReply)8 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)8 LogisticsModule (logisticspipes.modules.abstractmodules.LogisticsModule)7 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)7 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)7 ConnectionPipeType (logisticspipes.routing.pathfinder.IPipeInformationProvider.ConnectionPipeType)7