Search in sources :

Example 6 with Pair

use of logisticspipes.utils.tuples.Pair 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 7 with Pair

use of logisticspipes.utils.tuples.Pair in project LogisticsPipes by RS485.

the class FluidRoutedPipe method endReached.

public boolean endReached(LPTravelingItemServer arrivingItem, TileEntity tile) {
    if (canInsertToTanks() && MainProxy.isServer(getWorld())) {
        getCacheHolder().trigger(CacheTypes.Inventory);
        if (arrivingItem.getItemIdentifierStack() == null || !(arrivingItem.getItemIdentifierStack().getItem().isFluidContainer())) {
            return false;
        }
        if (getRouter().getSimpleID() != arrivingItem.getDestination()) {
            return false;
        }
        int filled = 0;
        FluidStack liquid = SimpleServiceLocator.logisticsFluidManager.getFluidFromContainer(arrivingItem.getItemIdentifierStack());
        if (isConnectableTank(tile, arrivingItem.output, false)) {
            List<Pair<TileEntity, ForgeDirection>> adjTanks = getAdjacentTanks(false);
            //Try to put liquid into all adjacent tanks.
            for (Pair<TileEntity, ForgeDirection> pair : adjTanks) {
                IFluidHandler tank = (IFluidHandler) pair.getValue1();
                ForgeDirection dir = pair.getValue2();
                filled = tank.fill(dir.getOpposite(), liquid.copy(), true);
                liquid.amount -= filled;
                if (liquid.amount != 0) {
                    continue;
                }
                return true;
            }
            //Try inserting the liquid into the pipe side tank
            filled = ((PipeFluidTransportLogistics) transport).sideTanks[arrivingItem.output.ordinal()].fill(liquid, true);
            if (filled == liquid.amount) {
                return true;
            }
            liquid.amount -= filled;
        }
        //Try inserting the liquid into the pipe internal tank
        filled = ((PipeFluidTransportLogistics) transport).internalTank.fill(liquid, true);
        if (filled == liquid.amount) {
            return true;
        }
        //If liquids still exist,
        liquid.amount -= filled;
        //TODO: FIX THIS
        if (this instanceof IRequireReliableFluidTransport) {
            ((IRequireReliableFluidTransport) this).liquidNotInserted(FluidIdentifier.get(liquid), liquid.amount);
        }
        IRoutedItem routedItem = SimpleServiceLocator.routedItemHelper.createNewTravelItem(SimpleServiceLocator.logisticsFluidManager.getFluidContainer(liquid));
        Pair<Integer, Integer> replies = SimpleServiceLocator.logisticsFluidManager.getBestReply(liquid, getRouter(), routedItem.getJamList());
        int dest = replies.getValue1();
        routedItem.setDestination(dest);
        routedItem.setTransportMode(TransportMode.Passive);
        this.queueRoutedItem(routedItem, arrivingItem.output.getOpposite());
        return true;
    }
    return false;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) PipeFluidTransportLogistics(logisticspipes.transport.PipeFluidTransportLogistics) IRequireReliableFluidTransport(logisticspipes.interfaces.routing.IRequireReliableFluidTransport) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) TileEntity(net.minecraft.tileentity.TileEntity) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Pair(logisticspipes.utils.tuples.Pair)

Example 8 with Pair

use of logisticspipes.utils.tuples.Pair in project LogisticsPipes by RS485.

the class ItemAmountPipeSign method spread.

