Search in sources :

Example 1 with IRoutedItem

use of logisticspipes.logisticspipes.IRoutedItem in project LogisticsPipes by RS485.

the class PipeItemsProviderLogistics method sendStack.

private int sendStack(ItemIdentifierStack stack, int maxCount, int destination, IAdditionalTargetInformation info) {
    ItemIdentifier item = stack.getItem();
    WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(container);
    //@formatter:off
    Iterator<Pair<IInventoryUtil, ForgeDirection>> iterator = worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).filter(adjacent -> !SimpleServiceLocator.pipeInformationManager.isItemPipe(adjacent.tileEntity)).map(adjacent -> new Pair<>(getAdaptedInventoryUtil(adjacent), adjacent.direction)).iterator();
    while (iterator.hasNext()) {
        Pair<IInventoryUtil, ForgeDirection> next = iterator.next();
        int available = next.getValue1().itemCount(item);
        if (available == 0) {
            continue;
        }
        int wanted = Math.min(available, stack.getStackSize());
        wanted = Math.min(wanted, maxCount);
        wanted = Math.min(wanted, item.getMaxStackSize());
        IRouter dRtr = SimpleServiceLocator.routerManager.getRouterUnsafe(destination, false);
        if (dRtr == null) {
            _orderManager.sendFailed();
            return 0;
        }
        SinkReply reply = LogisticsManager.canSink(dRtr, null, true, stack.getItem(), null, true, false);
        boolean defersend = false;
        if (reply != null) {
            // some pipes are not aware of the space in the adjacent inventory, so they return null
            if (reply.maxNumberOfItems < wanted) {
                wanted = reply.maxNumberOfItems;
                if (wanted <= 0) {
                    _orderManager.deferSend();
                    return 0;
                }
                defersend = true;
            }
        }
        if (!canUseEnergy(wanted * neededEnergy())) {
            return -1;
        }
        ItemStack removed = next.getValue1().getMultipleItems(item, wanted);
        if (removed == null || removed.stackSize == 0) {
            continue;
        }
        int sent = removed.stackSize;
        useEnergy(sent * neededEnergy());
        IRoutedItem routedItem = SimpleServiceLocator.routedItemHelper.createNewTravelItem(removed);
        routedItem.setDestination(destination);
        routedItem.setTransportMode(TransportMode.Active);
        routedItem.setAdditionalTargetInformation(info);
        super.queueRoutedItem(routedItem, next.getValue2());
        _orderManager.sendSuccessfull(sent, defersend, routedItem);
        return sent;
    }
    _orderManager.sendFailed();
    return 0;
}
Also used : IRouter(logisticspipes.routing.IRouter) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) Textures(logisticspipes.textures.Textures) Item(net.minecraft.item.Item) LogisticsPipes(logisticspipes.LogisticsPipes) ProviderPipeInclude(logisticspipes.network.packets.modules.ProviderPipeInclude) Particles(logisticspipes.pipefxhandlers.Particles) ChestContent(logisticspipes.network.packets.hud.ChestContent) MainProxy(logisticspipes.proxy.MainProxy) IHeadUpDisplayRenderer(logisticspipes.interfaces.IHeadUpDisplayRenderer) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) HUDStartWatchingPacket(logisticspipes.network.packets.hud.HUDStartWatchingPacket) SinkReply(logisticspipes.utils.SinkReply) SidedInventoryMinecraftAdapter(logisticspipes.utils.SidedInventoryMinecraftAdapter) Map(java.util.Map) ModuleProvider(logisticspipes.modules.ModuleProvider) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IChangeListener(logisticspipes.interfaces.IChangeListener) HUDStopWatchingPacket(logisticspipes.network.packets.hud.HUDStopWatchingPacket) IProvideItems(logisticspipes.interfaces.routing.IProvideItems) ConnectionPipeType(logisticspipes.routing.pathfinder.IPipeInformationProvider.ConnectionPipeType) Collection(java.util.Collection) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) LogisticsManager(logisticspipes.logistics.LogisticsManager) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) Set(java.util.Set) PacketHandler(logisticspipes.network.PacketHandler) RequestTreeNode(logisticspipes.request.RequestTreeNode) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) DictResource(logisticspipes.request.resources.DictResource) Collectors(java.util.stream.Collectors) TransportMode(logisticspipes.logisticspipes.IRoutedItem.TransportMode) List(java.util.List) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) IChestContentReceiver(logisticspipes.interfaces.IChestContentReceiver) IFilter(logisticspipes.interfaces.routing.IFilter) OrdererManagerContent(logisticspipes.network.packets.orderer.OrdererManagerContent) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Pair(logisticspipes.utils.tuples.Pair) Entry(java.util.Map.Entry) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) GuiIDs(logisticspipes.network.GuiIDs) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) ItemResource(logisticspipes.request.resources.ItemResource) LogisticsOrder(logisticspipes.routing.order.LogisticsOrder) HashMap(java.util.HashMap) HUDProvider(logisticspipes.gui.hud.HUDProvider) ResourceType(logisticspipes.routing.order.IOrderInfoProvider.ResourceType) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) IRequestItems(logisticspipes.interfaces.routing.IRequestItems) IHeadUpDisplayRendererProvider(logisticspipes.interfaces.IHeadUpDisplayRendererProvider) ExtractionMode(logisticspipes.logisticspipes.ExtractionMode) LogisticsItemOrderManager(logisticspipes.routing.order.LogisticsItemOrderManager) LinkedList(java.util.LinkedList) Iterator(java.util.Iterator) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) LogisticsPromise(logisticspipes.routing.LogisticsPromise) TextureType(logisticspipes.textures.Textures.TextureType) RequestTree(logisticspipes.request.RequestTree) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity) IResource(logisticspipes.request.resources.IResource) TreeMap(java.util.TreeMap) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ProviderPipeMode(logisticspipes.network.packets.modules.ProviderPipeMode) IInventory(net.minecraft.inventory.IInventory) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) IOrderManagerContentReceiver(logisticspipes.interfaces.IOrderManagerContentReceiver) IInventory(net.minecraft.inventory.IInventory) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) IRouter(logisticspipes.routing.IRouter) SinkReply(logisticspipes.utils.SinkReply) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) ItemStack(net.minecraft.item.ItemStack) Pair(logisticspipes.utils.tuples.Pair)

