package net.battlefield;

import java.util.logging.Level;

import net.minecraft.src.BiomeGenBase;
import net.minecraft.src.Block;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.EnumCreatureType;
import net.minecraft.src.EnumToolMaterial;
import net.minecraft.src.Item;
import net.minecraft.src.ItemDye;
import net.minecraft.src.ItemStack;
import net.minecraft.src.Material;
import net.minecraft.src.ModLoader;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.EnumHelper;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.IWorldGenerator;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.asm.SideOnly;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid = "battlefield", name="Battlefield Mod", version = "1.1", dependencies="required-after:FML@[4.2.18,)")
@NetworkMod(channels = { "battlefield" }, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketHandler.class)
public class Battlefield 
{
	private static final EnumToolMaterial EnumToolMaterialKnife = null;
	@SidedProxy(clientSide = "net.battlefield.ClientProxy", serverSide = "net.battlefield.CommonProxy")
	public static net.battlefield.CommonProxy proxy;
	@Instance("battlefield")
	public static Battlefield instance;
	
	int[] itemIDs = new int[30];
	int[] blockIDs = new int[30];
				
	public static Item CamouflageDye; 
	public static Item Pistol;
	public static Item RocketLauncher;
	public static Item ScarL;
	public static Item L85; 
	public static Item M4;
	public static Item M16; 
	public static Item Famas;
	public static Item L96A1;
	public static Item G3;
	public static Item Knife;
	public static Item Ammunition; 
	public static Block Camouflage;
	public static Block SilverOre;
	public static Block ThatchedRoof;
	public static Item SilverIngot;
	public static Item Rocket; 

	@PreInit
    @SideOnly(Side.CLIENT)
	public void preLoad(FMLPreInitializationEvent event)
	{
		MinecraftForge.EVENT_BUS.register(new AudioHandler());
	}
	
	@Init
	public void load(FMLInitializationEvent Event)
	{
		init();
		proxy.registerRenderInformation();
		registerBlocks();
		addNames();
	}

	public void init()
	{
		//itemCarbine = (new BaseItemGun(itemIDs[15], 100, 100, Max amount of shots, Amount of recoil, Strength of the shot)).setIconCoord(0, 1).setItemName("itemCarbine");
		CamouflageDye = (new ForgeBaseItem(itemIDs[0], 64, CreativeTabs.tabMisc, true)).setIconCoord(0, 0).setItemName("CamouflageDye");
		RocketLauncher = (new ItemLauncher(itemIDs[1])) .setIconCoord(9,0) .setItemName("RocketLauncher") .setIconCoord(9,0) .setItemName("RocketLauncher");
		Rocket = (new ForgeBaseItem(itemIDs[2], 64, CreativeTabs.tabCombat, true)) .setIconCoord(10,0) .setItemName("Rocket");
		Pistol = (new BaseItemPistol(itemIDs[3], 100, 100, 800, 4, 0.02D)) .setIconCoord(6,0) .setItemName("Pistol");
		ScarL = (new BaseItemGun(itemIDs[4], 100, 100, 800, 2, 0.04D)).setIconCoord(3, 0).setItemName("ScarL");
		L85 = (new BaseItemGun(itemIDs[5], 100, 100, 800, 3, 0.3D)).setIconCoord(7, 0).setItemName("L85");
		M4 = (new BaseItemGun(itemIDs[6], 100, 100, 1650, 3, 0.03D)).setIconCoord(0, 1).setItemName("M4");
		M16 = (new BaseItemGun(itemIDs[7], 100, 100, 1200, 1, 0.03D)).setIconCoord(5, 0).setItemName("M16");
		Famas = (new BaseItemGun(itemIDs[8], 100, 100, 800, 3, 0.04D)).setIconCoord(8, 0).setItemName("Famas");
		L96A1 = (new BaseItemSniper(itemIDs[9], 100, 100, 648, 19, 0.8D)).setIconCoord(4, 0).setItemName("L96A1");
		G3 = (new BaseItemGun(itemIDs[10], 100, 100, 1900, 1, 0.02D)).setIconCoord(1, 0).setItemName("G3");
		Knife = (new ForgeBaseItem(itemIDs[11], 1, CreativeTabs.tabCombat, true)).setIconCoord(2, 0).setItemName("Knife");
		Ammunition = (new ForgeBaseItem(itemIDs[12], 64, CreativeTabs.tabCombat, true)).setIconCoord(1, 1).setItemName("Ammunition");
	    SilverIngot= (new ForgeBaseItem(itemIDs[13], 64, CreativeTabs.tabMaterials, true)).setIconCoord(6, 1).setItemName("SilverIngot");
	    SilverOre = (new ForgeBaseBlock(blockIDs[0], 0, Material.iron)).setHardness(2.0F).setResistance(2.0F).setBlockName("SilverOre");
		Camouflage = (new ForgeBaseBlock(blockIDs[1], 1, Material.cloth)).setHardness(1.9F).setResistance(1.3F).setBlockName("Camouflage");
		ThatchedRoof = (new ForgeBaseBlock(blockIDs[2], 2, Material.cloth)).setHardness(1.9F).setResistance(1.3F).setBlockName("ThatchedRoof");
		}
	private Item setIconCoord(int i, int j) {
		// TODO Auto-generated method stub
		return null;
	}

