Example usage for net.minecraftforge.fluids IFluidBlock canDrain

List of usage examples for net.minecraftforge.fluids IFluidBlock canDrain

Introduction

In this page you can find the example usage for net.minecraftforge.fluids IFluidBlock canDrain.

Prototype

boolean canDrain(World world, BlockPos pos);

Source Link

Document

Check to see if a block can be drained.

Usage

From source file:buildcraft.lib.misc.BlockUtil.java

License:Minecraft Mod Public

public static FluidStack drainBlock(IBlockState state, World world, BlockPos pos, boolean doDrain) {
    Block block = state.getBlock();//from ww w .  ja  v a2s .com
    Fluid fluid = getFluidWithFlowing(block);

    if (fluid != null && FluidRegistry.isFluidRegistered(fluid)) {
        if (block instanceof IFluidBlock) {
            IFluidBlock fluidBlock = (IFluidBlock) block;
            if (!fluidBlock.canDrain(world, pos)) {
                return null;
            }
            return fluidBlock.drain(world, pos, doDrain);
        } else {
            // FIXME: this should probably check the level...
            int level = state.getValue(BlockLiquid.LEVEL);
            // if (level != 0) {
            // return null;
            // }

            if (doDrain) {
                world.setBlockToAir(pos);
            }

            return new FluidStack(fluid, 1000);
        }
    } else {
        return null;
    }
}