Example 2 with IRoutedItem

use of logisticspipes.logisticspipes.IRoutedItem in project LogisticsPipes by RS485.

the class CoreRoutedPipe method sendStack.

@Override
public IRoutedItem sendStack(ItemStack stack, Pair<Integer, SinkReply> reply, ItemSendMode mode) {
    IRoutedItem itemToSend = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stack);
    itemToSend.setDestination(reply.getValue1());
    if (reply.getValue2().isPassive) {
        if (reply.getValue2().isDefault) {
            itemToSend.setTransportMode(TransportMode.Default);
        } else {
            itemToSend.setTransportMode(TransportMode.Passive);
        }
    }
    itemToSend.setAdditionalTargetInformation(reply.getValue2().addInfo);
    queueRoutedItem(itemToSend, getPointedOrientation(), mode);
    return itemToSend;
}
Also used : IRoutedItem(logisticspipes.logisticspipes.IRoutedItem)

Example 3 with IRoutedItem

use of logisticspipes.logisticspipes.IRoutedItem in project LogisticsPipes by RS485.

the class ModuleCrafter method enabledUpdateEntity.

public void enabledUpdateEntity() {
    final IPipeServiceProvider service = _service;
    if (service == null)
        return;
    if (service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
        if (service.isNthTick(6)) {
            cacheAreAllOrderesToBuffer();
        }
        if (service.getItemOrderManager().isFirstOrderWatched()) {
            TileEntity tile = lastAccessedCrafter.get();
            if (tile != null) {
                service.getItemOrderManager().setMachineProgress(SimpleServiceLocator.machineProgressProvider.getProgressForTile(tile));
            } else {
                service.getItemOrderManager().setMachineProgress((byte) 0);
            }
        }
    } else {
        cachedAreAllOrderesToBuffer = false;
    }
    if (!service.isNthTick(6)) {
        return;
    }
    final List<NeighborTileEntity<TileEntity>> adjacentInventories = service.getAvailableAdjacent().inventories();
    if (!service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
        final ISlotUpgradeManager upgradeManager = Objects.requireNonNull(getUpgradeManager());
        if (upgradeManager.getCrafterCleanup() > 0) {
            adjacentInventories.stream().map(neighbor -> extractFiltered(neighbor, cleanupInventory, cleanupModeIsExclude.getValue(), upgradeManager.getCrafterCleanup() * 3)).filter(stack -> !stack.isEmpty()).findFirst().ifPresent(extracted -> {
                service.queueRoutedItem(SimpleServiceLocator.routedItemHelper.createNewTravelItem(extracted), EnumFacing.UP);
                service.getCacheHolder().trigger(CacheTypes.Inventory);
            });
        }
        return;
    }
    if (adjacentInventories.size() < 1) {
        if (service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
            service.getItemOrderManager().sendFailed();
        }
        return;
    }
    List<ItemIdentifierStack> wanteditem = getCraftedItems();
    if (wanteditem == null || wanteditem.isEmpty()) {
        return;
    }
    service.spawnParticle(Particles.VioletParticle, 2);
    int itemsleft = itemsToExtract();
    int stacksleft = stacksToExtract();
    while (itemsleft > 0 && stacksleft > 0 && (service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA))) {
        LogisticsItemOrder nextOrder = service.getItemOrderManager().peekAtTopRequest(ResourceType.CRAFTING, // fetch but not remove.
        ResourceType.EXTRA);
        int maxtosend = Math.min(itemsleft, nextOrder.getResource().stack.getStackSize());
        maxtosend = Math.min(nextOrder.getResource().getItem().getMaxStackSize(), maxtosend);
        // retrieve the new crafted items
        ItemStack extracted = ItemStack.EMPTY;
        // there has to be at least one adjacentCrafter at this point; adjacent wont stay null
        NeighborTileEntity<TileEntity> adjacent = null;
        for (NeighborTileEntity<TileEntity> adjacentCrafter : adjacentInventories) {
            adjacent = adjacentCrafter;
            extracted = extract(adjacent, nextOrder.getResource(), maxtosend);
            if (!extracted.isEmpty()) {
                break;
            }
        }
        if (extracted.isEmpty()) {
            service.getItemOrderManager().deferSend();
            break;
        }
        service.getCacheHolder().trigger(CacheTypes.Inventory);
        Objects.requireNonNull(adjacent);
        lastAccessedCrafter = new WeakReference<>(adjacent.getTileEntity());
        // send the new crafted items to the destination
        ItemIdentifier extractedID = ItemIdentifier.get(extracted);
        while (!extracted.isEmpty()) {
            if (isExtractedMismatch(nextOrder, extractedID)) {
                LogisticsItemOrder startOrder = nextOrder;
                if (service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
                    do {
                        service.getItemOrderManager().deferSend();
                        nextOrder = service.getItemOrderManager().peekAtTopRequest(ResourceType.CRAFTING, ResourceType.EXTRA);
                    } while (isExtractedMismatch(nextOrder, extractedID) && startOrder != nextOrder);
                }
                if (startOrder == nextOrder) {
                    int numtosend = Math.min(extracted.getCount(), extractedID.getMaxStackSize());
                    if (numtosend == 0) {
                        break;
                    }
                    stacksleft -= 1;
                    itemsleft -= numtosend;
                    ItemStack stackToSend = extracted.splitStack(numtosend);
                    // Route the unhandled item
                    service.sendStack(stackToSend, -1, ItemSendMode.Normal, null, adjacent.getDirection());
                    continue;
                }
            }
            int numtosend = Math.min(extracted.getCount(), extractedID.getMaxStackSize());
            numtosend = Math.min(numtosend, nextOrder.getResource().stack.getStackSize());
            if (numtosend == 0) {
                break;
            }
            stacksleft -= 1;
            itemsleft -= numtosend;
            ItemStack stackToSend = extracted.splitStack(numtosend);
            if (nextOrder.getDestination() != null) {
                SinkReply reply = LogisticsManager.canSink(stackToSend, nextOrder.getDestination().getRouter(), null, true, ItemIdentifier.get(stackToSend), null, true, false);
                boolean defersend = (reply == null || reply.bufferMode != BufferMode.NONE || reply.maxNumberOfItems < 1);
                IRoutedItem item = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stackToSend);
                item.setDestination(nextOrder.getDestination().getRouter().getSimpleID());
                item.setTransportMode(TransportMode.Active);
                item.setAdditionalTargetInformation(nextOrder.getInformation());
                service.queueRoutedItem(item, adjacent.getDirection());
                service.getItemOrderManager().sendSuccessfull(stackToSend.getCount(), defersend, item);
            } else {
                service.sendStack(stackToSend, -1, ItemSendMode.Normal, nextOrder.getInformation(), adjacent.getDirection());
                service.getItemOrderManager().sendSuccessfull(stackToSend.getCount(), false, null);
            }
            if (service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
                nextOrder = service.getItemOrderManager().peekAtTopRequest(ResourceType.CRAFTING, // fetch but not remove.
                ResourceType.EXTRA);
            }
        }
    }
}
Also used : CPipeSatelliteImportBack(logisticspipes.network.packets.cpipe.CPipeSatelliteImportBack) ChassiTargetInformation(logisticspipes.pipes.PipeLogisticsChassis.ChassiTargetInformation) NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) BitSetProperty(network.rs485.logisticspipes.property.BitSetProperty) Constants(net.minecraftforge.common.util.Constants) EnumHand(net.minecraft.util.EnumHand) MainProxy(logisticspipes.proxy.MainProxy) FluidCraftingAmount(logisticspipes.network.packets.pipe.FluidCraftingAmount) SinkReply(logisticspipes.utils.SinkReply) HUDStopModuleWatchingPacket(logisticspipes.network.packets.hud.HUDStopModuleWatchingPacket) ItemCraftingTemplate(logisticspipes.request.ItemCraftingTemplate) Map(java.util.Map) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) NewGuiHandler(logisticspipes.network.NewGuiHandler) LogisticsExtraPromise(logisticspipes.routing.LogisticsExtraPromise) LogisticsManager(logisticspipes.logistics.LogisticsManager) PacketHandler(logisticspipes.network.PacketHandler) ExitRoute(logisticspipes.routing.ExitRoute) UUIDPropertyKt(network.rs485.logisticspipes.property.UUIDPropertyKt) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) IFilter(logisticspipes.interfaces.routing.IFilter) BooleanProperty(network.rs485.logisticspipes.property.BooleanProperty) LogisticsCraftingTableTileEntity(logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity) BufferMode(logisticspipes.utils.SinkReply.BufferMode) CraftingModuleInHand(logisticspipes.network.guis.module.inhand.CraftingModuleInHand) IItemIdentifierInventory(network.rs485.logisticspipes.inventory.IItemIdentifierInventory) UUIDListProperty(network.rs485.logisticspipes.property.UUIDListProperty) CraftingPipeOpenConnectedGuiPacket(logisticspipes.network.packets.cpipe.CraftingPipeOpenConnectedGuiPacket) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) CraftingModuleSlot(logisticspipes.network.guis.module.inpipe.CraftingModuleSlot) InventoryProperty(network.rs485.logisticspipes.property.InventoryProperty) IWorldProvider(logisticspipes.interfaces.IWorldProvider) LogisticsDictPromise(logisticspipes.routing.LogisticsDictPromise) FuzzyUtil(network.rs485.logisticspipes.util.FuzzyUtil) Nullable(javax.annotation.Nullable) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) BlockPos(net.minecraft.util.math.BlockPos) LogisticsExtraDictPromise(logisticspipes.routing.LogisticsExtraDictPromise) DelayedGeneric(logisticspipes.utils.DelayedGeneric) ItemSendMode(logisticspipes.pipes.basic.CoreRoutedPipe.ItemSendMode) CPipeSatelliteImport(logisticspipes.network.packets.cpipe.CPipeSatelliteImport) HUDStartModuleWatchingPacket(logisticspipes.network.packets.hud.HUDStartModuleWatchingPacket) IResource(logisticspipes.request.resources.IResource) IBlockState(net.minecraft.block.state.IBlockState) 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) ICraftingTemplate(logisticspipes.request.ICraftingTemplate) LogisticsPipes(logisticspipes.LogisticsPipes) 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) ICraftItems(logisticspipes.interfaces.routing.ICraftItems) LPNeighborTileEntityKt(network.rs485.logisticspipes.connection.LPNeighborTileEntityKt) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ModernPacket(logisticspipes.network.abstractpackets.ModernPacket) Collection(java.util.Collection) FluidResource(logisticspipes.request.resources.FluidResource) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) IFuzzyRecipeProvider(logisticspipes.proxy.interfaces.IFuzzyRecipeProvider) UUID(java.util.UUID) RequestTreeNode(logisticspipes.request.RequestTreeNode) DictResource(logisticspipes.request.resources.DictResource) TransportMode(logisticspipes.logisticspipes.IRoutedItem.TransportMode) Objects(java.util.Objects) 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) Gui(network.rs485.logisticspipes.module.Gui) Property(network.rs485.logisticspipes.property.Property) IPromise(logisticspipes.request.IPromise) AdjacentUtilKt(network.rs485.logisticspipes.connection.AdjacentUtilKt) ItemResource(logisticspipes.request.resources.ItemResource) Getter(lombok.Getter) ModuleCoordinatesGuiProvider(logisticspipes.network.abstractguis.ModuleCoordinatesGuiProvider) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) IReqCraftingTemplate(logisticspipes.request.IReqCraftingTemplate) ResourceType(logisticspipes.routing.order.IOrderInfoProvider.ResourceType) CoordinatesPacket(logisticspipes.network.abstractpackets.CoordinatesPacket) IBitSet(network.rs485.logisticspipes.property.IBitSet) IntListProperty(network.rs485.logisticspipes.property.IntListProperty) IntegerProperty(network.rs485.logisticspipes.property.IntegerProperty) ImmutableList(com.google.common.collect.ImmutableList) IRequestItems(logisticspipes.interfaces.routing.IRequestItems) IModuleWatchReciver(logisticspipes.interfaces.IModuleWatchReciver) ISlotUpgradeManager(logisticspipes.interfaces.ISlotUpgradeManager) DelayQueue(java.util.concurrent.DelayQueue) WeakReference(java.lang.ref.WeakReference) PipeFluidSatellite(logisticspipes.pipes.PipeFluidSatellite) Nonnull(javax.annotation.Nonnull) IHUDModuleRenderer(logisticspipes.interfaces.IHUDModuleRenderer) IGuiOpenControler(logisticspipes.interfaces.IGuiOpenControler) FixedPriority(logisticspipes.utils.SinkReply.FixedPriority) CraftingPipeUpdatePacket(logisticspipes.network.packets.pipe.CraftingPipeUpdatePacket) EnumFacing(net.minecraft.util.EnumFacing) LogisticsPromise(logisticspipes.routing.LogisticsPromise) RequestTree(logisticspipes.request.RequestTree) UUIDProperty(network.rs485.logisticspipes.property.UUIDProperty) BitSet(java.util.BitSet) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) LogisticsCraftingTableTileEntity(logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) SinkReply(logisticspipes.utils.SinkReply) NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ItemStack(net.minecraft.item.ItemStack) ISlotUpgradeManager(logisticspipes.interfaces.ISlotUpgradeManager)

