Search in sources :

Example 21 with ItemIdentifierStack

use of logisticspipes.utils.item.ItemIdentifierStack in project LogisticsPipes by RS485.

the class PipeItemsSatelliteLogistics method throttledUpdateEntity.

@Override
public void throttledUpdateEntity() {
    super.throttledUpdateEntity();
    if (_lostItems.isEmpty()) {
        return;
    }
    final Iterator<ItemIdentifierStack> iterator = _lostItems.iterator();
    while (iterator.hasNext()) {
        ItemIdentifierStack stack = iterator.next();
        int received = RequestTree.requestPartial(stack, (CoreRoutedPipe) container.pipe, null);
        if (received > 0) {
            if (received == stack.getStackSize()) {
                iterator.remove();
            } else {
                stack.setStackSize(stack.getStackSize() - received);
            }
        }
    }
}
Also used : ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

Example 22 with ItemIdentifierStack

use of logisticspipes.utils.item.ItemIdentifierStack in project LogisticsPipes by RS485.

the class PipeLogisticsChassi method registerExtras.

@Override
public void registerExtras(IPromise promise) {
    if (!(promise instanceof LogisticsPromise)) {
        throw new UnsupportedOperationException("Extra has to be an item for a chassis pipe");
    }
    ItemIdentifierStack stack = new ItemIdentifierStack(((LogisticsPromise) promise).item, ((LogisticsPromise) promise).numberOfItems);
    _extras.add(new LogisticsItemOrder(new DictResource(stack, null), null, ResourceType.EXTRA, null));
}
Also used : LogisticsPromise(logisticspipes.routing.LogisticsPromise) DictResource(logisticspipes.request.resources.DictResource) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

Example 23 with ItemIdentifierStack

use of logisticspipes.utils.item.ItemIdentifierStack in project LogisticsPipes by RS485.

the class PipeLogisticsChassi method onAllowedRemoval.

@Override
public void onAllowedRemoval() {
    _moduleInventory.removeListener(this);
    if (MainProxy.isServer(getWorld())) {
        for (int i = 0; i < getChassiSize(); i++) {
            LogisticsModule x = _module.getSubModule(i);
            if (x instanceof ILegacyActiveModule) {
                ILegacyActiveModule y = (ILegacyActiveModule) x;
                y.onBlockRemoval();
            }
        }
        for (int i = 0; i < _moduleInventory.getSizeInventory(); i++) {
            ItemIdentifierStack ms = _moduleInventory.getIDStackInSlot(i);
            if (ms != null) {
                ItemStack s = ms.makeNormalStack();
                ItemModuleInformationManager.saveInfotmation(s, getLogisticsModule().getSubModule(i));
                _moduleInventory.setInventorySlotContents(i, s);
            }
        }
        _moduleInventory.dropContents(getWorld(), getX(), getY(), getZ());
    }
}
Also used : ILegacyActiveModule(logisticspipes.interfaces.ILegacyActiveModule) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ItemStack(net.minecraft.item.ItemStack)

Example 24 with ItemIdentifierStack

use of logisticspipes.utils.item.ItemIdentifierStack in project LogisticsPipes by RS485.

the class PipeFluidProvider method enabledUpdateEntity.

