Search in sources :

Example 11 with IRouter

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

the class ModuleCrafter method addCrafting.

@Override
public ICraftingTemplate addCrafting(IResource toCraft) {
    List<ItemIdentifierStack> stack = getCraftedItems();
    if (stack == null) {
        return null;
    }
    IReqCraftingTemplate template = null;
    if (getUpgradeManager().isFuzzyUpgrade() && outputFuzzy().nextSetBit(0) != -1) {
        for (ItemIdentifierStack craftable : stack) {
            DictResource dict = new DictResource(craftable, null);
            dict.loadFromBitSet(outputFuzzy().copyValue());
            if (toCraft.matches(dict, IResource.MatchSettings.NORMAL)) {
                template = new DictCraftingTemplate(dict, this, priority.getValue());
                break;
            }
        }
    } else {
        for (ItemIdentifierStack craftable : stack) {
            if (toCraft.matches(craftable.getItem(), IResource.MatchSettings.NORMAL)) {
                template = new ItemCraftingTemplate(craftable, this, priority.getValue());
                break;
            }
        }
    }
    if (template == null) {
        return null;
    }
    IRequestItems[] target = new IRequestItems[9];
    for (int i = 0; i < 9; i++) {
        target[i] = this;
    }
    if (!isSatelliteConnected()) {
        // has a satellite configured and that one is unreachable
        return null;
    }
    if (!getUpgradeManager().isAdvancedSatelliteCrafter()) {
        IRouter r = getSatelliteRouter(-1);
        if (r != null) {
            IRequestItems sat = r.getPipe();
            for (int i = 6; i < 9; i++) {
                target[i] = sat;
            }
        }
    } else {
        for (int i = 0; i < 9; i++) {
            IRouter r = getSatelliteRouter(i);
            if (r != null) {
                target[i] = r.getPipe();
            }
        }
    }
    // Check all materials
    for (int i = 0; i < 9; i++) {
        ItemIdentifierStack resourceStack = dummyInventory.getIDStackInSlot(i);
        if (resourceStack == null || resourceStack.getStackSize() == 0) {
            continue;
        }
        IResource req;
        if (getUpgradeManager().isFuzzyUpgrade() && inputFuzzy(i).nextSetBit(0) != -1) {
            DictResource dict;
            req = dict = new DictResource(resourceStack, target[i]);
            dict.loadFromBitSet(inputFuzzy(i).copyValue());
        } else {
            req = new ItemResource(resourceStack, target[i]);
        }
        template.addRequirement(req, new CraftingChassisInformation(i, getPositionInt()));
    }
    int liquidCrafter = getUpgradeManager().getFluidCrafter();
    IRequestFluid[] liquidTarget = new IRequestFluid[liquidCrafter];
    if (!getUpgradeManager().isAdvancedSatelliteCrafter()) {
        IRouter r = getFluidSatelliteRouter(-1);
        if (r != null) {
            IRequestFluid sat = (IRequestFluid) r.getPipe();
            for (int i = 0; i < liquidCrafter; i++) {
                liquidTarget[i] = sat;
            }
        }
    } else {
        for (int i = 0; i < liquidCrafter; i++) {
            IRouter r = getFluidSatelliteRouter(i);
            if (r != null) {
                liquidTarget[i] = (IRequestFluid) r.getPipe();
            }
        }
    }
    for (int i = 0; i < liquidCrafter; i++) {
        FluidIdentifier liquid = getFluidMaterial(i);
        int amount = liquidAmounts.get(i);
        if (liquid == null || amount <= 0 || liquidTarget[i] == null) {
            continue;
        }
        template.addRequirement(new FluidResource(liquid, amount, liquidTarget[i]), null);
    }
    if (getUpgradeManager().hasByproductExtractor() && getByproductItem() != null) {
        template.addByproduct(getByproductItem());
    }
    return template;
}
Also used : DictResource(logisticspipes.request.resources.DictResource) DictCraftingTemplate(logisticspipes.request.DictCraftingTemplate) IReqCraftingTemplate(logisticspipes.request.IReqCraftingTemplate) FluidIdentifier(logisticspipes.utils.FluidIdentifier) ItemResource(logisticspipes.request.resources.ItemResource) FluidResource(logisticspipes.request.resources.FluidResource) IRouter(logisticspipes.routing.IRouter) IRequestFluid(logisticspipes.interfaces.routing.IRequestFluid) ItemCraftingTemplate(logisticspipes.request.ItemCraftingTemplate) IRequestItems(logisticspipes.interfaces.routing.IRequestItems) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) IResource(logisticspipes.request.resources.IResource)