Example 4 with IRoutedItem

use of logisticspipes.logisticspipes.IRoutedItem in project LogisticsPipes by RS485.

the class CoreRoutedPipe method updateEntity.

@Override
public final void updateEntity() {
    debug.tick();
    spawnParticleTick();
    if (stillNeedReplace) {
        stillNeedReplace = false;
        // IBlockState state = getWorld().getBlockState(getPos());
        // getWorld().notifyNeighborsOfStateChange(getPos(), state == null ? null : state.getBlock(), true);
        /* TravelingItems are just held by a pipe, they don't need to know their world
			 * for(Triplet<IRoutedItem, EnumFacing, ItemSendMode> item : _sendQueue) {
				//assign world to any entityitem we created in readfromnbt
				item.getValue1().getTravelingItem().setWorld(getWorld());
			}*/
        // first tick just create a router and do nothing.
        firstInitialiseTick();
        return;
    }
    if (repeatFor > 0) {
        if (delayTo < System.currentTimeMillis()) {
            delayTo = System.currentTimeMillis() + 200;
            repeatFor--;
            getWorld().notifyNeighborsOfStateChange(getPos(), getWorld().getBlockState(getPos()).getBlock(), true);
        }
    }
    // remove old items _inTransit -- these should have arrived, but have probably been lost instead. In either case, it will allow a re-send so that another attempt to re-fill the inventory can be made.
    while (_inTransitToMe.peek() != null && _inTransitToMe.peek().getTickToTimeOut() <= 0) {
        final ItemRoutingInformation polledInfo = _inTransitToMe.poll();
        if (polledInfo != null) {
            if (LogisticsPipes.isDEBUG()) {
                LogisticsPipes.log.info("Timed Out: " + polledInfo.getItem().getFriendlyName() + " (" + polledInfo.hashCode() + ")");
            }
            debug.log("Timed Out: " + polledInfo.getItem().getFriendlyName() + " (" + polledInfo.hashCode() + ")");
        }
    }
    // update router before ticking logic/transport
    final boolean doFullRefresh = getWorld().getTotalWorldTime() % Configs.LOGISTICS_DETECTION_FREQUENCY == _delayOffset || _initialInit || recheckConnections;
    if (doFullRefresh) {
        // update adjacent cache first, so interests can be gathered correctly
        // in getRouter().update(…) below
        updateAdjacentCache();
    }
    getRouter().update(doFullRefresh, this);
    recheckConnections = false;
    getOriginalUpgradeManager().securityTick();
    super.updateEntity();
    if (isNthTick(200)) {
        getCacheHolder().trigger(null);
    }
    // from BaseRoutingLogic
    if (--throttleTimeLeft <= 0) {
        throttledUpdateEntity();
        throttleTimeLeft = throttleTime;
    }
    ignoreDisableUpdateEntity();
    _initialInit = false;
    if (!_sendQueue.isEmpty()) {
        if (getItemSendMode() == ItemSendMode.Normal) {
            Triplet<IRoutedItem, EnumFacing, ItemSendMode> itemToSend = _sendQueue.getFirst();
            sendRoutedItem(itemToSend.getValue1(), itemToSend.getValue2());
            _sendQueue.removeFirst();
            for (int i = 0; i < 16 && !_sendQueue.isEmpty() && _sendQueue.getFirst().getValue3() == ItemSendMode.Fast; i++) {
                if (!_sendQueue.isEmpty()) {
                    itemToSend = _sendQueue.getFirst();
                    sendRoutedItem(itemToSend.getValue1(), itemToSend.getValue2());
                    _sendQueue.removeFirst();
                }
            }
            sendQueueChanged(false);
        } else if (getItemSendMode() == ItemSendMode.Fast) {
            for (int i = 0; i < 16; i++) {
                if (!_sendQueue.isEmpty()) {
                    Triplet<IRoutedItem, EnumFacing, ItemSendMode> itemToSend = _sendQueue.getFirst();
                    sendRoutedItem(itemToSend.getValue1(), itemToSend.getValue2());
                    _sendQueue.removeFirst();
                }
            }
            sendQueueChanged(false);
        } else if (getItemSendMode() == null) {
            throw new UnsupportedOperationException("getItemSendMode() can't return null. " + this.getClass().getName());
        } else {
            throw new UnsupportedOperationException("getItemSendMode() returned unhandled value. " + getItemSendMode().name() + " in " + this.getClass().getName());
        }
    }
    if (MainProxy.isClient(getWorld())) {
        return;
    }
    checkTexturePowered();
    if (!isEnabled()) {
        return;
    }
    enabledUpdateEntity();
    if (getLogisticsModule() == null) {
        return;
    }
    getLogisticsModule().tick();
}
Also used : ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) Triplet(logisticspipes.utils.tuples.Triplet) EnumFacing(net.minecraft.util.EnumFacing)