	@PreInit
	public void preInit(FMLPreInitializationEvent evt){
		Configuration Config = new Configuration(evt.getSuggestedConfigurationFile());
		try{
			Config.load();
		//Item IDs
			 itemIDs[0] = Config.get("CamouflageDye", Config.CATEGORY_ITEM, 2800).getInt();
			 itemIDs[1] = Config.get("RocketLauncher", Config.CATEGORY_ITEM, 2813).getInt();
			 itemIDs[2] = Config.get("Pistol", Config.CATEGORY_ITEM, 2814).getInt();
			 itemIDs[3] = Config.get("ScarL", Config.CATEGORY_ITEM, 2802).getInt();
			 itemIDs[4] = Config.get("L85", Config.CATEGORY_ITEM, 2803).getInt();
			 itemIDs[5] = Config.get("M4", Config.CATEGORY_ITEM, 2804).getInt();
			 itemIDs[6] = Config.get("M16", Config.CATEGORY_ITEM, 2805).getInt();
			 itemIDs[7] = Config.get("G3", Config.CATEGORY_ITEM, 2810).getInt();
			 itemIDs[8] = Config.get("Famas", Config.CATEGORY_ITEM, 2806).getInt();
			 itemIDs[9] = Config.get("L96A1", Config.CATEGORY_ITEM, 2807).getInt();
			 itemIDs[10] = Config.get("Knife", Config.CATEGORY_ITEM, 2808).getInt();
			 itemIDs[11] = Config.get("Ammunition", Config.CATEGORY_ITEM, 2809).getInt();
			 itemIDs[12] = Config.get("SilverIngot", Config.CATEGORY_ITEM, 2812).getInt();
			 itemIDs[13] = Config.get("Rocket", Config.CATEGORY_ITEM, 2815).getInt();
			 
		//Block IDs
			 blockIDs[0] = Config.get("SilverOre", Config.CATEGORY_BLOCK, 2811).getInt();
			 blockIDs[1] = Config.get("Camouflage", Config.CATEGORY_BLOCK, 2801).getInt();
			 blockIDs[2] = Config.get("ThatchedRoof", Config.CATEGORY_BLOCK, 2816).getInt();
			
		}catch (Exception e){
			FMLLog.log(Level.SEVERE, e, "A mod had a problem loading its configuration file.");
		}finally{
			Config.save();
		}
	}
	
	public void addNames()
	{
		LanguageRegistry.addName(ThatchedRoof, "ThatchedRoof");
		LanguageRegistry.addName(Rocket, "Rocket");
		LanguageRegistry.addName(CamouflageDye, "Camouflage Dye");
		LanguageRegistry.addName(Camouflage, "Camouflage");
		LanguageRegistry.addName(RocketLauncher, "RocketLauncher");
		LanguageRegistry.addName(Pistol, "Pistol");
		LanguageRegistry.addName(ScarL, "ScarL");
		LanguageRegistry.addName(L85, "L85");
		LanguageRegistry.addName(M4, "M4");
		LanguageRegistry.addName(M16, "M16");
		LanguageRegistry.addName(Famas, "Famas");
		LanguageRegistry.addName(L96A1, "L96A1");
		LanguageRegistry.addName(G3, "G3");
		LanguageRegistry.addName(Knife, "Knife");
		LanguageRegistry.addName(Ammunition, "Ammunition");
		LanguageRegistry.addName(SilverOre, "SilverOre");
		LanguageRegistry.addName(SilverIngot, "SilverIngot");
	}
    //tools and armorl
	{

		
	}
	
