/*
 * Caveworld
 *
 * Copyright (c) 2014 kegare
 * https://github.com/kegare
 *
 * This mod is distributed under the terms of the Minecraft Mod Public License 1.0, or MMPL.
 * Please check the contents of the license located in http://www.mod-buildcraft.com/MMPL-1.0.txt
 */

package com.kegare.caveworld.proxy;

import java.util.logging.Level;

import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;

import com.kegare.caveworld.block.CaveBlock;
import com.kegare.caveworld.core.Config;
import com.kegare.caveworld.util.CaveLog;

import cpw.mods.fml.common.FMLCommonHandler;

public class CommonProxy
{
	public void registerRenderers() {}

	public int getUniqueRenderType()
	{
		return -1;
	}

	public void registerRecipes()
	{
		if (CaveBlock.rope != null)
		{
			addShapelessRecipe(new ItemStack(CaveBlock.rope), Item.silk, Item.silk, Item.silk, Item.leather);
		}

		if (Config.portalCraftRecipe)
		{
			addShapedRecipe(new ItemStack(CaveBlock.portalCaveworld),
				" E ", "EPE", " D ",
				'E', Item.emerald,
				'P', Item.enderPearl,
				'D', Item.diamond
			);
		}

		if (Config.mossStoneCraftRecipe)
		{
			addShapedRecipe(new ItemStack(Block.cobblestoneMossy),
				" V ", "VCV", " V ",
				'V', Block.vine,
				'C', Block.cobblestone
			);
		}
	}

	public void addShapedRecipe(ItemStack result, Object... recipe)
	{
		try
		{
			CraftingManager.getInstance().getRecipeList().add(new ShapedOreRecipe(result, recipe));
		}
		catch (Exception e)
		{
			CaveLog.log(Level.WARNING, e, "Failed to register a shaped recipe: %s", result.getUnlocalizedName());
		}
	}

	public void addShapelessRecipe(ItemStack result, Object... recipe)
	{
		try
		{
			CraftingManager.getInstance().getRecipeList().add(new ShapelessOreRecipe(result, recipe));
		}
		catch (Exception e)
		{
			CaveLog.log(Level.WARNING, e, "Failed to register a shapeless recipe: %s", result.getUnlocalizedName());
		}
	}

	public MinecraftServer getServer()
	{
		return FMLCommonHandler.instance().getMinecraftServerInstance();
	}
}