package frogcraftrebirth.api;

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

import javax.annotation.Nonnull;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.common.IFuelHandler;

/**
 * This FuelHanlder implementation will handle both vanilla fuel registration as
 * well as combustion furnace fuel and byproducts registration.
 * 
 * @see frogcraftrebirth.common.tile.TileCombustionFurnace
 * @author 3TUSK
 */
public final class FrogFuelHandler implements IFuelHandler {

	// Though deprecated, one bucket = 1000 milli-bucket is still a
	// common-agreed standard.
	public static final int BUCKET_VOLUME = 1000;

	FrogFuelHandler() {
	}

	@Override
	public int getBurnTime(ItemStack fuel) {
		for (Entry<ItemStack, Integer> entry : fuelMap.entrySet()) {
			if (fuel.isItemEqual(entry.getKey()))
				return entry.getValue().intValue();
		}
		return 0;
	}

	public FluidStack getFluidByproduct(@Nonnull ItemStack aStack) {
		for (Entry<ItemStack, FluidStack> entry : fuel2FluidMap.entrySet()) {
			if (aStack.isItemEqual(entry.getKey()))
				return entry.getValue();
		}
		return null;
	}

	public ItemStack getItemByproduct(@Nonnull ItemStack aStack) {
		for (Entry<ItemStack, ItemStack> entry : fuel2ByproductMap.entrySet()) {
			if (aStack.isItemEqual(entry.getKey()))
				return entry.getValue();
		}
		return null;
	}

	public void regFuel(@Nonnull Item fuel, int timeInTicks) {
		regFuel(new ItemStack(fuel, 1), timeInTicks);
	}

	public void regFuel(@Nonnull ItemStack fuel, int timeInTicks) {
		fuelMap.put(fuel, timeInTicks < 0 ? 0 : timeInTicks);
	}

	public void regFuelByproduct(@Nonnull ItemStack fuel, @Nonnull Fluid byproduct) {
		regFuelByproduct(fuel, new FluidStack(byproduct, BUCKET_VOLUME));
	}

	public void regFuelByproduct(@Nonnull ItemStack fuel, @Nonnull FluidStack byproduct) {
		fuel2FluidMap.put(fuel, byproduct);
	}

	public void regFuelByproduct(@Nonnull ItemStack fuel, @Nonnull ItemStack byproduct) {
		fuel2ByproductMap.put(fuel, byproduct);
	}

	private Map<ItemStack, Integer> fuelMap = new HashMap<ItemStack, Integer>();
	private Map<ItemStack, FluidStack> fuel2FluidMap = new HashMap<ItemStack, FluidStack>();
	private Map<ItemStack, ItemStack> fuel2ByproductMap = new HashMap<ItemStack, ItemStack>();
}

@@ -41,16 +41,22 @@
 va.util.
+Linked
 HashMap;
@@ -139,16 +139,50 @@
 Nonnull;
+%0Aimport javax.annotation.Nullable;
 %0A%0Aimport
@@ -467,23 +467,56 @@
 ion 
-as
 %0A * 
-well as c
+in a more generic way; it will also handle C
 ombu
@@ -521,17 +521,17 @@
 bustion 
-f
+F
 urnace f
@@ -538,16 +538,20 @@
 uel and 
+%0A * 
 byproduc
@@ -630,16 +630,83 @@
 Furnace%0A
+ * @see net.minecraft.tileentity.TileEntityFurnace#getItemBurnTime%0A
  * @auth
@@ -786,98 +786,124 @@
 %0A%0A%09/
-/ Though deprecated, one bucket = 1000 milli-bucket is still a%0A%09// common-agreed standard.
+**%0A%09 * Use 1000mB as default volume.%0A%09 * @see FrogFuelHandler#regFuelByproduct(ItemStack fuel, Fluid byproduct)%0A%09 */
 %0A%09pu
@@ -1185,24 +1185,35 @@
 turn 0;%0A%09%7D%0A%0A
+%09@Nullable%0A
 %09public Flui
@@ -1231,38 +1231,39 @@
 luidByproduct(@N
-onn
 ull
+able
  ItemStack aStac
@@ -1259,32 +1259,70 @@
 Stack aStack) %7B%0A
+%09%09if (aStack == null)%0A%09%09%09return null;%0A
 %09%09for (Entry%3CIte
@@ -1464,32 +1464,43 @@
 eturn null;%0A%09%7D%0A%0A
+%09@Nullable%0A
 %09public ItemStac
@@ -1512,38 +1512,39 @@
 ItemByproduct(@N
-onn
 ull
+able
  ItemStack aStac
@@ -1544,24 +1544,62 @@
 k aStack) %7B%0A
+%09%09if (aStack == null)%0A%09%09%09return null;%0A
 %09%09for (Entry
@@ -2412,32 +2412,38 @@
 );%0A%09%7D%0A%0A%09private 
+final 
 Map%3CItemStack, I
@@ -2456,32 +2456,38 @@
 %3E fuelMap = new 
+Linked
 HashMap%3CItemStac
@@ -2502,32 +2502,38 @@
 er%3E();%0A%09private 
+final 
 Map%3CItemStack, F
@@ -2555,32 +2555,38 @@
 2FluidMap = new 
+Linked
 HashMap%3CItemStac
@@ -2612,16 +2612,22 @@
 private 
+final 
 Map%3CItem
@@ -2668,16 +2668,22 @@
 p = new 
+Linked
 HashMap%3C

Tweak on FrogFuelHandler