Example 5 with IRoutedItem

use of logisticspipes.logisticspipes.IRoutedItem in project LogisticsPipes by RS485.

the class CoreRoutedPipe method writeToNBT.

@Override
public void writeToNBT(@Nonnull NBTTagCompound nbttagcompound) {
    super.writeToNBT(nbttagcompound);
    synchronized (routerIdLock) {
        if (routerId == null || routerId.isEmpty()) {
            if (router != null) {
                routerId = router.getId().toString();
            } else {
                routerId = UUID.randomUUID().toString();
            }
        }
    }
    nbttagcompound.setString("routerId", routerId);
    nbttagcompound.setLong("stat_lifetime_sent", stat_lifetime_sent);
    nbttagcompound.setLong("stat_lifetime_recieved", stat_lifetime_recieved);
    nbttagcompound.setLong("stat_lifetime_relayed", stat_lifetime_relayed);
    if (getLogisticsModule() != null) {
        getLogisticsModule().writeToNBT(nbttagcompound);
    }
    NBTTagCompound upgradeNBT = new NBTTagCompound();
    upgradeManager.writeToNBT(upgradeNBT);
    nbttagcompound.setTag("upgradeManager", upgradeNBT);
    NBTTagCompound powerNBT = new NBTTagCompound();
    powerHandler.writeToNBT(powerNBT);
    if (!powerNBT.hasNoTags()) {
        nbttagcompound.setTag("powerHandler", powerNBT);
    }
    NBTTagList sendqueue = new NBTTagList();
    for (Triplet<IRoutedItem, EnumFacing, ItemSendMode> p : _sendQueue) {
        NBTTagCompound tagentry = new NBTTagCompound();
        NBTTagCompound tagentityitem = new NBTTagCompound();
        p.getValue1().writeToNBT(tagentityitem);
        tagentry.setTag("entityitem", tagentityitem);
        tagentry.setByte("from", (byte) (p.getValue2().ordinal()));
        tagentry.setByte("mode", (byte) (p.getValue3().ordinal()));
        sendqueue.appendTag(tagentry);
    }
    nbttagcompound.setTag("sendqueue", sendqueue);
    for (int i = 0; i < 6; i++) {
        if (signItem[i] != null) {
            nbttagcompound.setBoolean("PipeSign_" + i, true);
            int signType = -1;
            List<Class<? extends IPipeSign>> typeClasses = ItemPipeSignCreator.signTypes;
            for (int j = 0; j < typeClasses.size(); j++) {
                if (typeClasses.get(j) == signItem[i].getClass()) {
                    signType = j;
                    break;
                }
            }
            nbttagcompound.setInteger("PipeSign_" + i + "_type", signType);
            NBTTagCompound tag = new NBTTagCompound();
            signItem[i].writeToNBT(tag);
            nbttagcompound.setTag("PipeSign_" + i + "_tags", tag);
        } else {
            nbttagcompound.setBoolean("PipeSign_" + i, false);
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) IPipeSign(logisticspipes.pipes.signs.IPipeSign) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Aggregations

IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)17 EnumFacing (net.minecraft.util.EnumFacing)7 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)5 Pair (logisticspipes.utils.tuples.Pair)5 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 List (java.util.List)4 Map (java.util.Map)4 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)4 IAdditionalTargetInformation (logisticspipes.interfaces.routing.IAdditionalTargetInformation)4 IFilter (logisticspipes.interfaces.routing.IFilter)4 Nonnull (javax.annotation.Nonnull)3 IRequestItems (logisticspipes.interfaces.routing.IRequestItems)3 LogisticsManager (logisticspipes.logistics.LogisticsManager)3 TransportMode (logisticspipes.logisticspipes.IRoutedItem.TransportMode)3 PacketHandler (logisticspipes.network.PacketHandler)3 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)3 RequestTree (logisticspipes.request.RequestTree)3 RequestTreeNode (logisticspipes.request.RequestTreeNode)3 ResourceType (logisticspipes.routing.order.IOrderInfoProvider.ResourceType)3