Example 12 with IRouter

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

the class CoreRoutedPipe method sendRoutedItem.

private void sendRoutedItem(IRoutedItem routedItem, EnumFacing from) {
    if (from == null) {
        throw new NullPointerException();
    }
    transport.injectItem(routedItem, from.getOpposite());
    IRouter r = SimpleServiceLocator.routerManager.getServerRouter(routedItem.getDestination());
    if (r != null) {
        CoreRoutedPipe pipe = r.getCachedPipe();
        if (pipe != null) {
            pipe.notifyOfSend(routedItem.getInfo());
        }
    // else TODO: handle sending items to known chunk-unloaded destination?
    }
    // should not be able to send to a non-existing router
    // router.startTrackingRoutedItem((RoutedEntityItem) routedItem.getTravelingItem());
    spawnParticle(Particles.OrangeParticle, 2);
    stat_lifetime_sent++;
    stat_session_sent++;
    updateStats();
}
Also used : IRouter(logisticspipes.routing.IRouter)

Example 13 with IRouter

use of logisticspipes.routing.IRouter 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<EnumFacing, IPipeSign>> pipeSigns = cachedPipe.getPipeSigns();
                pipeSigns.stream().filter(signPair -> signPair != null && signPair.getValue2() instanceof ItemAmountPipeSign).forEach(signPair -> ((ItemAmountPipeSign) signPair.getValue2()).updateStats(availableItems, set));
            }
        }
    }
}
Also used : TextUtil(network.rs485.logisticspipes.util.TextUtil) IRouter(logisticspipes.routing.IRouter) Item(net.minecraft.item.Item) MainProxy(logisticspipes.proxy.MainProxy) ItemStack(net.minecraft.item.ItemStack) Side(net.minecraftforge.fml.relauncher.Side) Map(java.util.Map) LogisticsRenderPipe(logisticspipes.renderer.LogisticsRenderPipe) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) ItemAmountSignUpdatePacket(logisticspipes.network.packets.pipe.ItemAmountSignUpdatePacket) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ModernPacket(logisticspipes.network.abstractpackets.ModernPacket) NewGuiHandler(logisticspipes.network.NewGuiHandler) PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) ItemAmountSignGui(logisticspipes.network.guis.item.ItemAmountSignGui) GlStateManager(net.minecraft.client.renderer.GlStateManager) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) EnumFacing(net.minecraft.util.EnumFacing) PacketHandler(logisticspipes.network.PacketHandler) ExitRoute(logisticspipes.routing.ExitRoute) ServerRouter(logisticspipes.routing.ServerRouter) List(java.util.List) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) ISimpleInventoryEventHandler(logisticspipes.utils.ISimpleInventoryEventHandler) FontRenderer(net.minecraft.client.gui.FontRenderer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IInventory(net.minecraft.inventory.IInventory) Pair(logisticspipes.utils.tuples.Pair) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) BitSet(java.util.BitSet) IRouter(logisticspipes.routing.IRouter) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ExitRoute(logisticspipes.routing.ExitRoute) Pair(logisticspipes.utils.tuples.Pair)

Example 14 with IRouter

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

the class LogisticsPowerProviderTileEntity method sendPowerLaserPackets.