	public void registerBlocks()
	//GameRegistry
	{
		GameRegistry.registerBlock(Camouflage);
		GameRegistry.registerBlock(SilverOre);
		GameRegistry.registerBlock(ThatchedRoof);
		GameRegistry.addSmelting(SilverOre.blockID, new ItemStack(SilverIngot), 1);
		GameRegistry.addRecipe(new ItemStack(ThatchedRoof, 16), new Object[] {"111", "222", "111", Character.valueOf('1'),  new ItemStack(Item.wheat, 1), Character.valueOf('2'), new ItemStack(Item.silk)});
		GameRegistry.addRecipe(new ItemStack(CamouflageDye, 1), new Object[] {"***", "*12", "***", Character.valueOf('1'), new ItemStack(Item.dyePowder, 1, 2), Character.valueOf('2'), new ItemStack(Item.dyePowder,1,14)});
		GameRegistry.addRecipe(new ItemStack(Camouflage, 1), new Object[] {"***", "*11", "*11", Character.valueOf('1'), this.CamouflageDye});
		GameRegistry.addRecipe(new ItemStack(Pistol, 1), new Object[] {"11*", "12*", "***", Character.valueOf('1'),  new ItemStack(Item.ingotIron, 1), Character.valueOf('2'), new ItemStack(Item.stick)});
		GameRegistry.addRecipe(new ItemStack(RocketLauncher, 1), new Object[] {"111", "222", "111", Character.valueOf('1'),  new ItemStack(Item.ingotIron, 1), Character.valueOf('2'), new ItemStack(Item.gunpowder)});
		GameRegistry.addRecipe(new ItemStack(Rocket, 4), new Object[] {"*1*", "*2*", "212", Character.valueOf('1'),  new ItemStack(Item.ingotIron, 1), Character.valueOf('2'), new ItemStack(Item.gunpowder)});
		GameRegistry.addRecipe(new ItemStack(Famas, 1), new Object[] {"111", "12*", "***", Character.valueOf('1'), new ItemStack(Item.ingotIron, 1), Character.valueOf('2'), new ItemStack(Item.stick)});
		GameRegistry.addRecipe(new ItemStack(M16, 1), new Object[] {"113", "12*", "***", Character.valueOf('1'),  new ItemStack(Item.ingotIron, 1), Character.valueOf('2'), new ItemStack(Item.stick), Character.valueOf('3'), new ItemStack(Item.gunpowder)});
		GameRegistry.addRecipe(new ItemStack(M4, 1), new Object[] {"111", "12*", "3**", Character.valueOf('1'),  new ItemStack(Item.ingotIron, 1), Character.valueOf('2'), new ItemStack(Item.stick), Character.valueOf('3'), new ItemStack(Item.gunpowder)});
		GameRegistry.addRecipe(new ItemStack(G3, 1), new Object[] {"311", "12*", "3**", Character.valueOf('1'),  new ItemStack(Item.ingotIron, 1), Character.valueOf('2'), new ItemStack(Item.stick), Character.valueOf('3'), new ItemStack(Item.gunpowder)});
		GameRegistry.addRecipe(new ItemStack(Knife, 1), new Object[] {"***", "**2", "*1*", Character.valueOf('1'),  new ItemStack(Item.stick, 1), Character.valueOf('2'), this.SilverIngot});
		GameRegistry.addRecipe(new ItemStack(ScarL, 1), new Object[] {"131", "12*", "***", Character.valueOf('1'),  new ItemStack(Item.ingotIron, 1), Character.valueOf('2'), new ItemStack(Item.stick), Character.valueOf('3'), new ItemStack(Item.gunpowder)});
		GameRegistry.addRecipe(new ItemStack(L85, 1), new Object[] {"131", "12*", "***", Character.valueOf('1'),  new ItemStack(Item.ingotIron, 1), Character.valueOf('2'), new ItemStack(Item.stick), Character.valueOf('3'), new ItemStack(Block.glass)});
		GameRegistry.addRecipe(new ItemStack(Ammunition, 64), new Object[] {"*1*", "121", "212", Character.valueOf('1'),  new ItemStack(Item.ingotIron, 1), Character.valueOf('2'), new ItemStack(Item.gunpowder)});
		GameRegistry.addRecipe(new ItemStack(L96A1, 1), new Object[] {"141", "12*", "3**", Character.valueOf('1'),  new ItemStack(Item.ingotIron, 1), Character.valueOf('2'), new ItemStack(Item.stick), Character.valueOf('3'), new ItemStack(Item.gunpowder),  Character.valueOf('4'), new ItemStack(Block.glass)});
		GameRegistry.registerWorldGenerator(new WorldGeneratorSilverOre());
	}
			
