Search in sources :

Example 11 with ItemRoutingInformation

use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.

the class LPItemDuct method transferItem.

@Override
public void transferItem(TravelingItem item) {
    ItemRoutingInformation info = (ItemRoutingInformation) item.lpRoutingInformation;
    if (info != null) {
        info.setItem(ItemIdentifierStack.getFromStack(item.stack));
        LPTravelingItemServer lpItem = new LPTravelingItemServer(info);
        lpItem.setSpeed(info._transportMode == TransportMode.Active ? 0.3F : 0.2F);
        pipe.pipe.transport.injectItem(lpItem, ForgeDirection.getOrientation(item.direction));
    } else if (item.stack != null) {
        int consumed = pipe.injectItem(item.stack, true, dir);
        item.stack.stackSize -= consumed;
        if (item.stack.stackSize > 0) {
            pipe.pipe.transport._itemBuffer.add(new Triplet<>(ItemIdentifierStack.getFromStack(item.stack), new Pair<>(20 * 2, 0), null));
        }
    }
}
Also used : ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) Triplet(logisticspipes.utils.tuples.Triplet) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)

Example 12 with ItemRoutingInformation

use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.

the class PipeTransportLogistics method injectItem.

/**
	 * Accept items from BC
	 */
@ModDependentMethod(modId = "BuildCraft|Transport")
public void injectItem(TravelingItem item, ForgeDirection inputOrientation) {
    if (MainProxy.isServer(getWorld())) {
        if (item instanceof LPRoutedBCTravelingItem) {
            ItemRoutingInformation info = ((LPRoutedBCTravelingItem) item).getRoutingInformation();
            info.setItem(ItemIdentifierStack.getFromStack(item.getItemStack()));
            LPTravelingItemServer lpItem = new LPTravelingItemServer(info);
            lpItem.setSpeed(item.getSpeed());
            this.injectItem(lpItem, inputOrientation);
        } else {
            ItemRoutingInformation info = LPRoutedBCTravelingItem.restoreFromExtraNBTData(item);
            if (info != null) {
                info.setItem(ItemIdentifierStack.getFromStack(item.getItemStack()));
                LPTravelingItemServer lpItem = new LPTravelingItemServer(info);
                lpItem.setSpeed(item.getSpeed());
                this.injectItem(lpItem, inputOrientation);
            } else {
                LPTravelingItemServer lpItem = SimpleServiceLocator.routedItemHelper.createNewTravelItem(item.getItemStack());
                lpItem.setSpeed(item.getSpeed());
                this.injectItem(lpItem, inputOrientation);
            }
        }
    }
}
Also used : ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) LPRoutedBCTravelingItem(logisticspipes.proxy.buildcraft.LPRoutedBCTravelingItem) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer) ModDependentMethod(logisticspipes.asm.ModDependentMethod)

Example 13 with ItemRoutingInformation

use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.

the class PipeTransportLogistics method handleTileReachedServer_internal.

