package sstow.handler;

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

import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import sstow.gameObjs.ObjHandler;
import sstow.utils.Config;

public class ForgeRecipes {
	private static final ForgeRecipes SMELTING_BASE = new ForgeRecipes();

	private Map smeltingList = new HashMap();
	private Map experienceList = new HashMap();

	public static ForgeRecipes smelting() {
		return SMELTING_BASE;
	}

	private ForgeRecipes() {
		this.addRecipe(Items.diamond, new ItemStack(ObjHandler.SOUL_SHARD,
				Config.SHARDS), 1F);
		this.addRecipe(Items.iron_ingot, new ItemStack(
				ObjHandler.SOULIUM_NUGGET, Config.NUGGETS), 0.8F);
		this.addRecipe(Blocks.iron_block, new ItemStack(
				ObjHandler.SOULIUM_INGOT, 8), 0.9F);
	}

	public void addRecipe(Item item, ItemStack itemstack, float experience) {
		this.addLists(item, itemstack, experience);
	}

	public void addRecipe(Block block, ItemStack itemstack, float experience) {
		this.addLists(block, itemstack, experience);
	}

	public void addLists(Block block, ItemStack itemstack, float experience) {
		this.putLists(new ItemStack(block, 1, 32767), itemstack, experience);
	}

	public void addLists(Item item, ItemStack itemstack, float experience) {
		this.putLists(new ItemStack(item, 1, 32767), itemstack, experience);
	}

	public void putLists(ItemStack itemstack, ItemStack itemstack2,
			float experience) {
		this.smeltingList.put(itemstack, itemstack2);
		this.experienceList.put(itemstack2, Float.valueOf(experience));
	}

	public ItemStack getSmeltingResult(ItemStack itemstack) {
		Iterator iterator = this.smeltingList.entrySet().iterator();
		Entry entry;

		do {
			if (!iterator.hasNext()) {
				return null;
			}
			entry = (Entry) iterator.next();
		} while (!canBeSmelted(itemstack, (ItemStack) entry.getKey()));
		return (ItemStack) entry.getValue();
	}

	private boolean canBeSmelted(ItemStack itemstack, ItemStack itemstack2) {
		return itemstack2.getItem() == itemstack.getItem()
				&& (itemstack2.getItemDamage() == 32767 || itemstack2
						.getItemDamage() == itemstack.getItemDamage());
	}

	public float giveExperience(ItemStack itemstack) {
		Iterator iterator = this.experienceList.entrySet().iterator();
		Entry entry;

		do {
			if (!iterator.hasNext()) {
				return 0.0f;
			}

			entry = (Entry) iterator.next();
		} while (!this.canBeSmelted(itemstack, (ItemStack) entry.getKey()));

		if (itemstack.getItem().getSmeltingExperience(itemstack) != -1) {
			return itemstack.getItem().getSmeltingExperience(itemstack);
		}

		return ((Float) entry.getValue()).floatValue();
	}
}

@@ -650,24 +650,38 @@
 s.addRecipe(
+new ItemStack(
 Items.diamon
@@ -681,16 +681,17 @@
 .diamond
+)
 , new It
@@ -698,16 +698,21 @@
 emStack(
+%0A%09%09%09%09
 ObjHandl
@@ -725,21 +725,17 @@
 L_SHARD,
-%0A%09%09%09%09
+ 
 Config.S
@@ -760,24 +760,38 @@
 s.addRecipe(
+new ItemStack(
 Items.iron_i
@@ -794,16 +794,17 @@
 on_ingot
+)
 , new It
@@ -880,24 +880,38 @@
 s.addRecipe(
+new ItemStack(
 Blocks.iron_
@@ -915,16 +915,17 @@
 on_block
+)
 , new It
@@ -963,17 +963,29 @@
 _INGOT, 
-8
+Config.INGOTS
 ), 0.9F)
@@ -1021,668 +1021,96 @@
 Item
- item, ItemStack itemstack, float experience) %7B%0A%09%09this.addLists(item, itemstack, experience);%0A%09%7D%0A%0A%09public void addRecipe(Block block, ItemStack itemstack, float experience) %7B%0A%09%09this.addLists(block, itemstack, experience);%0A%09%7D%0A%0A%09public void addLists(Block block, ItemStack itemstack, float experience) %7B%0A%09%09this.putLists(new ItemStack(block, 1, 32767), itemstack, experience);%0A%09%7D%0A%0A%09public void addLists(Item item, ItemStack itemstack, float experience) %7B%0A%09%09this.putLists(new ItemStack(item, 1, 32767), itemstack, experience);%0A%09%7D%0A%0A%09public void putLists(ItemStack itemstack, ItemStack itemstack2,%0A%09%09%09float experience) %7B%0A%09%09this.smeltingList.put(itemstack, itemstack2
+Stack input, ItemStack output, float experience) %7B%0A%09%09this.smeltingList.put(input, output
 );%0A%09
@@ -1134,26 +1134,22 @@
 ist.put(
-itemstack2
+output
 , Float.

Update ForgeRecipes.java