Search in sources :

Example 1 with IFluidFilter

use of buildcraft.api.core.IFluidFilter in project BuildCraft by BuildCraft.

the class BoardRobotFluidCarrier method update.

@Override
public void update() {
    if (!robotHasFluid()) {
        IFluidFilter filter = ActionRobotFilter.getGateFluidFilter(robot.getLinkedStation());
        startDelegateAI(new AIRobotGotoStationAndLoadFluids(robot, filter));
    } else {
        startDelegateAI(new AIRobotGotoStationAndUnloadFluids(robot));
    }
}
Also used : IFluidFilter(buildcraft.api.core.IFluidFilter) AIRobotGotoStationAndUnloadFluids(buildcraft.robotics.ai.AIRobotGotoStationAndUnloadFluids) AIRobotGotoStationAndLoadFluids(buildcraft.robotics.ai.AIRobotGotoStationAndLoadFluids)

Example 2 with IFluidFilter

use of buildcraft.api.core.IFluidFilter in project BuildCraft by BuildCraft.

the class FluidUtilBC method move.

/**
 * @param max The maximum amount of fluid to move.
 * @return The fluidstack that was moved, or null if no fluid was moved.
 */
@Nullable
public static FluidStack move(IFluidHandler from, IFluidHandler to, int max) {
    if (from == null || to == null) {
        return null;
    }
    FluidStack toDrainPotential;
    if (from instanceof IFluidHandlerAdv) {
        IFluidFilter filter = f -> to.fill(f, false) > 0;
        toDrainPotential = ((IFluidHandlerAdv) from).drain(filter, max, false);
    } else {
        toDrainPotential = from.drain(max, false);
    }
    int accepted = to.fill(toDrainPotential, false);
    if (accepted <= 0) {
        return null;
    }
    FluidStack toDrain = new FluidStack(toDrainPotential, accepted);
    FluidStack drained = from.drain(toDrain, true);
    if (!toDrain.isFluidEqual(drained) || toDrain.amount != drained.amount) {
        String detail = "(To Drain = " + StringUtilBC.fluidToString(toDrain);
        detail += ",\nactually drained = " + StringUtilBC.fluidToString(drained) + ")";
        detail += ",\nIFluidHandler (from) = " + from.getClass() + "(" + from + ")";
        detail += ",\nIFluidHandler (to) = " + to.getClass() + "(" + to + ")";
        throw new IllegalStateException("Drained fluid did not equal expected fluid!\n" + detail);
    }
    int actuallyAccepted = to.fill(drained, true);
    if (actuallyAccepted != accepted) {
        String detail = "(actually accepted = " + actuallyAccepted + ", accepted = " + accepted + ")";
        throw new IllegalStateException("Mismatched IFluidHandler implementations!\n" + detail);
    }
    return new FluidStack(drained, accepted);
}
Also used : FluidUtil(net.minecraftforge.fluids.FluidUtil) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) World(net.minecraft.world.World) EnumHand(net.minecraft.util.EnumHand) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) ArrayList(java.util.ArrayList) Tank(buildcraft.lib.fluid.Tank) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) ItemHandlerHelper(net.minecraftforge.items.ItemHandlerHelper) IFluidHandlerAdv(buildcraft.api.core.IFluidHandlerAdv) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IFluidFilter(buildcraft.api.core.IFluidFilter) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) Fluid(net.minecraftforge.fluids.Fluid) TileEntity(net.minecraft.tileentity.TileEntity) FluidStack(net.minecraftforge.fluids.FluidStack) Nullable(javax.annotation.Nullable) IBlockAccess(net.minecraft.world.IBlockAccess) IFluidFilter(buildcraft.api.core.IFluidFilter) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidHandlerAdv(buildcraft.api.core.IFluidHandlerAdv) Nullable(javax.annotation.Nullable)

Aggregations

IFluidFilter (buildcraft.api.core.IFluidFilter)2 IFluidHandlerAdv (buildcraft.api.core.IFluidHandlerAdv)1 Tank (buildcraft.lib.fluid.Tank)1 AIRobotGotoStationAndLoadFluids (buildcraft.robotics.ai.AIRobotGotoStationAndLoadFluids)1 AIRobotGotoStationAndUnloadFluids (buildcraft.robotics.ai.AIRobotGotoStationAndUnloadFluids)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Nullable (javax.annotation.Nullable)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1 EnumHand (net.minecraft.util.EnumHand)1 BlockPos (net.minecraft.util.math.BlockPos)1 IBlockAccess (net.minecraft.world.IBlockAccess)1 World (net.minecraft.world.World)1 Fluid (net.minecraftforge.fluids.Fluid)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 FluidUtil (net.minecraftforge.fluids.FluidUtil)1 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)1