Search in sources :

Example 46 with ItemIdentifierStack

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

the class PipeFluidInsertion method enabledUpdateEntity.

@Override
public void enabledUpdateEntity() {
    super.enabledUpdateEntity();
    List<Integer> tempJamList = new ArrayList<>();
    if (!localJamList.isEmpty()) {
        List<Pair<Integer, Integer>> toRemove = new ArrayList<>();
        for (Pair<Integer, Integer> part : localJamList) {
            part.setValue2(part.getValue2() - 1);
            if (part.getValue2() <= 0) {
                toRemove.add(part);
            } else {
                tempJamList.add(part.getValue1());
            }
        }
        if (!toRemove.isEmpty()) {
            localJamList.removeAll(toRemove);
        }
    }
    PipeFluidTransportLogistics transport = (PipeFluidTransportLogistics) this.transport;
    for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        FluidStack stack = transport.sideTanks[dir.ordinal()].getFluid();
        if (stack == null) {
            continue;
        }
        stack = stack.copy();
        if (nextSendMax[dir.ordinal()] > 0 && stack.amount < transport.sideTanks[dir.ordinal()].getCapacity()) {
            nextSendMax[dir.ordinal()]--;
            continue;
        }
        if (nextSendMin[dir.ordinal()] > 0) {
            nextSendMin[dir.ordinal()]--;
            continue;
        }
        Pair<Integer, Integer> result = SimpleServiceLocator.logisticsFluidManager.getBestReply(stack, getRouter(), tempJamList);
        if (result == null || result.getValue1() == null || result.getValue1() == 0 || result.getValue2() == 0) {
            nextSendMax[dir.ordinal()] = 100;
            nextSendMin[dir.ordinal()] = 10;
            continue;
        }
        if (!useEnergy((int) (0.01 * result.getValue2()))) {
            nextSendMax[dir.ordinal()] = 100;
            nextSendMin[dir.ordinal()] = 10;
            continue;
        }
        FluidStack toSend = transport.sideTanks[dir.ordinal()].drain(result.getValue2(), true);
        ItemIdentifierStack liquidContainer = SimpleServiceLocator.logisticsFluidManager.getFluidContainer(toSend);
        IRoutedItem routed = SimpleServiceLocator.routedItemHelper.createNewTravelItem(liquidContainer);
        routed.setDestination(result.getValue1());
        routed.setTransportMode(TransportMode.Passive);
        this.queueRoutedItem(routed, dir);
        nextSendMax[dir.ordinal()] = 100;
        nextSendMin[dir.ordinal()] = 5;
    }
}
Also used : IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) PipeFluidTransportLogistics(logisticspipes.transport.PipeFluidTransportLogistics) FluidStack(net.minecraftforge.fluids.FluidStack) ArrayList(java.util.ArrayList) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) Pair(logisticspipes.utils.tuples.Pair)

Example 47 with ItemIdentifierStack

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

the class PipeItemsInvSysConnector method getExpectedItems.

public Set<ItemIdentifierStack> getExpectedItems() {
    // got to be a TreeMap, because a TreeSet doesn't have the ability to retrieve the key.
    Set<ItemIdentifierStack> list = new TreeSet<>();
    for (Entry<ItemIdentifier, List<ItemRoutingInformation>> entry : itemsOnRoute.entrySet()) {
        if (entry.getValue().isEmpty()) {
            continue;
        }
        ItemIdentifierStack currentStack = new ItemIdentifierStack(entry.getKey(), 0);
        for (ItemRoutingInformation e : entry.getValue()) {
            currentStack.setStackSize(currentStack.getStackSize() + e.getItem().getStackSize());
        }
        list.add(currentStack);
    }
    return list;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) TreeSet(java.util.TreeSet) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

Example 48 with ItemIdentifierStack

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

the class PipeItemsProviderLogistics method updateInv.

private void updateInv(EntityPlayer player) {
    if (localModeWatchers.size() == 0 && player == null) {
        return;
    }
    displayList.clear();
    displayMap.clear();
    getAllItems(displayMap, new ArrayList<>(0));
    displayList.ensureCapacity(displayMap.size());
    displayList.addAll(displayMap.entrySet().stream().map(item -> new ItemIdentifierStack(item.getKey(), item.getValue())).collect(Collectors.toList()));
    if (!oldList.equals(displayList)) {
        oldList.clear();
        oldList.ensureCapacity(displayList.size());
        oldList.addAll(displayList);
        MainProxy.sendToPlayerList(PacketHandler.getPacket(ChestContent.class).setIdentList(displayList).setPosX(getX()).setPosY(getY()).setPosZ(getZ()), localModeWatchers);
    } else if (player != null) {
        MainProxy.sendPacketToPlayer(PacketHandler.getPacket(ChestContent.class).setIdentList(displayList).setPosX(getX()).setPosY(getY()).setPosZ(getZ()), player);
    }
}
Also used : ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ChestContent(logisticspipes.network.packets.hud.ChestContent)

Example 49 with ItemIdentifierStack

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

the class CraftingPipeSign method getRenderData.

@Override
public IPipeSignData getRenderData(CoreRoutedPipe pipe) {
    PipeItemsCraftingLogistics cpipe = (PipeItemsCraftingLogistics) pipe;
    if (cpipe != null) {
        List<ItemIdentifierStack> craftables = cpipe.getCraftedItems();
        if (craftables != null && craftables.size() > 0) {
            ItemIdentifierStack itemIdentifierStack = craftables.get(0);
            ModuleCrafter logisticsMod = cpipe.getLogisticsModule();
            return new CraftingPipeSignData(itemIdentifierStack, logisticsMod.satelliteId);
        } else {
            return new CraftingPipeSignData(null, -1);
        }
    }
    return null;
}
Also used : PipeItemsCraftingLogistics(logisticspipes.pipes.PipeItemsCraftingLogistics) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ModuleCrafter(logisticspipes.modules.ModuleCrafter)

Example 50 with ItemIdentifierStack

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

the class LogisticsCraftingTable method importRecipe.

@Override
public boolean importRecipe(TileEntity tile, ItemIdentifierInventory inventory) {
    if (!(tile instanceof LogisticsCraftingTableTileEntity)) {
        return false;
    }
    LogisticsCraftingTableTileEntity bench = (LogisticsCraftingTableTileEntity) tile;
    ItemIdentifierStack result = bench.resultInv.getIDStackInSlot(0);
    if (result == null) {
        return false;
    }
    inventory.setInventorySlotContents(9, result);
    // Import
    for (int i = 0; i < bench.matrix.getSizeInventory(); i++) {
        if (i >= inventory.getSizeInventory() - 2) {
            break;
        }
        final ItemStack newStack = bench.matrix.getStackInSlot(i) == null ? null : bench.matrix.getStackInSlot(i).copy();
        if (newStack != null && newStack.stackSize > 1) {
            newStack.stackSize = 1;
        }
        inventory.setInventorySlotContents(i, newStack);
    }
    if (!bench.isFuzzy()) {
        inventory.compact_first(9);
    }
    return true;
}
Also used : ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ItemStack(net.minecraft.item.ItemStack) 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