	//Entities, MOBS
			{
				EntityRegistry.registerGlobalEntityID(EntityUS_Recon.class, "US Recon", EntityRegistry.findGlobalUniqueEntityId(), 0x333333, 0x999999);
				EntityRegistry.registerGlobalEntityID(EntityUS_Assault.class, "US Assault", EntityRegistry.findGlobalUniqueEntityId(), 0x333333, 0x999999);
				EntityRegistry.registerGlobalEntityID(EntityUS_Support.class, "US Support", EntityRegistry.findGlobalUniqueEntityId(), 0x333333, 0x999999);
			    EntityRegistry.registerGlobalEntityID(EntityUS_Engineer.class, "US Engineer", EntityRegistry.findGlobalUniqueEntityId(), 0x333333, 0x999999);
				EntityRegistry.registerGlobalEntityID(EntityTerrorist_G.class, "Terrorist Gunner", EntityRegistry.findGlobalUniqueEntityId(), 0x333333, 0x999999);
				//EntityRegistry.registerGlobalEntityID(EntityUS_Recon.class, "US Recon", EntityRegistry.findGlobalUniqueEntityId(), 0x333333, 0x999999);
				//EntityRegistry.registerGlobalEntityID(EntityUS_Recon.class, "US Recon", EntityRegistry.findGlobalUniqueEntityId(), 0x333333, 0x999999);
				//EntityRegistry.registerGlobalEntityID(EntityUS_Recon.class, "US Recon", EntityRegistry.findGlobalUniqueEntityId(), 0x333333, 0x999999);
				//EntityRegistry.registerGlobalEntityID(EntityUS_Recon.class, "US Recon", EntityRegistry.findGlobalUniqueEntityId(), 0x333333, 0x999999);
				//EntityRegistry.registerGlobalEntityID(EntityUS_Recon.class, "US Recon", EntityRegistry.findGlobalUniqueEntityId(), 0x333333, 0x999999);
				//EntityRegistry.registerGlobalEntityID(EntityUS_Recon.class, "US Recon", EntityRegistry.findGlobalUniqueEntityId(), 0x333333, 0x999999);
				//EntityRegistry.registerGlobalEntityID(EntityUS_Recon.class, "US Recon", EntityRegistry.findGlobalUniqueEntityId(), 0x333333, 0x999999);
				
           
			}