private void spread(Map<ItemIdentifier, Integer> availableItems, BitSet set) {
    // Improve performance by updating a wall of Amount pipe signs all at once
    IRouter router = pipe.getRouter();
    if (set.get(router.getSimpleID()))
        return;
    set.set(router.getSimpleID());
    for (ExitRoute exit : router.getIRoutersByCost()) {
        // Only when the signs are in one wall. To not spread to far.
        if (exit.distanceToDestination > 2)
            break;
        if (!exit.filters.isEmpty())
            continue;
        if (set.get(exit.destination.getSimpleID()))
            continue;
        if (exit.connectionDetails.contains(PipeRoutingConnectionType.canRequestFrom) && exit.connectionDetails.contains(PipeRoutingConnectionType.canRouteTo)) {
            CoreRoutedPipe cachedPipe = exit.destination.getCachedPipe();
            if (cachedPipe != null) {
                List<Pair<ForgeDirection, IPipeSign>> pipeSigns = cachedPipe.getPipeSigns();
                pipeSigns.stream().filter(signPair -> signPair != null && signPair.getValue2() instanceof ItemAmountPipeSign).forEach(signPair -> ((ItemAmountPipeSign) signPair.getValue2()).updateStats(availableItems, set));
            }
        }
    }
}
Also used : IRouter(logisticspipes.routing.IRouter) Item(net.minecraft.item.Item) MainProxy(logisticspipes.proxy.MainProxy) StringUtils(logisticspipes.utils.string.StringUtils) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map) LogisticsRenderPipe(logisticspipes.renderer.LogisticsRenderPipe) GL11(org.lwjgl.opengl.GL11) ItemAmountSignUpdatePacket(logisticspipes.network.packets.pipe.ItemAmountSignUpdatePacket) ModernPacket(logisticspipes.network.abstractpackets.ModernPacket) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NewGuiHandler(logisticspipes.network.NewGuiHandler) PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) Side(cpw.mods.fml.relauncher.Side) ItemAmountSignGui(logisticspipes.network.guis.item.ItemAmountSignGui) SideOnly(cpw.mods.fml.relauncher.SideOnly) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) PacketHandler(logisticspipes.network.PacketHandler) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ExitRoute(logisticspipes.routing.ExitRoute) ServerRouter(logisticspipes.routing.ServerRouter) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) ISimpleInventoryEventHandler(logisticspipes.utils.ISimpleInventoryEventHandler) List(java.util.List) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) FontRenderer(net.minecraft.client.gui.FontRenderer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Pair(logisticspipes.utils.tuples.Pair) IInventory(net.minecraft.inventory.IInventory) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) Data(lombok.Data) BitSet(java.util.BitSet) IRouter(logisticspipes.routing.IRouter) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ExitRoute(logisticspipes.routing.ExitRoute) Pair(logisticspipes.utils.tuples.Pair)

Example 9 with Pair

use of logisticspipes.utils.tuples.Pair in project LogisticsPipes by RS485.

the class ServerRouter method recheckAdjacent.

/**
	 * Rechecks the piped connection to all adjacent routers as well as discover
	 * new ones.
	 */
