public ItemStack tryPlaceContainedLiquid( World world, ItemStack bucket, int x, int y, int z, int side) { if (world.isRemote) return bucket; CarbonContainer item = (CarbonContainer) bucket.getItem(); int id = bucket.getItemDamage(); if (id != 0) { if (!item.canPlaceInWorld) return bucket; FluidStack liquid = LiquidRegistry.getLiquid(id); if (world.setBlock(x, y, z, liquid.getFluid().getBlock(), 0, 3)) return item.getContainerItem(bucket); return bucket; } if (!item.canBeFilledFromWorld) return bucket; Block block = world.getBlock(x, y, z); if (block instanceof IFluidBlock) { FluidStack liquid = ((IFluidBlock) block).drain(world, x, y, z, false); if (liquid != null && FluidRegistry.isFluidRegistered(liquid.getFluid())) { ItemStack r = FluidContainerRegistry.fillFluidContainer(liquid, bucket); if (r != null && FluidContainerRegistry.isFilledContainer(r)) { ((IFluidBlock) block).drain(world, x, y, z, true); return r; } } } return bucket; }
public static FluidStack drainBlock( Block block, World world, int x, int y, int z, boolean doDrain) { if (block instanceof IFluidBlock) { IFluidBlock fluidBlock = (IFluidBlock) block; if (fluidBlock.canDrain(world, x, y, z)) return fluidBlock.drain(world, x, y, z, doDrain); } else if (block == Blocks.water || block == Blocks.flowing_water) { int meta = world.getBlockMetadata(x, y, z); if (meta != 0) return null; if (doDrain) world.setBlockToAir(x, y, z); return new FluidStack(FluidRegistry.WATER, FluidContainerRegistry.BUCKET_VOLUME); } else if (block == Blocks.lava || block == Blocks.flowing_lava) { int meta = world.getBlockMetadata(x, y, z); if (meta != 0) return null; if (doDrain) world.setBlockToAir(x, y, z); return new FluidStack(FluidRegistry.LAVA, FluidContainerRegistry.BUCKET_VOLUME); } return null; }