Search in sources :

Example 1 with FluidIdentifier

use of logisticspipes.utils.FluidIdentifier 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 (this.getUpgradeManager().isFuzzyUpgrade() && outputFuzzyFlags.getBitSet().nextSetBit(0) != -1) {
        if (toCraft instanceof DictResource) {
            for (ItemIdentifierStack craftable : stack) {
                DictResource dict = new DictResource(craftable, null);
                dict.loadFromBitSet(outputFuzzyFlags.getBitSet());
                if (toCraft.matches(craftable.getItem(), IResource.MatchSettings.NORMAL) && dict.matches(((DictResource) toCraft).getItem(), IResource.MatchSettings.NORMAL) && dict.getBitSet().equals(((DictResource) toCraft).getBitSet())) {
                    template = new DictCraftingTemplate(dict, this, priority);
                    break;
                }
            }
        }
    } else {
        for (ItemIdentifierStack craftable : stack) {
            if (toCraft.matches(craftable.getItem(), IResource.MatchSettings.NORMAL)) {
                template = new ItemCraftingTemplate(craftable, this, priority);
                break;
            }
        }
    }
    if (template == null) {
        return null;
    }
    IRequestItems[] target = new IRequestItems[9];
    for (int i = 0; i < 9; i++) {
        target[i] = this;
    }
    boolean hasSatellite = isSatelliteConnected();
    if (!hasSatellite) {
        return null;
    }
    if (!getUpgradeManager().isAdvancedSatelliteCrafter()) {
        if (satelliteId != 0) {
            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++) {
            if (advancedSatelliteIdArray[i] != 0) {
                IRouter r = getSatelliteRouter(i);
                if (r != null) {
                    target[i] = r.getPipe();
                }
            }
        }
    }
    //Check all materials
    for (int i = 0; i < 9; i++) {
        ItemIdentifierStack resourceStack = getMaterials(i);
        if (resourceStack == null || resourceStack.getStackSize() == 0) {
            continue;
        }
        IResource req = null;
        if (getUpgradeManager().isFuzzyUpgrade() && fuzzyCraftingFlagArray[i].getBitSet().nextSetBit(0) != -1) {
            DictResource dict;
            req = dict = new DictResource(resourceStack, target[i]);
            dict.loadFromBitSet(fuzzyCraftingFlagArray[i].getBitSet());
        } else {
            req = new ItemResource(resourceStack, target[i]);
        }
        template.addRequirement(req, new CraftingChassieInformation(i, getPositionInt()));
    }
    int liquidCrafter = getUpgradeManager().getFluidCrafter();
    IRequestFluid[] liquidTarget = new IRequestFluid[liquidCrafter];
    if (!getUpgradeManager().isAdvancedSatelliteCrafter()) {
        if (liquidSatelliteId != 0) {
            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++) {
            if (liquidSatelliteIdArray[i] != 0) {
                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 = getFluidAmount()[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 FluidIdentifier

use of logisticspipes.utils.FluidIdentifier in project LogisticsPipes by RS485.

the class PipeFluidBasic method sinkAmount.

@Override
public int sinkAmount(FluidStack stack) {
    if (!guiOpenedBy.isEmpty()) {
        //Don't sink when the gui is open
        return 0;
    }
    FluidIdentifier ident = FluidIdentifier.get(stack);
    if (filterInv.getStackInSlot(0) == null) {
        return 0;
    }
    if (!ident.equals(FluidIdentifier.get(filterInv.getIDStackInSlot(0).getItem()))) {
        return 0;
    }
    int onTheWay = this.countOnRoute(ident);
    int freeSpace = -onTheWay;
    for (Pair<TileEntity, ForgeDirection> pair : getAdjacentTanks(true)) {
        FluidTank tank = ((PipeFluidTransportLogistics) transport).sideTanks[pair.getValue2().ordinal()];
        freeSpace += ident.getFreeSpaceInsideTank((IFluidHandler) pair.getValue1(), pair.getValue2().getOpposite());
        freeSpace += ident.getFreeSpaceInsideTank(tank);
        if (freeSpace >= stack.amount) {
            return stack.amount;
        }
    }
    return freeSpace;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidTank(net.minecraftforge.fluids.FluidTank) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) FluidIdentifier(logisticspipes.utils.FluidIdentifier) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 3 with FluidIdentifier

use of logisticspipes.utils.FluidIdentifier in project LogisticsPipes by RS485.

the class PipeFluidProvider method getAvailableFluids.

@Override
public Map<FluidIdentifier, Integer> getAvailableFluids() {
    Map<FluidIdentifier, Integer> map = new HashMap<>();
    for (Pair<TileEntity, ForgeDirection> pair : getAdjacentTanks(false)) {
        boolean fallback = true;
        if (SimpleServiceLocator.specialTankHandler.hasHandlerFor(pair.getValue1())) {
            ISpecialTankHandler handler = SimpleServiceLocator.specialTankHandler.getTankHandlerFor(pair.getValue1());
            if (handler instanceof ISpecialTankAccessHandler) {
                fallback = false;
                Map<FluidIdentifier, Long> tmp = ((ISpecialTankAccessHandler) handler).getAvailableLiquid(pair.getValue1());
                for (Entry<FluidIdentifier, Long> entry : tmp.entrySet()) {
                    if (map.containsKey(entry.getKey())) {
                        long addition = ((long) map.get(entry.getKey())) + entry.getValue();
                        map.put(entry.getKey(), addition > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) addition);
                    } else {
                        map.put(entry.getKey(), entry.getValue() > Integer.MAX_VALUE ? Integer.MAX_VALUE : entry.getValue().intValue());
                    }
                }
            }
        }
        if (fallback) {
            FluidTankInfo[] tanks = ((IFluidHandler) pair.getValue1()).getTankInfo(pair.getValue2().getOpposite());
            if (tanks != null) {
                for (FluidTankInfo tank : tanks) {
                    if (tank == null) {
                        continue;
                    }
                    FluidStack liquid;
                    if ((liquid = tank.fluid) != null && liquid.getFluidID() != 0) {
                        FluidIdentifier ident = FluidIdentifier.get(liquid);
                        if (((IFluidHandler) pair.getValue1()).canDrain(pair.getValue2().getOpposite(), liquid.getFluid())) {
                            if (((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), 1, false) != null) {
                                if (map.containsKey(ident)) {
                                    long addition = ((long) map.get(ident)) + tank.fluid.amount;
                                    map.put(ident, addition > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) addition);
                                } else {
                                    map.put(ident, tank.fluid.amount);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    Map<FluidIdentifier, Integer> result = new HashMap<>();
    //Reduce what has been reserved, add.
    for (Entry<FluidIdentifier, Integer> fluid : map.entrySet()) {
        int remaining = fluid.getValue() - getFluidOrderManager().totalFluidsCountInOrders(fluid.getKey());
        if (remaining < 1) {
            continue;
        }
        result.put(fluid.getKey(), remaining);
    }
    return result;
}
Also used : ISpecialTankHandler(logisticspipes.interfaces.ISpecialTankHandler) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) HashMap(java.util.HashMap) FluidStack(net.minecraftforge.fluids.FluidStack) ISpecialTankAccessHandler(logisticspipes.interfaces.ISpecialTankAccessHandler) FluidIdentifier(logisticspipes.utils.FluidIdentifier) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) TileEntity(net.minecraft.tileentity.TileEntity) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 4 with FluidIdentifier

use of logisticspipes.utils.FluidIdentifier in project LogisticsPipes by RS485.

the class BuildCraftTankHandler method getAvailableLiquid.

@Override
public Map<FluidIdentifier, Long> getAvailableLiquid(TileEntity tile) {
    Map<FluidIdentifier, Long> map = new HashMap<>();
    FluidTankInfo[] tanks = ((IFluidHandler) tile).getTankInfo(ForgeDirection.UNKNOWN);
    for (FluidTankInfo tank : tanks) {
        if (tank == null) {
            continue;
        }
        FluidStack liquid;
        if ((liquid = tank.fluid) != null && liquid.getFluidID() != 0) {
            FluidIdentifier ident = FluidIdentifier.get(liquid);
            if (((IFluidHandler) tile).drain(ForgeDirection.UNKNOWN, 1, false) != null) {
                if (map.containsKey(ident)) {
                    long addition = map.get(ident) + tank.fluid.amount;
                    map.put(ident, addition);
                } else {
                    map.put(ident, (long) tank.fluid.amount);
                }
            }
        }
    }
    return map;
}
Also used : FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) HashMap(java.util.HashMap) FluidStack(net.minecraftforge.fluids.FluidStack) FluidIdentifier(logisticspipes.utils.FluidIdentifier) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 5 with FluidIdentifier

use of logisticspipes.utils.FluidIdentifier in project LogisticsPipes by RS485.

the class LogisticsFluidManager method getAvailableFluid.

@Override
public TreeSet<ItemIdentifierStack> getAvailableFluid(List<ExitRoute> validDestinations) {
    Map<FluidIdentifier, Integer> allAvailableItems = new HashMap<>();
    for (ExitRoute r : validDestinations) {
        if (r == null) {
            continue;
        }
        if (!r.containsFlag(PipeRoutingConnectionType.canRequestFrom)) {
            continue;
        }
        if (!(r.destination.getPipe() instanceof IProvideFluids)) {
            continue;
        }
        IProvideFluids provider = (IProvideFluids) r.destination.getPipe();
        Map<FluidIdentifier, Integer> allItems = provider.getAvailableFluids();
        for (Entry<FluidIdentifier, Integer> liquid : allItems.entrySet()) {
            Integer amount = allAvailableItems.get(liquid.getKey());
            if (amount == null) {
                allAvailableItems.put(liquid.getKey(), liquid.getValue());
            } else {
                long addition = ((long) amount) + liquid.getValue();
                if (addition > Integer.MAX_VALUE) {
                    addition = Integer.MAX_VALUE;
                }
                allAvailableItems.put(liquid.getKey(), (int) addition);
            }
        }
    }
    TreeSet<ItemIdentifierStack> itemIdentifierStackList = allAvailableItems.entrySet().stream().map(item -> new ItemIdentifierStack(item.getKey().getItemIdentifier(), item.getValue())).collect(Collectors.toCollection(TreeSet::new));
    return itemIdentifierStackList;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) IRouter(logisticspipes.routing.IRouter) LogisticsPipes(logisticspipes.LogisticsPipes) IFluidSink(logisticspipes.interfaces.routing.IFluidSink) HashMap(java.util.HashMap) LogisticsFluidContainer(logisticspipes.items.LogisticsFluidContainer) Collectors(java.util.stream.Collectors) ExitRoute(logisticspipes.routing.ExitRoute) TreeSet(java.util.TreeSet) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) FluidIdentifier(logisticspipes.utils.FluidIdentifier) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) Map(java.util.Map) Pair(logisticspipes.utils.tuples.Pair) Entry(java.util.Map.Entry) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) FluidStack(net.minecraftforge.fluids.FluidStack) IProvideFluids(logisticspipes.interfaces.routing.IProvideFluids) HashMap(java.util.HashMap) IProvideFluids(logisticspipes.interfaces.routing.IProvideFluids) FluidIdentifier(logisticspipes.utils.FluidIdentifier) ExitRoute(logisticspipes.routing.ExitRoute) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

Aggregations

FluidIdentifier (logisticspipes.utils.FluidIdentifier)13 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)7 FluidStack (net.minecraftforge.fluids.FluidStack)7 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)7 HashMap (java.util.HashMap)6 FluidTankInfo (net.minecraftforge.fluids.FluidTankInfo)6 TileEntity (net.minecraft.tileentity.TileEntity)5 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)4 Map (java.util.Map)3 Entry (java.util.Map.Entry)3 LogisticsPipes (logisticspipes.LogisticsPipes)3 ISpecialTankAccessHandler (logisticspipes.interfaces.ISpecialTankAccessHandler)3 ISpecialTankHandler (logisticspipes.interfaces.ISpecialTankHandler)3 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)3 ItemStack (net.minecraft.item.ItemStack)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 TreeSet (java.util.TreeSet)2 GuiIDs (logisticspipes.network.GuiIDs)2 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)2 MainProxy (logisticspipes.proxy.MainProxy)2