package xyz.ibatv.iba_backblocks;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.item.Item;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import xyz.ibatv.iba_backblocks.Register.Register;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
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.registry.GameRegistry;
import xyz.ibatv.iba_backblocks.items.Minecraft1_8_Items;

@Mod(modid = IBA_BackBlocks.MODID, name = "IBA Back-Blocks", version = IBA_BackBlocks.VERSION)
public class IBA_BackBlocks {

    public static final String MODID = "iba_backblocks";
    public static final String VERSION = "0.1.1-dev";

	
    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {
    	//item / block init and registering
    	//config handling
    	Register.mc18Ore();
    	Register.mc18logs();
        Register.initFencesGates();
        Register.newSandStone();
        Register.initSlimeBlock();
        Register.initMutton();
        Register.initRabbit();
        Register.initRecipes();
        Register.initAcaciaDoor();
        Register.initDarkoakDoor();
        Register.initBirchDoor();
        Register.initJungleDoor();
        Register.initSpruceDoor();
        Register.initIronTrapdoor();
        Register.initNewStones();
        Register.initPrismarine();
        Register.initRabbitStew();
        //Register.init();
        Minecraft1_8_Items.items();
    	
    }
    
    @EventHandler
    public void init(FMLInitializationEvent event) {
    	//proxy, tileEntity, entity, gui and packet registering
    	//GameRegistry.addShapelessRecipe(new ItemStack(TestMod.items.itemCopperIngot, 9), new Object[] {new ItemStack(TestMod.blockCopperBlock, 1)});
    	//GameRegistry.addShapelessRecipe(new ItemStack(TestMod.itemRawCopper, 9), new Object[] {new ItemStack(TestMod.blockRawCopper, 1)});

    	
    	
    	//GameRegistry.addRecipe(new ItemStack(TestMod.blockCopperBlock), new Object[] {"CCC","CCC","CCC", 'C', TestMod.itemCopperIngot}); //Copper Block
    	//GameRegistry.addRecipe(new ItemStack(TestMod.blockRawCopper), new Object[] {"CCC","CCC","CCC", 'C', TestMod.itemRawCopper}); //Raw Copper Block
    }

    @EventHandler
    public void postInit(FMLPostInitializationEvent event) {
    	
    }


    @SubscribeEvent
    public void onLivingDrops(LivingDropsEvent event)
    {
        if (event.entityLiving instanceof EntitySheep
                && Register.mutton_cooked != null
                && Register.mutton_raw != null)
        {
            // 50/50 drop 1-2
            // TODO. more with looting

            int drops = 1 + event.entity.worldObj.rand.nextInt(2);// this gets num in range [0,1]

            if (event.entityLiving.isBurning())
                event.entityLiving.dropItem(Register.mutton_cooked, drops);
            else
                event.entityLiving.dropItem(Register.mutton_raw, drops);
        }
    }

    public static void registerBlockHelperNoTab(Block s, String name)
    {
        s.setBlockName(name).setBlockTextureName("iba_backblocks:" + name);
        GameRegistry.registerBlock(s, name);
    }

    public static void registerBlockHelper(Block s, String name)
    {
        s.setBlockName(name).setBlockTextureName("iba_backblocks:" + name);
        GameRegistry.registerBlock(s, name);
    }


    public static void registerItemHelper(Item s, String name)
    {
        s.setUnlocalizedName(name).setTextureName("iba_backblocks:" + name);
        GameRegistry.registerItem(s, name);
    }
}