	//Spawn mob
			{
				EntityRegistry.addSpawn(EntityUS_Recon.class, 10, 1, 2, EnumCreatureType.creature, new BiomeGenBase[]{BiomeGenBase.plains, BiomeGenBase.forest, BiomeGenBase.forestHills, BiomeGenBase.taiga,  BiomeGenBase.swampland, BiomeGenBase.desertHills, BiomeGenBase.beach, BiomeGenBase.extremeHills, BiomeGenBase.desert, BiomeGenBase.jungle, BiomeGenBase.jungleHills, BiomeGenBase.icePlains, BiomeGenBase.swampland});
				EntityRegistry.addSpawn(EntityUS_Assault.class, 10, 1, 2, EnumCreatureType.creature, new BiomeGenBase[]{BiomeGenBase.plains, BiomeGenBase.forest, BiomeGenBase.forestHills, BiomeGenBase.taiga, BiomeGenBase.swampland, BiomeGenBase.desertHills, BiomeGenBase.beach, BiomeGenBase.extremeHills, BiomeGenBase.desert, BiomeGenBase.jungle, BiomeGenBase.jungleHills, BiomeGenBase.icePlains, BiomeGenBase.swampland});	
				EntityRegistry.addSpawn(EntityUS_Support.class, 10, 1, 2, EnumCreatureType.creature, new BiomeGenBase[]{BiomeGenBase.plains, BiomeGenBase.forest, BiomeGenBase.forestHills, BiomeGenBase.taiga, BiomeGenBase.swampland, BiomeGenBase.desertHills, BiomeGenBase.beach, BiomeGenBase.extremeHills, BiomeGenBase.desert, BiomeGenBase.jungle, BiomeGenBase.jungleHills, BiomeGenBase.icePlains, BiomeGenBase.swampland});
				EntityRegistry.addSpawn(EntityUS_Engineer.class, 10, 1, 2, EnumCreatureType.creature, new BiomeGenBase[]{BiomeGenBase.plains, BiomeGenBase.forest, BiomeGenBase.forestHills, BiomeGenBase.taiga,  BiomeGenBase.swampland, BiomeGenBase.desertHills, BiomeGenBase.beach, BiomeGenBase.extremeHills, BiomeGenBase.desert, BiomeGenBase.jungle, BiomeGenBase.jungleHills, BiomeGenBase.icePlains, BiomeGenBase.swampland});	
				EntityRegistry.addSpawn(EntityTerrorist_G.class, 10, 1, 2, EnumCreatureType.creature, new BiomeGenBase[]{BiomeGenBase.plains, BiomeGenBase.forest, BiomeGenBase.forestHills, BiomeGenBase.taiga,  BiomeGenBase.swampland, BiomeGenBase.desertHills, BiomeGenBase.beach, BiomeGenBase.extremeHills, BiomeGenBase.desert, BiomeGenBase.jungle, BiomeGenBase.jungleHills, BiomeGenBase.icePlains, BiomeGenBase.swampland});	
				//EntityRegistry.addSpawn(EntityUS_Recon.class, 10, 1, 2, EnumCreatureType.creature, new BiomeGenBase[]{BiomeGenBase.plains, BiomeGenBase.forest, BiomeGenBase.forestHills, BiomeGenBase.taiga});	
				//EntityRegistry.addSpawn(EntityUS_Recon.class, 10, 1, 2, EnumCreatureType.creature, new BiomeGenBase[]{BiomeGenBase.plains, BiomeGenBase.forest, BiomeGenBase.forestHills, BiomeGenBase.taiga});	
				//EntityRegistry.addSpawn(EntityUS_Recon.class, 10, 1, 2, EnumCreatureType.creature, new BiomeGenBase[]{BiomeGenBase.plains, BiomeGenBase.forest, BiomeGenBase.forestHills, BiomeGenBase.taiga});	
				//EntityRegistry.addSpawn(EntityUS_Recon.class, 10, 1, 2, EnumCreatureType.creature, new BiomeGenBase[]{BiomeGenBase.plains, BiomeGenBase.forest, BiomeGenBase.forestHills, BiomeGenBase.taiga});	
				//EntityRegistry.addSpawn(EntityUS_Recon.class, 10, 1, 2, EnumCreatureType.creature, new BiomeGenBase[]{BiomeGenBase.plains, BiomeGenBase.forest, BiomeGenBase.forestHills, BiomeGenBase.taiga});	
				//EntityRegistry.addSpawn(EntityUS_Recon.class, 10, 1, 2, EnumCreatureType.creature, new BiomeGenBase[]{BiomeGenBase.plains, BiomeGenBase.forest, BiomeGenBase.forestHills, BiomeGenBase.taiga});	
				
				
			}

    //Localize mob name
			{

				LanguageRegistry.instance().addStringLocalization("US_Recon", "en_US", "US Recon");
				LanguageRegistry.instance().addStringLocalization("US_Assault", "en_US", "US Assault");
				LanguageRegistry.instance().addStringLocalization("US_Support", "en_US", "US Support");
				LanguageRegistry.instance().addStringLocalization("US_Engineer", "en_US", "US Engineer");
				LanguageRegistry.instance().addStringLocalization("Terrorist_G", "en_US", "Terrorist Gunner");
				//LanguageRegistry.instance().addStringLocalization("entity.US_Recon.name", "en_US", "US Recon");
				//LanguageRegistry.instance().addStringLocalization("entity.US_Recon.name", "en_US", "US Recon");
				//LanguageRegistry.instance().addStringLocalization("entity.US_Recon.name", "en_US", "US Recon");
				//LanguageRegistry.instance().addStringLocalization("entity.US_Recon.name", "en_US", "US Recon");
				//LanguageRegistry.instance().addStringLocalization("entity.US_Recon.name", "en_US", "US Recon");
				//LanguageRegistry.instance().addStringLocalization("entity.US_Recon.name", "en_US", "US Recon");
				//LanguageRegistry.instance().addStringLocalization("entity.US_Recon.name", "en_US", "US Recon");
				
			}
}



