Search in sources :

Example 6 with ItemRoutingInformation

use of logisticspipes.routing.ItemRoutingInformation 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 7 with ItemRoutingInformation

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

the class PipeItemsInvSysConnector method handleItemEnterInv.

public void handleItemEnterInv(ItemRoutingInformation info, TileEntity tile) {
    if (info.getItem().getStackSize() == 0) {
        // system.throw("why you try to insert empty stack?");
        return;
    }
    if (info.destinationint < 0) {
        // The item does not have a destination anymore, maybe the target pipe has been removed... We cannot do anything anymore so just let it be.
        return;
    }
    if (isInventoryConnected(tile)) {
        if (hasRemoteConnection()) {
            List<CoreRoutedPipe> connectedPipes = SimpleServiceLocator.connectionManager.getConnectedPipes(getRouter());
            Optional<CoreRoutedPipe> bestConnection = connectedPipes.stream().map(con -> new Triplet<>(con, con.getRouter().getExitFor(info.destinationint, info._transportMode == IRoutedItem.TransportMode.Active, info.getItem().getItem()), con.getRouter().getExitFor(getRouterId(), info._transportMode == IRoutedItem.TransportMode.Active, info.getItem().getItem()))).filter(triplet -> triplet.getValue2() != null && triplet.getValue3() != null).filter(triplet -> triplet.getValue2().exitOrientation != triplet.getValue3().exitOrientation).min(Comparator.comparing(trip -> trip.getValue2().blockDistance)).map(Pair::getValue1);
            if (!bestConnection.isPresent()) {
                bestConnection = connectedPipes.stream().map(con -> new Pair<>(con, con.getRouter().getExitFor(info.destinationint, info._transportMode == IRoutedItem.TransportMode.Active, info.getItem().getItem()))).filter(triplet -> triplet.getValue2() != null).min(Comparator.comparing(trip -> trip.getValue2().blockDistance)).map(Pair::getValue1);
            }
            if (bestConnection.isPresent() && bestConnection.get() instanceof IChannelRoutingConnection) {
                IChannelRoutingConnection pipe = (IChannelRoutingConnection) bestConnection.get();
                pipe.addItem(info);
                spawnParticle(Particles.OrangeParticle, 4);
            }
        }
    }
}
Also used : HUDInvSysConnector(logisticspipes.gui.hud.HUDInvSysConnector) InvSysConGuiProvider(logisticspipes.network.guis.pipe.InvSysConGuiProvider) Textures(logisticspipes.textures.Textures) Item(net.minecraft.item.Item) Particles(logisticspipes.pipefxhandlers.Particles) MainProxy(logisticspipes.proxy.MainProxy) IHeadUpDisplayRenderer(logisticspipes.interfaces.IHeadUpDisplayRenderer) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) HUDStartWatchingPacket(logisticspipes.network.packets.hud.HUDStartWatchingPacket) LogisticsModule(logisticspipes.modules.LogisticsModule) Map(java.util.Map) TransportInvConnection(logisticspipes.transport.TransportInvConnection) LPNeighborTileEntityKt(network.rs485.logisticspipes.connection.LPNeighborTileEntityKt) ChannelInformationPacket(logisticspipes.network.packets.gui.ChannelInformationPacket) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) HUDStopWatchingPacket(logisticspipes.network.packets.hud.HUDStopWatchingPacket) NewGuiHandler(logisticspipes.network.NewGuiHandler) Collection(java.util.Collection) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) Set(java.util.Set) Triplet(logisticspipes.utils.tuples.Triplet) UUID(java.util.UUID) PacketHandler(logisticspipes.network.PacketHandler) List(java.util.List) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) OrdererManagerContent(logisticspipes.network.packets.orderer.OrdererManagerContent) EntityPlayer(net.minecraft.entity.player.EntityPlayer) InvSysConResistance(logisticspipes.network.packets.pipe.InvSysConResistance) Pair(logisticspipes.utils.tuples.Pair) Entry(java.util.Map.Entry) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) Optional(java.util.Optional) ChannelInformation(logisticspipes.routing.channels.ChannelInformation) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) IChannelManager(logisticspipes.interfaces.routing.IChannelManager) IHeadUpDisplayRendererProvider(logisticspipes.interfaces.IHeadUpDisplayRendererProvider) ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) LinkedList(java.util.LinkedList) Nonnull(javax.annotation.Nonnull) ITransactor(logisticspipes.utils.transactor.ITransactor) Nullable(javax.annotation.Nullable) Iterator(java.util.Iterator) IGuiOpenControler(logisticspipes.interfaces.IGuiOpenControler) EnumFacing(net.minecraft.util.EnumFacing) TextureType(logisticspipes.textures.Textures.TextureType) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) TileEntity(net.minecraft.tileentity.TileEntity) IChannelRoutingConnection(logisticspipes.interfaces.routing.IChannelRoutingConnection) Comparator(java.util.Comparator) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) IOrderManagerContentReceiver(logisticspipes.interfaces.IOrderManagerContentReceiver) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) IChannelRoutingConnection(logisticspipes.interfaces.routing.IChannelRoutingConnection) Pair(logisticspipes.utils.tuples.Pair)

Example 8 with ItemRoutingInformation

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

the class PipeItemsInvSysConnector method addItem.

@Override
public void addItem(ItemRoutingInformation info) {
    if (info.getItem() != null && info.getItem().getStackSize() > 0 && info.destinationint >= 0) {
        ItemIdentifier insertedType = info.getItem().getItem();
        List<ItemRoutingInformation> entry = itemsOnRoute.computeIfAbsent(insertedType, k -> new LinkedList<>());
        // linked list as this is almost always very small, but experiences random removal
        entry.add(info);
        updateContentListener();
    }
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation)

Example 9 with ItemRoutingInformation

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

the class BCEventHandler method eventHandler.

public void eventHandler(PipeEventItem.DropItem event) {
    ItemRoutingInformation info = null;
    if (event.item instanceof LPRoutedBCTravelingItem) {
        info = ((LPRoutedBCTravelingItem) event.item).getRoutingInformation();
    } else {
        info = LPRoutedBCTravelingItem.restoreFromExtraNBTData(event.item);
    }
    if (info != null) {
        LPTravelingItemServer lpItem = new LPTravelingItemServer(info);
        lpItem.setContainer(event.pipe.container);
        lpItem.itemWasLost();
    }
}
Also used : ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)

Example 10 with ItemRoutingInformation

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

the class LPRoutedBCTravelingItem method restoreFromExtraNBTData.

public static ItemRoutingInformation restoreFromExtraNBTData(TravelingItem item) {
    if (!item.hasExtraData()) {
        return null;
    }
    NBTTagCompound nbt = item.getExtraData();
    if (nbt.hasKey("LPRoutingInformation")) {
        ItemRoutingInformation routingInformation = new ItemRoutingInformation();
        routingInformation.readFromNBT(nbt.getCompoundTag("LPRoutingInformation"));
        return routingInformation;
    }
    return null;
}
Also used : ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

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