private boolean recheckAdjacent() {
    connectionNeedsChecking = 0;
    if (LPConstants.DEBUG) {
        causedBy.clear();
    }
    if (getPipe() != null) {
        /*
			if (getPipe().getDebug() != null && getPipe().getDebug().debugThisPipe) {
				Info info = StackTraceUtil.addTraceInformation("(" + getPipe().getX() + ", " + getPipe().getY() + ", " + getPipe().getZ() + ")");
				StackTraceUtil.printTrace();
				info.end();
			}
			*/
        getPipe().spawnParticle(Particles.LightRedParticle, 5);
    }
    LPTickHandler.adjChecksDone++;
    boolean adjacentChanged = false;
    CoreRoutedPipe thisPipe = getPipe();
    if (thisPipe == null) {
        return false;
    }
    HashMap<CoreRoutedPipe, ExitRoute> adjacent;
    List<Pair<ILogisticsPowerProvider, List<IFilter>>> power;
    List<Pair<ISubSystemPowerProvider, List<IFilter>>> subSystemPower;
    PathFinder finder = new PathFinder(thisPipe.container, Configs.LOGISTICS_DETECTION_COUNT, Configs.LOGISTICS_DETECTION_LENGTH, localChangeListener);
    power = finder.powerNodes;
    subSystemPower = finder.subPowerProvider;
    adjacent = finder.result;
    Map<ForgeDirection, List<CoreRoutedPipe>> pipeDirections = new HashMap<>();
    for (Entry<CoreRoutedPipe, ExitRoute> entry : adjacent.entrySet()) {
        List<CoreRoutedPipe> list = pipeDirections.get(entry.getValue().exitOrientation);
        if (list == null) {
            list = new ArrayList<>();
            pipeDirections.put(entry.getValue().exitOrientation, list);
        }
        list.add(entry.getKey());
    }
    pipeDirections.entrySet().stream().filter(entry -> entry.getValue().size() > Configs.MAX_UNROUTED_CONNECTIONS).forEach(entry -> entry.getValue().forEach(adjacent::remove));
    listenedPipes.stream().filter(list -> !finder.listenedPipes.contains(list)).forEach(list -> list.remove(localChangeListener));
    listenedPipes = finder.listenedPipes;
    for (CoreRoutedPipe pipe : adjacent.keySet()) {
        if (pipe.stillNeedReplace()) {
            return false;
        }
    }
    boolean[] oldSideDisconnected = sideDisconnected;
    sideDisconnected = new boolean[6];
    checkSecurity(adjacent);
    boolean changed = false;
    for (int i = 0; i < 6; i++) {
        changed |= sideDisconnected[i] != oldSideDisconnected[i];
    }
    if (changed) {
        CoreRoutedPipe pipe = getPipe();
        if (pipe != null) {
            pipe.getWorld().notifyBlocksOfNeighborChange(pipe.getX(), pipe.getY(), pipe.getZ(), pipe.getWorld().getBlock(pipe.getX(), pipe.getY(), pipe.getZ()));
            pipe.refreshConnectionAndRender(false);
        }
        adjacentChanged = true;
    }
    if (_adjacent.size() != adjacent.size()) {
        adjacentChanged = true;
    }
    for (CoreRoutedPipe pipe : _adjacent.keySet()) {
        if (!adjacent.containsKey(pipe)) {
            adjacentChanged = true;
        }
    }
    if (_powerAdjacent != null) {
        if (power == null) {
            adjacentChanged = true;
        } else {
            for (Pair<ILogisticsPowerProvider, List<IFilter>> provider : _powerAdjacent) {
                if (!power.contains(provider)) {
                    adjacentChanged = true;
                }
            }
        }
    }
    if (power != null) {
        if (_powerAdjacent == null) {
            adjacentChanged = true;
        } else {
            for (Pair<ILogisticsPowerProvider, List<IFilter>> provider : power) {
                if (!_powerAdjacent.contains(provider)) {
                    adjacentChanged = true;
                }
            }
        }
    }
    if (_subSystemPowerAdjacent != null) {
        if (subSystemPower == null) {
            adjacentChanged = true;
        } else {
            for (Pair<ISubSystemPowerProvider, List<IFilter>> provider : _subSystemPowerAdjacent) {
                if (!subSystemPower.contains(provider)) {
                    adjacentChanged = true;
                }
            }
        }
    }
    if (subSystemPower != null) {
        if (_subSystemPowerAdjacent == null) {
            adjacentChanged = true;
        } else {
            for (Pair<ISubSystemPowerProvider, List<IFilter>> provider : subSystemPower) {
                if (!_subSystemPowerAdjacent.contains(provider)) {
                    adjacentChanged = true;
                }
            }
        }
    }
    for (Entry<CoreRoutedPipe, ExitRoute> pipe : adjacent.entrySet()) {
        ExitRoute oldExit = _adjacent.get(pipe.getKey());
        if (oldExit == null) {
            adjacentChanged = true;
            break;
        }
        ExitRoute newExit = pipe.getValue();
        if (!newExit.equals(oldExit)) {
            adjacentChanged = true;
            break;
        }
    }
    if (!oldTouchedPipes.equals(finder.touchedPipes)) {
        CacheHolder.clearCache(oldTouchedPipes);
        CacheHolder.clearCache(finder.touchedPipes);
        oldTouchedPipes = finder.touchedPipes;
        BitSet visited = new BitSet(ServerRouter.getBiggestSimpleID());
        visited.set(getSimpleID());
        act(visited, new floodClearCache());
    }
    if (adjacentChanged) {
        HashMap<IRouter, ExitRoute> adjacentRouter = new HashMap<>();
        EnumSet<ForgeDirection> routedexits = EnumSet.noneOf(ForgeDirection.class);
        EnumMap<ForgeDirection, Integer> subpowerexits = new EnumMap<>(ForgeDirection.class);
        for (Entry<CoreRoutedPipe, ExitRoute> pipe : adjacent.entrySet()) {
            adjacentRouter.put(pipe.getKey().getRouter(), pipe.getValue());
            if ((pipe.getValue().connectionDetails.contains(PipeRoutingConnectionType.canRouteTo) || pipe.getValue().connectionDetails.contains(PipeRoutingConnectionType.canRequestFrom) && !routedexits.contains(pipe.getValue().exitOrientation))) {
                routedexits.add(pipe.getValue().exitOrientation);
            }
            if (!subpowerexits.containsKey(pipe.getValue().exitOrientation) && pipe.getValue().connectionDetails.contains(PipeRoutingConnectionType.canPowerSubSystemFrom)) {
                subpowerexits.put(pipe.getValue().exitOrientation, PathFinder.messureDistanceToNextRoutedPipe(getLPPosition(), pipe.getValue().exitOrientation, pipe.getKey().getWorld()));
            }
        }
        _adjacent = Collections.unmodifiableMap(adjacent);
        _adjacentRouter_Old = _adjacentRouter;
        _adjacentRouter = Collections.unmodifiableMap(adjacentRouter);
        if (power != null) {
            _powerAdjacent = Collections.unmodifiableList(power);
        } else {
            _powerAdjacent = null;
        }
        if (subSystemPower != null) {
            _subSystemPowerAdjacent = Collections.unmodifiableList(subSystemPower);
        } else {
            _subSystemPowerAdjacent = null;
        }
        _routedExits = routedexits;
        _subPowerExits = subpowerexits;
        SendNewLSA();
    }
    return adjacentChanged;
}
Also used : LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) PriorityQueue(java.util.PriorityQueue) Quartet(logisticspipes.utils.tuples.Quartet) Particles(logisticspipes.pipefxhandlers.Particles) MainProxy(logisticspipes.proxy.MainProxy) ILogisticsPowerProvider(logisticspipes.api.ILogisticsPowerProvider) Configs(logisticspipes.config.Configs) StackTraceUtil(logisticspipes.utils.StackTraceUtil) Map(java.util.Map) ILPTEInformation(logisticspipes.asm.te.ILPTEInformation) EnumSet(java.util.EnumSet) ITileEntityChangeListener(logisticspipes.asm.te.ITileEntityChangeListener) EnumMap(java.util.EnumMap) FluidResource(logisticspipes.request.resources.FluidResource) CacheHolder(logisticspipes.utils.CacheHolder) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) Set(java.util.Set) LPTickHandler(logisticspipes.ticks.LPTickHandler) UUID(java.util.UUID) DictResource(logisticspipes.request.resources.DictResource) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Collectors(java.util.stream.Collectors) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) Info(logisticspipes.utils.StackTraceUtil.Info) List(java.util.List) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) IFilter(logisticspipes.interfaces.routing.IFilter) Pair(logisticspipes.utils.tuples.Pair) Entry(java.util.Map.Entry) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ItemResource(logisticspipes.request.resources.ItemResource) Setter(lombok.Setter) Getter(lombok.Getter) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) HashMap(java.util.HashMap) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ISubSystemPowerProvider(logisticspipes.interfaces.ISubSystemPowerProvider) AccessLevel(lombok.AccessLevel) IRoutingDebugAdapter(logisticspipes.interfaces.IRoutingDebugAdapter) LPTileEntityObject(logisticspipes.asm.te.LPTileEntityObject) PathFinder(logisticspipes.routing.pathfinder.PathFinder) OneList(logisticspipes.utils.OneList) WeakReference(java.lang.ref.WeakReference) LinkedList(java.util.LinkedList) LPConstants(logisticspipes.LPConstants) DimensionManager(net.minecraftforge.common.DimensionManager) RoutingTableUpdateThread(logisticspipes.ticks.RoutingTableUpdateThread) Iterator(java.util.Iterator) World(net.minecraft.world.World) IResource(logisticspipes.request.resources.IResource) Lock(java.util.concurrent.locks.Lock) PipeItemsFirewall(logisticspipes.pipes.PipeItemsFirewall) TileEntity(net.minecraft.tileentity.TileEntity) BitSet(java.util.BitSet) Collections(java.util.Collections) HashMap(java.util.HashMap) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ILogisticsPowerProvider(logisticspipes.api.ILogisticsPowerProvider) List(java.util.List) ArrayList(java.util.ArrayList) OneList(logisticspipes.utils.OneList) LinkedList(java.util.LinkedList) EnumMap(java.util.EnumMap) ISubSystemPowerProvider(logisticspipes.interfaces.ISubSystemPowerProvider) Pair(logisticspipes.utils.tuples.Pair) BitSet(java.util.BitSet) PathFinder(logisticspipes.routing.pathfinder.PathFinder) IFilter(logisticspipes.interfaces.routing.IFilter)

