package reborncore.common.util;

import java.util.HashMap;
import java.util.Map;

import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.FillBucketEvent;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class BucketHandler
{

	public static BucketHandler INSTANCE = new BucketHandler();
	public Map<IBlockState, Item> buckets = new HashMap<IBlockState, Item>();

	private BucketHandler()
	{

	}

	@SubscribeEvent
	public void onBucketFill(FillBucketEvent event)
	{
		ItemStack result = fillCustomBucket(event.getWorld(), event.getTarget());

		if (result == null)
			return;

		event.setResult(Event.Result.ALLOW);
	}

	private ItemStack fillCustomBucket(World world, RayTraceResult pos)
	{
		IBlockState state = world.getBlockState(pos.getBlockPos());

		Item bucket = buckets.get(state);

		if (bucket != null)
		{
			world.setBlockToAir(pos.getBlockPos());
			return new ItemStack(bucket);
		} else
		{
			return null;
		}
	}

}

@@ -30,57 +30,8 @@
 l;%0A%0A
-import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 impo
@@ -409,16 +409,65 @@
 Event;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 public c
@@ -953,16 +953,72 @@
 pos)%0A%09%7B%0A
+%09%09if(world.getBlockState(pos.getBlockPos()) != null) %7B%0A%09
 %09%09IBlock
@@ -1074,16 +1074,17 @@
 ());%0A%0A%09%09
+%09
 Item buc
@@ -1108,24 +1108,25 @@
 (state);%0A%0A%09%09
+%09
 if (bucket !
@@ -1132,21 +1132,20 @@
 != null)
-%0A%09%09
+ 
 %7B%0A
+%09
 %09%09%09world
@@ -1178,24 +1178,25 @@
 kPos());%0A%09%09%09
+%09
 return new I
@@ -1217,16 +1217,17 @@
 t);%0A
+%09
 %09%09%7D else
 %0A%09%09%7B
@@ -1222,19 +1222,48 @@
 %09%09%7D else
+ %7B
 %0A%09%09
+%09%09return null;%0A%09%09%09%7D%0A%09%09%7Delse
 %7B%0A%09%09%09ret

Fix bucket handling, closes #398