protected final void handleTileReachedServer_internal(LPTravelingItemServer arrivingItem, TileEntity tile, ForgeDirection dir) {
    if (isRouted && getPipe().container.tilePart.getBCPipePluggable(dir) != null && getPipe().container.tilePart.getBCPipePluggable(dir).isAcceptingItems(arrivingItem)) {
        LPTravelingItemServer remainingItem = getPipe().container.tilePart.getBCPipePluggable(dir).handleItem(arrivingItem);
        if (remainingItem != null) {
            getRoutedPipe().getRouter().update(true, getRoutedPipe());
            this.injectItem(remainingItem, dir);
        }
        return;
    }
    if (getPipe() instanceof PipeItemsFluidSupplier) {
        ((PipeItemsFluidSupplier) getPipe()).endReached(arrivingItem, tile);
        if (arrivingItem.getItemIdentifierStack().getStackSize() <= 0) {
            return;
        }
    }
    markChunkModified(tile);
    if (MainProxy.isServer(getWorld()) && arrivingItem.getInfo() != null && arrivingItem.getArrived() && isRouted) {
        getRoutedPipe().notifyOfItemArival(arrivingItem.getInfo());
    }
    if (getPipe() instanceof FluidRoutedPipe) {
        if (((FluidRoutedPipe) getPipe()).endReached(arrivingItem, tile)) {
            return;
        }
    }
    boolean isSpecialConnectionInformationTransition = false;
    if (MainProxy.isServer(getWorld())) {
        if (SimpleServiceLocator.specialtileconnection.needsInformationTransition(tile)) {
            isSpecialConnectionInformationTransition = true;
            SimpleServiceLocator.specialtileconnection.transmit(tile, arrivingItem);
        }
    }
    if (SimpleServiceLocator.pipeInformationManager.isItemPipe(tile)) {
        if (passToNextPipe(arrivingItem, tile)) {
            return;
        }
    } else if (tile instanceof IInventory && isRouted) {
        getRoutedPipe().getCacheHolder().trigger(CacheTypes.Inventory);
        // items.scheduleRemoval(arrivingItem);
        if (MainProxy.isServer(getWorld())) {
            // destroy the item on exit if it isn't exitable
            if (!isSpecialConnectionInformationTransition && !isItemExitable(arrivingItem.getItemIdentifierStack())) {
                return;
            }
            // last chance for chassi to back out
            if (arrivingItem != null) {
                if (arrivingItem.getTransportMode() != TransportMode.Active && !getRoutedPipe().getTransportLayer().stillWantItem(arrivingItem)) {
                    reverseItem(arrivingItem);
                    return;
                }
            }
            ISlotUpgradeManager slotManager;
            {
                ModulePositionType slot = null;
                int positionInt = -1;
                if (arrivingItem.getInfo().targetInfo instanceof ChassiTargetInformation) {
                    positionInt = ((ChassiTargetInformation) arrivingItem.getInfo().targetInfo).getModuleSlot();
                    slot = ModulePositionType.SLOT;
                } else if (LPConstants.DEBUG && container.pipe instanceof PipeLogisticsChassi) {
                    System.out.println(arrivingItem);
                    new RuntimeException("[ItemInsertion] Information weren't ment for a chassi pipe").printStackTrace();
                }
                slotManager = getRoutedPipe().getUpgradeManager(slot, positionInt);
            }
            boolean tookSome = false;
            if (arrivingItem.getAdditionalTargetInformation() instanceof ITargetSlotInformation) {
                ITargetSlotInformation information = (ITargetSlotInformation) arrivingItem.getAdditionalTargetInformation();
                IInventory inv = (IInventory) tile;
                if (inv instanceof ISidedInventory) {
                    inv = new SidedInventoryMinecraftAdapter((ISidedInventory) inv, ForgeDirection.UNKNOWN, false);
                }
                IInventoryUtil util = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(inv);
                if (util instanceof ISpecialInsertion) {
                    int slot = information.getTargetSlot();
                    int amount = information.getAmount();
                    if (util.getSizeInventory() > slot) {
                        ItemStack content = util.getStackInSlot(slot);
                        ItemStack toAdd = arrivingItem.getItemIdentifierStack().makeNormalStack();
                        toAdd.stackSize = Math.min(toAdd.stackSize, Math.max(0, amount - (content != null ? content.stackSize : 0)));
                        if (toAdd.stackSize > 0) {
                            if (util.getSizeInventory() > slot) {
                                int added = ((ISpecialInsertion) util).addToSlot(toAdd, slot);
                                arrivingItem.getItemIdentifierStack().lowerStackSize(added);
                                if (added > 0) {
                                    tookSome = true;
                                }
                            }
                        }
                    }
                    if (information.isLimited()) {
                        if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
                            reverseItem(arrivingItem);
                        }
                        return;
                    }
                }
            }
            // sneaky insertion
            if (!getRoutedPipe().getUpgradeManager().hasCombinedSneakyUpgrade() || slotManager.hasOwnSneakyUpgrade()) {
                ForgeDirection insertion = arrivingItem.output.getOpposite();
                if (slotManager.hasSneakyUpgrade()) {
                    insertion = slotManager.getSneakyOrientation();
                }
                ItemStack added = InventoryHelper.getTransactorFor(tile, insertion).add(arrivingItem.getItemIdentifierStack().makeNormalStack(), insertion, true);
                arrivingItem.getItemIdentifierStack().lowerStackSize(added.stackSize);
                if (added.stackSize > 0 && arrivingItem instanceof IRoutedItem) {
                    tookSome = true;
                    arrivingItem.setBufferCounter(0);
                }
                ItemRoutingInformation info;
                if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
                    // we have some leftovers, we are splitting the stack, we need to clone the info
                    info = arrivingItem.getInfo().clone();
                    // For InvSysCon
                    info.getItem().setStackSize(added.stackSize);
                    insertedItemStack(info, tile);
                } else {
                    info = arrivingItem.getInfo();
                    info.getItem().setStackSize(added.stackSize);
                    // For InvSysCon
                    insertedItemStack(info, tile);
                    // every item has been inserted.
                    return;
                }
            } else {
                ForgeDirection[] dirs = getRoutedPipe().getUpgradeManager().getCombinedSneakyOrientation();
                for (ForgeDirection insertion : dirs) {
                    if (insertion == null) {
                        continue;
                    }
                    ItemStack added = InventoryHelper.getTransactorFor(tile, insertion).add(arrivingItem.getItemIdentifierStack().makeNormalStack(), insertion, true);
                    arrivingItem.getItemIdentifierStack().lowerStackSize(added.stackSize);
                    if (added.stackSize > 0) {
                        tookSome = true;
                        arrivingItem.setBufferCounter(0);
                    }
                    ItemRoutingInformation info;
                    if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
                        // we have some leftovers, we are splitting the stack, we need to clone the info
                        info = arrivingItem.getInfo().clone();
                        // For InvSysCon
                        info.getItem().setStackSize(added.stackSize);
                        insertedItemStack(info, tile);
                    } else {
                        info = arrivingItem.getInfo();
                        info.getItem().setStackSize(added.stackSize);
                        // For InvSysCon
                        insertedItemStack(info, tile);
                        // every item has been inserted.
                        return;
                    }
                }
            }
            if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
                reverseItem(arrivingItem);
            }
        }
        // the item is handled
        return;
    }
    // end of insert into IInventory
    dropItem(arrivingItem);
}
Also used : IInventory(net.minecraft.inventory.IInventory) ITargetSlotInformation(logisticspipes.interfaces.routing.ITargetSlotInformation) SidedInventoryMinecraftAdapter(logisticspipes.utils.SidedInventoryMinecraftAdapter) FluidRoutedPipe(logisticspipes.pipes.basic.fluid.FluidRoutedPipe) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) ModulePositionType(logisticspipes.modules.abstractmodules.LogisticsModule.ModulePositionType) ISidedInventory(net.minecraft.inventory.ISidedInventory) PipeItemsFluidSupplier(logisticspipes.pipes.PipeItemsFluidSupplier) ISpecialInsertion(logisticspipes.interfaces.ISpecialInsertion) ChassiTargetInformation(logisticspipes.pipes.PipeLogisticsChassi.ChassiTargetInformation) PipeLogisticsChassi(logisticspipes.pipes.PipeLogisticsChassi) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack) ISlotUpgradeManager(logisticspipes.interfaces.ISlotUpgradeManager) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)

