Search in sources :

Example 1 with FluidResource

use of logisticspipes.request.resources.FluidResource 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 2 with FluidResource

use of logisticspipes.request.resources.FluidResource in project LogisticsPipes by RS485.

the class ServerRouter method getRoutersInterestedIn.

public static BitSet getRoutersInterestedIn(IResource item) {
    if (item instanceof ItemResource) {
        return ServerRouter.getRoutersInterestedIn(((ItemResource) item).getItem());
    } else if (item instanceof FluidResource) {
        return ServerRouter.getRoutersInterestedIn(((FluidResource) item).getFluid().getItemIdentifier());
    } else if (item instanceof DictResource) {
        DictResource dict = (DictResource) item;
        BitSet s = new BitSet(ServerRouter.getBiggestSimpleID() + 1);
        for (IRouter r : ServerRouter.genericInterests) {
            s.set(r.getSimpleID());
        }
        ServerRouter.globalSpecificInterests.entrySet().stream().filter(entry -> dict.matches(entry.getKey(), IResource.MatchSettings.NORMAL)).flatMap(entry -> entry.getValue().stream()).forEach(router -> s.set(router.simpleID));
        return s;
    }
    return new BitSet(ServerRouter.getBiggestSimpleID() + 1);
}
Also used : PriorityQueue(java.util.PriorityQueue) LogisticsPipes(logisticspipes.LogisticsPipes) 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) LogisticsModule(logisticspipes.modules.LogisticsModule) Map(java.util.Map) ObjectSets(it.unimi.dsi.fastutil.objects.ObjectSets) 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) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) NavigableSet(java.util.NavigableSet) LPTickHandler(logisticspipes.ticks.LPTickHandler) UUID(java.util.UUID) DictResource(logisticspipes.request.resources.DictResource) Collectors(java.util.stream.Collectors) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) Info(logisticspipes.utils.StackTraceUtil.Info) List(java.util.List) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) Stream(java.util.stream.Stream) 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) 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) IRoutingDebugAdapter(logisticspipes.interfaces.IRoutingDebugAdapter) BiConsumer(java.util.function.BiConsumer) LPTileEntityObject(logisticspipes.asm.te.LPTileEntityObject) PathFinder(logisticspipes.routing.pathfinder.PathFinder) OneList(logisticspipes.utils.OneList) WeakReference(java.lang.ref.WeakReference) LinkedList(java.util.LinkedList) Nonnull(javax.annotation.Nonnull) DimensionManager(net.minecraftforge.common.DimensionManager) RoutingTableUpdateThread(logisticspipes.ticks.RoutingTableUpdateThread) ReentrantLock(java.util.concurrent.locks.ReentrantLock) World(net.minecraft.world.World) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) 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) FluidResource(logisticspipes.request.resources.FluidResource) DictResource(logisticspipes.request.resources.DictResource) BitSet(java.util.BitSet) ItemResource(logisticspipes.request.resources.ItemResource)

Example 3 with FluidResource

use of logisticspipes.request.resources.FluidResource in project LogisticsPipes by RS485.

the class RequestTree method requestFluid.

private static int requestFluid(FluidIdentifier liquid, int amount, IRequestFluid pipe, RequestLog log, boolean acceptPartial) {
    FluidResource req = new FluidResource(liquid, amount, pipe);
    RequestTree request = new RequestTree(req, null, RequestTree.defaultRequestFlags, null);
    if (request.isDone() || acceptPartial) {
        request.fullFill();
        if (log != null) {
            log.handleSucessfullRequestOf(req.copyForDisplayWith(req.getRequestedAmount()), null);
        }
        return request.getPromiseAmount();
    } else {
        if (log != null) {
            request.sendMissingMessage(log);
        }
        return request.getPromiseAmount();
    }
}
Also used : FluidResource(logisticspipes.request.resources.FluidResource)

Example 4 with FluidResource

use of logisticspipes.request.resources.FluidResource in project LogisticsPipes by RS485.

the class PipeFluidProvider method canProvide.

