public static ItemStack fillBucket(World world, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
int bMeta = world.getBlockMetadata(x, y, z);
if (!buckets.containsKey(new BlockWrapper(block, bMeta))) {
if (block.equals(Blocks.water) || block.equals(Blocks.flowing_water)) {
if (world.getBlockMetadata(x, y, z) == 0) {
world.setBlockToAir(x, y, z);
return new ItemStack(Items.water_bucket);
}
return null;
} else if (block.equals(Blocks.lava) || block.equals(Blocks.flowing_lava)) {
if (world.getBlockMetadata(x, y, z) == 0) {
world.setBlockToAir(x, y, z);
return new ItemStack(Items.lava_bucket);
}
return null;
}
if (block instanceof IFluidBlock) {
IFluidBlock flBlock = (IFluidBlock) block;
if (flBlock.canDrain(world, x, y, z)) {
ItemStack stack = new ItemStack(Items.bucket);
stack = FluidContainerRegistry.fillFluidContainer(flBlock.drain(world, x, y, z, false), stack);
if (stack != null) {
flBlock.drain(world, x, y, z, true);
return stack;
}
}
}
return null;
}
if (!world.setBlockToAir(x, y, z)) {
return null;
}
ItemWrapper result = buckets.get(new BlockWrapper(block, bMeta));
return new ItemStack(result.item, 1, result.metadata);
}