private void sendPowerLaserPackets(IRouter sourceRouter, IRouter destinationRouter, EnumFacing exitOrientation, boolean addBall) {
    if (sourceRouter == destinationRouter) {
        return;
    }
    LinkedList<Triplet<IRouter, EnumFacing, Boolean>> todo = new LinkedList<>();
    todo.add(new Triplet<>(sourceRouter, exitOrientation, addBall));
    while (!todo.isEmpty()) {
        Triplet<IRouter, EnumFacing, Boolean> part = todo.pollFirst();
        List<ExitRoute> exits = part.getValue1().getRoutersOnSide(part.getValue2());
        for (ExitRoute exit : exits) {
            if (exit.containsFlag(PipeRoutingConnectionType.canPowerSubSystemFrom)) {
                // Find only result (caused by only straight connections)
                int distance = part.getValue1().getDistanceToNextPowerPipe(exit.exitOrientation);
                CoreRoutedPipe pipe = part.getValue1().getPipe();
                if (pipe != null && pipe.isInitialized()) {
                    pipe.container.addLaser(exit.exitOrientation, distance, getLaserColor(), false, part.getValue3());
                }
                // Use new sourceRouter
                IRouter nextRouter = exit.destination;
                if (nextRouter == destinationRouter) {
                    return;
                }
                outerRouters: for (ExitRoute newExit : nextRouter.getDistanceTo(destinationRouter)) {
                    if (newExit.containsFlag(PipeRoutingConnectionType.canPowerSubSystemFrom)) {
                        for (IFilter filter : newExit.filters) {
                            if (filter.blockPower()) {
                                continue outerRouters;
                            }
                        }
                        todo.addLast(new Triplet<>(nextRouter, newExit.exitOrientation, newExit.exitOrientation != exit.exitOrientation));
                    }
                }
            }
        }
    }
}
Also used : Triplet(logisticspipes.utils.tuples.Triplet) EnumFacing(net.minecraft.util.EnumFacing) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) LinkedList(java.util.LinkedList) IRouter(logisticspipes.routing.IRouter) IFilter(logisticspipes.interfaces.routing.IFilter) ExitRoute(logisticspipes.routing.ExitRoute)

Example 15 with IRouter

use of logisticspipes.routing.IRouter 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 (pipe.getWorld().provider.getDimension() == FMLClientHandler.instance().getClient().world.provider.getDimension()) {
            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 -> provider.getWorldForHUD().provider.getDimension() == FMLClientHandler.instance().getClient().world.provider.getDimension()).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;
    }
    newList.sort(Comparator.comparing(Pair::getValue1));
    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) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) HUDConfig(logisticspipes.hud.HUDConfig) Keyboard(org.lwjgl.input.Keyboard) Vector3d(logisticspipes.utils.math.Vector3d) Configs(logisticspipes.config.Configs) ArrayList(java.util.ArrayList) IHeadUpDisplayBlockRendererProvider(logisticspipes.interfaces.IHeadUpDisplayBlockRendererProvider) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) Minecraft(net.minecraft.client.Minecraft) Side(net.minecraftforge.fml.relauncher.Side) IHeadUpDisplayRendererProvider(logisticspipes.interfaces.IHeadUpDisplayRendererProvider) IHUDArmor(logisticspipes.api.IHUDArmor) GL11(org.lwjgl.opengl.GL11) LinkedList(java.util.LinkedList) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nonnull(javax.annotation.Nonnull) 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) FMLClientHandler(net.minecraftforge.fml.client.FMLClientHandler) 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) Comparator(java.util.Comparator) 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

IRouter (logisticspipes.routing.IRouter)32 ExitRoute (logisticspipes.routing.ExitRoute)19 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)16 ArrayList (java.util.ArrayList)15 LinkedList (java.util.LinkedList)13 List (java.util.List)12 IFilter (logisticspipes.interfaces.routing.IFilter)10 PipeRoutingConnectionType (logisticspipes.routing.PipeRoutingConnectionType)8 Pair (logisticspipes.utils.tuples.Pair)7 ItemStack (net.minecraft.item.ItemStack)7 BitSet (java.util.BitSet)6 HashMap (java.util.HashMap)6 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)6 Map (java.util.Map)5 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)5 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)5 EnumFacing (net.minecraft.util.EnumFacing)5 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)4 IResource (logisticspipes.request.resources.IResource)4 LaserData (logisticspipes.routing.LaserData)4