@Override
public void enabledUpdateEntity() {
    super.enabledUpdateEntity();
    if (!getFluidOrderManager().hasOrders(ResourceType.PROVIDER) || !isNthTick(6)) {
        return;
    }
    LogisticsFluidOrder order = getFluidOrderManager().peekAtTopRequest(ResourceType.PROVIDER);
    int amountToSend, attemptedAmount;
    amountToSend = attemptedAmount = Math.min(order.getAmount(), 5000);
    for (Pair<TileEntity, ForgeDirection> pair : getAdjacentTanks(false)) {
        if (amountToSend <= 0) {
            break;
        }
        boolean fallback = true;
        if (SimpleServiceLocator.specialTankHandler.hasHandlerFor(pair.getValue1())) {
            ISpecialTankHandler handler = SimpleServiceLocator.specialTankHandler.getTankHandlerFor(pair.getValue1());
            if (handler instanceof ISpecialTankAccessHandler) {
                fallback = false;
                FluidStack drained = ((ISpecialTankAccessHandler) handler).drainFrom(pair.getValue1(), order.getFluid(), amountToSend, false);
                if (drained != null && drained.amount > 0 && order.getFluid().equals(FluidIdentifier.get(drained))) {
                    drained = ((ISpecialTankAccessHandler) handler).drainFrom(pair.getValue1(), order.getFluid(), amountToSend, true);
                    int amount = drained.amount;
                    amountToSend -= amount;
                    ItemIdentifierStack stack = SimpleServiceLocator.logisticsFluidManager.getFluidContainer(drained);
                    IRoutedItem item = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stack);
                    item.setDestination(order.getRouter().getSimpleID());
                    item.setTransportMode(TransportMode.Active);
                    this.queueRoutedItem(item, pair.getValue2());
                    getFluidOrderManager().sendSuccessfull(amount, false, item);
                    if (amountToSend <= 0) {
                        break;
                    }
                }
            }
        }
        if (fallback) {
            FluidTankInfo[] tanks = ((IFluidHandler) pair.getValue1()).getTankInfo(pair.getValue2().getOpposite());
            if (tanks != null) {
                for (FluidTankInfo tank : tanks) {
                    if (tank == null) {
                        continue;
                    }
                    FluidStack liquid;
                    if ((liquid = tank.fluid) != null && liquid.getFluidID() != 0) {
                        if (order.getFluid().equals(FluidIdentifier.get(liquid))) {
                            int amount = Math.min(liquid.amount, amountToSend);
                            FluidStack drained = ((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), amount, false);
                            if (drained != null && drained.amount > 0 && order.getFluid().equals(FluidIdentifier.get(drained))) {
                                drained = ((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), amount, true);
                                while (drained.amount < amountToSend) {
                                    FluidStack addition = ((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), amountToSend - drained.amount, false);
                                    if (addition != null && addition.amount > 0 && order.getFluid().equals(FluidIdentifier.get(addition))) {
                                        addition = ((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), amountToSend - drained.amount, true);
                                        drained.amount += addition.amount;
                                    } else {
                                        break;
                                    }
                                }
                                amount = drained.amount;
                                amountToSend -= amount;
                                ItemIdentifierStack stack = SimpleServiceLocator.logisticsFluidManager.getFluidContainer(drained);
                                IRoutedItem item = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stack);
                                item.setDestination(order.getRouter().getSimpleID());
                                item.setTransportMode(TransportMode.Active);
                                this.queueRoutedItem(item, pair.getValue2());
                                getFluidOrderManager().sendSuccessfull(amount, false, item);
                                if (amountToSend <= 0) {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (amountToSend >= attemptedAmount) {
        getFluidOrderManager().sendFailed();
    }
}
Also used : ISpecialTankHandler(logisticspipes.interfaces.ISpecialTankHandler) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) FluidStack(net.minecraftforge.fluids.FluidStack) LogisticsFluidOrder(logisticspipes.routing.order.LogisticsFluidOrder) ISpecialTankAccessHandler(logisticspipes.interfaces.ISpecialTankAccessHandler) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) TileEntity(net.minecraft.tileentity.TileEntity) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

Example 25 with ItemIdentifierStack

use of logisticspipes.utils.item.ItemIdentifierStack in project LogisticsPipes by RS485.

the class LogisticsCraftingTable method importFuzzyFlags.

@Override
public void importFuzzyFlags(TileEntity tile, ItemIdentifierInventory inventory, DictResource[] flags, DictResource output) {
    if (!(tile instanceof LogisticsCraftingTableTileEntity)) {
        return;
    }
    LogisticsCraftingTableTileEntity bench = (LogisticsCraftingTableTileEntity) tile;
    if (!bench.isFuzzy()) {
        return;
    }
    for (int i = 0; i < bench.fuzzyFlags.length; i++) {
        if (i >= flags.length) {
            break;
        }
        flags[i].loadFromBitSet(bench.fuzzyFlags[i].getBitSet());
    }
    output.loadFromBitSet(bench.outputFuzzyFlags.getBitSet());
    for (int i = 0; i < 9; i++) {
        final ItemIdentifierStack stackInSlot = inventory.getIDStackInSlot(i);
        if (stackInSlot == null) {
            continue;
        }
        final ItemIdentifier itemInSlot = stackInSlot.getItem();
        for (int j = i + 1; j < 9; j++) {
            final ItemIdentifierStack stackInOtherSlot = inventory.getIDStackInSlot(j);
            if (stackInOtherSlot == null) {
                continue;
            }
            if (itemInSlot.equals(stackInOtherSlot.getItem()) && flags[i].getBitSet().equals(flags[j].getBitSet())) {
                stackInSlot.setStackSize(stackInSlot.getStackSize() + stackInOtherSlot.getStackSize());
                inventory.clearInventorySlotContents(j);
                // clear
                flags[j].loadFromBitSet(new BitSet());
            }
        }
        inventory.setInventorySlotContents(i, stackInSlot);
    }
    for (int i = 0; i < 9; i++) {
        if (inventory.getStackInSlot(i) != null) {
            continue;
        }
        for (int j = i + 1; j < 9; j++) {
            if (inventory.getStackInSlot(j) == null) {
                continue;
            }
            inventory.setInventorySlotContents(i, inventory.getStackInSlot(j));
            flags[i].loadFromBitSet(flags[j].getBitSet());
            inventory.clearInventorySlotContents(j);
            // clear
            flags[j].loadFromBitSet(new BitSet());
            break;
        }
    }
    return;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) BitSet(java.util.BitSet) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) LogisticsCraftingTableTileEntity(logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity)

Aggregations

ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)58 ItemStack (net.minecraft.item.ItemStack)21 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)18 ArrayList (java.util.ArrayList)9 Pair (logisticspipes.utils.tuples.Pair)8 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)7 LinkedList (java.util.LinkedList)5 NBTTagList (net.minecraft.nbt.NBTTagList)5 List (java.util.List)4 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)4 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)4 DictResource (logisticspipes.request.resources.DictResource)4 IResource (logisticspipes.request.resources.IResource)4 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)4 HashMap (java.util.HashMap)3 TreeSet (java.util.TreeSet)3 LogisticsCraftingTableTileEntity (logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity)3 IAdditionalTargetInformation (logisticspipes.interfaces.routing.IAdditionalTargetInformation)3 ItemResource (logisticspipes.request.resources.ItemResource)3 IRouter (logisticspipes.routing.IRouter)3