package ncrashed.warp;

import ncrashed.warp.CommonProxy;
import ncrashed.warp.client.ClientProxy;
import ncrashed.warp.cores.LegacyCoreBlock;
import ncrashed.warp.cores.MarkerBlock;
import ncrashed.warp.cores.TileLegacyCore;
import ncrashed.warp.cores.TileMarker;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.FMLCommonHandler;
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.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.relauncher.Side;

@Mod(modid = WarpMod.MOD_ID, name = "Warp", version = "0.0.1", dependencies = "required-after:RedPowerLogic")
@NetworkMod(clientSideRequired=true, serverSideRequired=true)
public class WarpMod 
{
	public static final String MOD_ID = "NCWarp";
	
    @Instance("NCWarp")
    public static WarpMod instance;
    
    public static Block mMarkerBlock;
    public static Block mLegacyCoreBlock;
    
    public static Item debugItem;
    
    public static BlockIdConfig mConfig;
    public static CoreRegistry mRegister;
    
    @SidedProxy(clientSide="ncrashed.warp.client.ClientProxy", serverSide="ncrashed.warp.CommonProxy")
    public static CommonProxy proxy;
    
    @PreInit
    public void preInit(FMLPreInitializationEvent event) 
    {
    	mConfig = new BlockIdConfig(event.getModConfigurationDirectory());
    	mRegister = new CoreRegistry();
    }
    
    @Init
    public void load(FMLInitializationEvent event) 
    {
    	debugItem = new DebugItem(795).setItemName("DebugWarpItem");
    	mMarkerBlock = new MarkerBlock(mConfig.mMarkerBlockID, Material.iron).setBlockName("MarkerBlock");
    	mLegacyCoreBlock = new LegacyCoreBlock(mConfig.mLegacyCoreBlockID, Material.iron).setBlockName("LegacyCoreBlock");
    	
    	registerBlock(mMarkerBlock, "Warp Marker");
    	registerBlock(mLegacyCoreBlock, "Warp Core");
    	
    	registerItem(debugItem, "Warp Debug Item");
    	
    	GameRegistry.registerTileEntity(TileLegacyCore.class, "LegacyCore");
    	GameRegistry.registerTileEntity(TileMarker.class, "WarpMarker");
    	
    	GameRegistry.addRecipe(new ItemStack(mLegacyCoreBlock, 1),
            "AXA",
            "GTG",
            "AZA",
            'A', new ItemStack(mConfig.mICAdvancedCircuit, 1, 0),
            'X', new ItemStack(mConfig.mGRAdvancedHeatVent, 1, 0),
            'G', new ItemStack(mConfig.mGRHellimuCollantCell, 1, 0),
            'T', new ItemStack(mConfig.mICTeleport, 1, 0),
            'Z', new ItemStack(mConfig.mICCable, 1, mConfig.mICGoldCableMeta)
    	);
    	
    	GameRegistry.addRecipe(new ItemStack(mMarkerBlock, 1),
            "AXA",
            "GTG",
            "AXA",
            'A', Item.diamond,
            'X', Item.enderPearl,
            'G', new ItemStack(mConfig.mCCWirelessBase, 1, mConfig.mCCWirelessModemMeta),
            'T', new ItemStack(mConfig.mICTeleport, 1, 0)
    	);
    	
    	proxy.registerRenderThings();
    }
    
    @PostInit
    public void postInit(FMLPostInitializationEvent event) 
    {
    	
    }
    
    private static final void registerBlock(Block block, String name)
    {
    	GameRegistry.registerBlock(block, MOD_ID + block.getBlockName());
    	LanguageRegistry.addName(block, name);
    }
    
    private static final void registerItem(Item item, String name)
    {
    	GameRegistry.registerItem(item, MOD_ID + item.getItemName());
    	LanguageRegistry.addName(item, name);
    }
}
