package reborncore.common.util;

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;

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

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)
	{
		if(world.getBlockState(pos.getBlockPos()) != null) {
			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;
			}
		}else{
			return null;
		}
	}

}

@@ -674,18 +674,17 @@
 ibeEvent
-%0A%09
+ 
 public v
@@ -956,16 +956,17 @@
 %0A%09%7B%0A%09%09if
+ 
 (world.g
@@ -1001,25 +1001,27 @@
 ()) != null)
- 
+%0A%09%09
 %7B%0A%09%09%09IBlockS
@@ -1134,17 +1134,20 @@
 != null)
- 
+%0A%09%09%09
 %7B%0A%09%09%09%09wo
@@ -1227,17 +1227,20 @@
 %09%09%7D else
- 
+%0A%09%09%09
 %7B%0A%09%09%09%09re
@@ -1258,20 +1258,24 @@
 %09%09%09%7D%0A%09%09%7D
+ 
 else
+%0A%09%09
 %7B%0A%09%09%09ret

Fix Bucket handling and format. Closes TechReborn/TechReborn#398