Search in sources :

Example 1 with InvertedFluidFilter

use of buildcraft.lib.inventory.filter.InvertedFluidFilter in project BuildCraft by BuildCraft.

the class PipeBehaviourWoodDiamond method extractFluid.

@Override
protected FluidStack extractFluid(IFlowFluid flow, EnumFacing dir, int millibuckets, boolean simulate) {
    if (filters.getStackInSlot(currentFilter).isEmpty()) {
        advanceFilter();
    }
    switch(filterMode) {
        default:
        case WHITE_LIST:
            if (filters.extract(s -> true, 1, 1, true).isEmpty()) {
                return flow.tryExtractFluid(millibuckets, dir, null, simulate);
            }
            // Firstly try the advanced version - if that fails we will need to try the basic version
            ActionResult<FluidStack> result = flow.tryExtractFluidAdv(millibuckets, dir, new ArrayFluidFilter(filters.stacks), simulate);
            FluidStack extracted = result.getResult();
            if (result.getType() != EnumActionResult.PASS) {
                return extracted;
            }
            if (extracted == null || extracted.amount <= 0) {
                for (int i = 0; i < filters.getSlots(); i++) {
                    ItemStack stack = filters.getStackInSlot(i);
                    if (stack.isEmpty()) {
                        continue;
                    }
                    extracted = flow.tryExtractFluid(millibuckets, dir, FluidUtil.getFluidContained(stack), simulate);
                    if (extracted != null && extracted.amount > 0) {
                        return extracted;
                    }
                }
            }
            return null;
        case BLACK_LIST:
            // We cannot fallback to the basic version - only use the advanced version
            InvertedFluidFilter filter = new InvertedFluidFilter(new ArrayFluidFilter(filters.stacks));
            return flow.tryExtractFluidAdv(millibuckets, dir, filter, simulate).getResult();
        case ROUND_ROBIN:
            // We can't do this -- amounts might differ and its just ugly
            return null;
    }
}
Also used : FluidUtil(net.minecraftforge.fluids.FluidUtil) InvertedStackFilter(buildcraft.lib.inventory.filter.InvertedStackFilter) ItemHandlerSimple(buildcraft.lib.tile.item.ItemHandlerSimple) BCTransportGuis(buildcraft.transport.BCTransportGuis) IFlowItems(buildcraft.api.transport.pipe.IFlowItems) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) IStackFilter(buildcraft.api.core.IStackFilter) Side(net.minecraftforge.fml.relauncher.Side) PipeMessageReceiver(buildcraft.api.transport.pipe.IPipeHolder.PipeMessageReceiver) StackFilter(buildcraft.lib.inventory.filter.StackFilter) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IItemPluggable(buildcraft.api.transport.IItemPluggable) DelegatingItemHandlerFilter(buildcraft.lib.inventory.filter.DelegatingItemHandlerFilter) EnumFacing(net.minecraft.util.EnumFacing) IOException(java.io.IOException) ActionResult(net.minecraft.util.ActionResult) IFlowFluid(buildcraft.api.transport.pipe.IFlowFluid) EntityUtil(buildcraft.lib.misc.EntityUtil) MessageContext(net.minecraftforge.fml.common.network.simpleimpl.MessageContext) InvertedFluidFilter(buildcraft.lib.inventory.filter.InvertedFluidFilter) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EnumActionResult(net.minecraft.util.EnumActionResult) StackUtil(buildcraft.lib.misc.StackUtil) FluidStack(net.minecraftforge.fluids.FluidStack) ArrayFluidFilter(buildcraft.lib.inventory.filter.ArrayFluidFilter) PacketBuffer(net.minecraft.network.PacketBuffer) EnumPipePart(buildcraft.api.core.EnumPipePart) IPipe(buildcraft.api.transport.pipe.IPipe) InvertedFluidFilter(buildcraft.lib.inventory.filter.InvertedFluidFilter) FluidStack(net.minecraftforge.fluids.FluidStack) ArrayFluidFilter(buildcraft.lib.inventory.filter.ArrayFluidFilter) ItemStack(net.minecraft.item.ItemStack)

Aggregations

EnumPipePart (buildcraft.api.core.EnumPipePart)1 IStackFilter (buildcraft.api.core.IStackFilter)1 IItemPluggable (buildcraft.api.transport.IItemPluggable)1 IFlowFluid (buildcraft.api.transport.pipe.IFlowFluid)1 IFlowItems (buildcraft.api.transport.pipe.IFlowItems)1 IPipe (buildcraft.api.transport.pipe.IPipe)1 PipeMessageReceiver (buildcraft.api.transport.pipe.IPipeHolder.PipeMessageReceiver)1 ArrayFluidFilter (buildcraft.lib.inventory.filter.ArrayFluidFilter)1 DelegatingItemHandlerFilter (buildcraft.lib.inventory.filter.DelegatingItemHandlerFilter)1 InvertedFluidFilter (buildcraft.lib.inventory.filter.InvertedFluidFilter)1 InvertedStackFilter (buildcraft.lib.inventory.filter.InvertedStackFilter)1 StackFilter (buildcraft.lib.inventory.filter.StackFilter)1 EntityUtil (buildcraft.lib.misc.EntityUtil)1 StackUtil (buildcraft.lib.misc.StackUtil)1 ItemHandlerSimple (buildcraft.lib.tile.item.ItemHandlerSimple)1 BCTransportGuis (buildcraft.transport.BCTransportGuis)1 IOException (java.io.IOException)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1