Example 14 with ItemRoutingInformation

use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.

the class LPDuctUnitItem method transferItem.

@Override
public void transferItem(TravelingItem item) {
    ItemRoutingInformation info = (ItemRoutingInformation) ((ILPTravelingItemInfo) item).getLPRoutingInfoAddition();
    if (info != null) {
        info.setItem(ItemIdentifierStack.getFromStack(item.stack));
        LPTravelingItem.LPTravelingItemServer lpItem = new LPTravelingItem.LPTravelingItemServer(info);
        lpItem.setSpeed(info._transportMode == IRoutedItem.TransportMode.Active ? 0.3F : 0.2F);
        pipe.pipe.transport.injectItem(lpItem, EnumFacing.getFront(item.direction).getOpposite());
    } else if (item.stack != null) {
        int consumed = pipe.injectItem(item.stack, true, EnumFacing.getFront(item.direction).getOpposite());
        item.stack.shrink(consumed);
        if (item.stack.getCount() > 0) {
            pipe.pipe.transport._itemBuffer.add(new Triplet<>(ItemIdentifierStack.getFromStack(item.stack), new Pair<>(20 * 2, 0), null));
        }
    }
}
Also used : ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) Triplet(logisticspipes.utils.tuples.Triplet) LPTravelingItem(logisticspipes.transport.LPTravelingItem)

Example 15 with ItemRoutingInformation

use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.

the class PipeTransportLogistics method insertArrivingItem.

/**
 * @return true, if every item has been inserted and otherwise false.
 */
private boolean insertArrivingItem(LPTravelingItemServer arrivingItem, TileEntity tile, EnumFacing insertion) {
    ItemStack added = InventoryHelper.getTransactorFor(tile, insertion).add(arrivingItem.getItemIdentifierStack().makeNormalStack(), insertion, true);
    arrivingItem.getItemIdentifierStack().lowerStackSize(added.getCount());
    if (added.getCount() > 0) {
        arrivingItem.setBufferCounter(0);
    }
    ItemRoutingInformation info = arrivingItem.getInfo();
    final boolean isSplitStack = arrivingItem.getItemIdentifierStack().getStackSize() > 0;
    if (isSplitStack) {
        // we have some leftovers, we are splitting the stack, we need to clone the info
        info = info.clone();
    }
    info.getItem().setStackSize(added.getCount());
    inventorySystemConnectorHook(info, tile);
    // back to normal code, break if we've inserted everything, all items disposed of.
    return !isSplitStack;
}
Also used : ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemRoutingInformation (logisticspipes.routing.ItemRoutingInformation)22 ItemStack (net.minecraft.item.ItemStack)7 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 ArrayList (java.util.ArrayList)4 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)4 LPTravelingItemServer (logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)4 Triplet (logisticspipes.utils.tuples.Triplet)4 EnumFacing (net.minecraft.util.EnumFacing)4 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)3 ITransactor (logisticspipes.utils.transactor.ITransactor)3 LinkedList (java.util.LinkedList)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)2 Pair (logisticspipes.utils.tuples.Pair)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 IFlowItems (buildcraft.api.transport.pipe.IFlowItems)1 Collection (java.util.Collection)1