@Override
public void canProvide(RequestTreeNode tree, RequestTree root, List<IFilter> filter) {
    if (tree.isDone()) {
        return;
    }
    if (!(tree.getRequestType() instanceof FluidResource)) {
        return;
    }
    FluidIdentifier fluid = ((FluidResource) tree.getRequestType()).getFluid();
    AtomicInteger containedAmount = new AtomicInteger(0);
    for (Pair<NeighborTileEntity<TileEntity>, ITankUtil> pair : PipeFluidUtil.INSTANCE.getAdjacentTanks(this, false)) {
        boolean fallback = true;
        if (pair.getValue2() instanceof ISpecialTankUtil) {
            final ISpecialTankUtil util = (ISpecialTankUtil) pair.getValue2();
            fallback = false;
            ISpecialTankAccessHandler handler = util.getSpecialHandler();
            TileEntity tile = util.getTileEntity();
            Map<FluidIdentifier, Long> map = handler.getAvailableLiquid(tile);
            if (map.containsKey(fluid)) {
                long addition = (containedAmount.get()) + map.get(fluid);
                containedAmount.set(addition > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) addition);
            }
        }
        if (fallback) {
            if (pair.getValue2().containsTanks()) {
                pair.getValue2().tanks().map(tank -> FluidIdentifierStack.getFromStack(tank.getContents())).forEach(liquid -> {
                    if (liquid != null && liquid.getFluid() != null) {
                        if (fluid.equals(liquid.getFluid())) {
                            if (pair.getValue2().canDrain(liquid.getFluid())) {
                                if (pair.getValue2().drain(liquid.getFluid().makeFluidIdentifierStack(1), false) != null) {
                                    long addition = ((long) containedAmount.get()) + liquid.getAmount();
                                    containedAmount.set(addition > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) addition);
                                }
                            }
                        }
                    }
                });
            }
        }
    }
    FluidLogisticsPromise promise = new FluidLogisticsPromise();
    promise.liquid = fluid;
    promise.amount = Math.min(tree.getMissingAmount(), containedAmount.get() - root.getAllPromissesFor(this, fluid.getItemIdentifier()));
    promise.sender = this;
    promise.type = ResourceType.PROVIDER;
    if (promise.amount > 0) {
        tree.addPromise(promise);
    }
}
Also used : ISpecialTankAccessHandler(logisticspipes.interfaces.ISpecialTankAccessHandler) LogisticsFluidOrder(logisticspipes.routing.order.LogisticsFluidOrder) NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) IRequestFluid(logisticspipes.interfaces.routing.IRequestFluid) IOrderInfoProvider(logisticspipes.routing.order.IOrderInfoProvider) Textures(logisticspipes.textures.Textures) Item(net.minecraft.item.Item) HashMap(java.util.HashMap) ResourceType(logisticspipes.routing.order.IOrderInfoProvider.ResourceType) FluidIdentifier(logisticspipes.utils.FluidIdentifier) FluidIdentifierStack(logisticspipes.utils.FluidIdentifierStack) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Nonnull(javax.annotation.Nonnull) IProvideFluids(logisticspipes.interfaces.routing.IProvideFluids) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation) ISpecialTankUtil(logisticspipes.interfaces.ISpecialTankUtil) Collection(java.util.Collection) FluidResource(logisticspipes.request.resources.FluidResource) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) TextureType(logisticspipes.textures.Textures.TextureType) RequestTreeNode(logisticspipes.request.RequestTreeNode) TransportMode(logisticspipes.logisticspipes.IRoutedItem.TransportMode) RequestTree(logisticspipes.request.RequestTree) List(java.util.List) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) IFilter(logisticspipes.interfaces.routing.IFilter) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ITankUtil(logisticspipes.interfaces.ITankUtil) Pair(logisticspipes.utils.tuples.Pair) Entry(java.util.Map.Entry) TileEntity(net.minecraft.tileentity.TileEntity) FluidStack(net.minecraftforge.fluids.FluidStack) FluidLogisticsPromise(logisticspipes.routing.FluidLogisticsPromise) FluidRoutedPipe(logisticspipes.pipes.basic.fluid.FluidRoutedPipe) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) ISpecialTankAccessHandler(logisticspipes.interfaces.ISpecialTankAccessHandler) FluidIdentifier(logisticspipes.utils.FluidIdentifier) NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ITankUtil(logisticspipes.interfaces.ITankUtil) FluidResource(logisticspipes.request.resources.FluidResource) ISpecialTankUtil(logisticspipes.interfaces.ISpecialTankUtil) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NeighborTileEntity(network.rs485.logisticspipes.connection.NeighborTileEntity) FluidLogisticsPromise(logisticspipes.routing.FluidLogisticsPromise)

Aggregations

FluidResource (logisticspipes.request.resources.FluidResource)4 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Nonnull (javax.annotation.Nonnull)2 IFilter (logisticspipes.interfaces.routing.IFilter)2 IRequestFluid (logisticspipes.interfaces.routing.IRequestFluid)2 DictResource (logisticspipes.request.resources.DictResource)2 IResource (logisticspipes.request.resources.IResource)2 ItemResource (logisticspipes.request.resources.ItemResource)2 ObjectSets (it.unimi.dsi.fastutil.objects.ObjectSets)1 WeakReference (java.lang.ref.WeakReference)1 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 EnumMap (java.util.EnumMap)1 EnumSet (java.util.EnumSet)1 HashSet (java.util.HashSet)1