Example 10 with Pair

use of logisticspipes.utils.tuples.Pair in project LogisticsPipes by RS485.

the class LogisticsHUDRenderer method refreshList.

private void refreshList(double x, double y, double z) {
    ArrayList<Pair<Double, IHeadUpDisplayRendererProvider>> newList = new ArrayList<>();
    for (IRouter router : SimpleServiceLocator.routerManager.getRouters()) {
        if (router == null) {
            continue;
        }
        CoreRoutedPipe pipe = router.getPipe();
        if (!(pipe instanceof IHeadUpDisplayRendererProvider)) {
            continue;
        }
        if (MainProxy.getDimensionForWorld(pipe.getWorld()) == MainProxy.getDimensionForWorld(FMLClientHandler.instance().getClient().theWorld)) {
            double dis = Math.hypot(pipe.getX() - x + 0.5, Math.hypot(pipe.getY() - y + 0.5, pipe.getZ() - z + 0.5));
            if (dis < Configs.LOGISTICS_HUD_RENDER_DISTANCE && dis > 0.75) {
                newList.add(new Pair<>(dis, (IHeadUpDisplayRendererProvider) pipe));
                if (!list.contains(pipe)) {
                    ((IHeadUpDisplayRendererProvider) pipe).startWatching();
                }
            }
        }
    }
    List<IHeadUpDisplayBlockRendererProvider> remove = new ArrayList<>();
    providers.stream().filter(provider -> MainProxy.getDimensionForWorld(provider.getWorld()) == MainProxy.getDimensionForWorld(FMLClientHandler.instance().getClient().theWorld)).forEach(provider -> {
        double dis = Math.hypot(provider.getX() - x + 0.5, Math.hypot(provider.getY() - y + 0.5, provider.getZ() - z + 0.5));
        if (dis < Configs.LOGISTICS_HUD_RENDER_DISTANCE && dis > 0.75 && !provider.isHUDInvalid() && provider.isHUDExistent()) {
            newList.add(new Pair<>(dis, provider));
            if (!list.contains(provider)) {
                provider.startWatching();
            }
        } else if (provider.isHUDInvalid() || !provider.isHUDExistent()) {
            remove.add(provider);
        }
    });
    for (IHeadUpDisplayBlockRendererProvider provider : remove) {
        providers.remove(provider);
    }
    if (newList.size() < 1) {
        clearList(true);
        return;
    }
    Collections.sort(newList, (o1, o2) -> {
        if (o1.getValue1() < o2.getValue1()) {
            return -1;
        } else if (o1.getValue1() > o2.getValue1()) {
            return 1;
        } else {
            return 0;
        }
    });
    for (IHeadUpDisplayRendererProvider part : list) {
        boolean contains = false;
        for (Pair<Double, IHeadUpDisplayRendererProvider> inpart : newList) {
            if (inpart.getValue2().equals(part)) {
                contains = true;
                break;
            }
        }
        if (!contains) {
            part.stopWatching();
        }
    }
    clearList(false);
    for (Pair<Double, IHeadUpDisplayRendererProvider> part : newList) {
        list.addLast(part.getValue2());
    }
}
Also used : IRouter(logisticspipes.routing.IRouter) HUDConfig(logisticspipes.hud.HUDConfig) Keyboard(org.lwjgl.input.Keyboard) MainProxy(logisticspipes.proxy.MainProxy) Vector3d(logisticspipes.utils.math.Vector3d) Configs(logisticspipes.config.Configs) ArrayList(java.util.ArrayList) IHeadUpDisplayBlockRendererProvider(logisticspipes.interfaces.IHeadUpDisplayBlockRendererProvider) ItemStack(net.minecraft.item.ItemStack) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) Minecraft(net.minecraft.client.Minecraft) IHeadUpDisplayRendererProvider(logisticspipes.interfaces.IHeadUpDisplayRendererProvider) IHUDArmor(logisticspipes.api.IHUDArmor) FMLClientHandler(cpw.mods.fml.client.FMLClientHandler) GL11(org.lwjgl.opengl.GL11) LinkedList(java.util.LinkedList) EnumSet(java.util.EnumSet) PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) ScaledResolution(net.minecraft.client.gui.ScaledResolution) IHUDConfig(logisticspipes.interfaces.IHUDConfig) DisplayAmount(logisticspipes.utils.item.ItemStackRenderer.DisplayAmount) List(java.util.List) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) LaserData(logisticspipes.routing.LaserData) Tessellator(net.minecraft.client.renderer.Tessellator) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Pair(logisticspipes.utils.tuples.Pair) ResourceLocation(net.minecraft.util.ResourceLocation) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) GuiGraphics(logisticspipes.utils.gui.GuiGraphics) MovingObjectType(net.minecraft.util.MovingObjectPosition.MovingObjectType) Collections(java.util.Collections) ItemStackRenderer(logisticspipes.utils.item.ItemStackRenderer) GuiIngameForge(net.minecraftforge.client.GuiIngameForge) IDebugHUDProvider(logisticspipes.interfaces.IDebugHUDProvider) ArrayList(java.util.ArrayList) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) IHeadUpDisplayBlockRendererProvider(logisticspipes.interfaces.IHeadUpDisplayBlockRendererProvider) IHeadUpDisplayRendererProvider(logisticspipes.interfaces.IHeadUpDisplayRendererProvider) IRouter(logisticspipes.routing.IRouter) Pair(logisticspipes.utils.tuples.Pair)

Aggregations

Pair (logisticspipes.utils.tuples.Pair)27 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)13 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)11 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)11 ArrayList (java.util.ArrayList)10 List (java.util.List)9 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)8 Map (java.util.Map)7 IFilter (logisticspipes.interfaces.routing.IFilter)7 ExitRoute (logisticspipes.routing.ExitRoute)7 ItemStack (net.minecraft.item.ItemStack)7 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)7 HashMap (java.util.HashMap)6 LinkedList (java.util.LinkedList)6 Entry (java.util.Map.Entry)6 MainProxy (logisticspipes.proxy.MainProxy)6 IRouter (logisticspipes.routing.IRouter)6 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)6 IInventory (net.minecraft.inventory.IInventory)6 TileEntity (net.minecraft.tileentity.TileEntity)6