package com.cadyyan.levels.recipes;

import com.cadyyan.levels.serializers.PlayerLevels;
import com.cadyyan.levels.registries.LevelStore;
import com.cadyyan.levels.skills.ISkill;
import com.cadyyan.levels.utils.LogUtility;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.*;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.ReflectionHelper;

import java.util.Map;

public class VanillaCraftingRecipeOverride extends RecipeOverride
{
	@Override
	public boolean matches(InventoryCrafting inventory, World world)
	{
		EntityPlayer player;

		Container container = ReflectionHelper.getPrivateValue(InventoryCrafting.class, inventory, "eventHandler");
		if (container instanceof ContainerPlayer)
		{
			ContainerPlayer playerCraftingArea = (ContainerPlayer) container;
			player = ReflectionHelper.getPrivateValue(ContainerPlayer.class, playerCraftingArea, "thePlayer");
		}
		else if (container instanceof ContainerWorkbench)
		{
			ContainerWorkbench worktableCraftingArea = (ContainerWorkbench) container;
			SlotCrafting craftingSlot = (SlotCrafting) worktableCraftingArea.getSlot(0);
			player = ReflectionHelper.getPrivateValue(SlotCrafting.class, craftingSlot, "thePlayer");
		}
		else
		{
			// TODO(cadyyan): we don't currently support other crafting methods. yet...
			LogUtility.warn("Unable to handle container of type {}", container.getClass().getCanonicalName());

			return recipe.matches(inventory, world);
		}

		// Check for a valid recipe
		if (!recipe.matches(inventory, world))
			return false;

		PlayerLevels playerLevels = LevelStore.getInstance().getPlayerLevels(player);
		for (Map.Entry<ISkill, Integer> entry : recipeModification.getRequirements().entrySet())
		{
			ISkill skill      = entry.getKey();
			int requiredLevel = entry.getValue();

			int level = playerLevels.getLevelForSkill(skill.getUnlocalizedName());
			if (level < requiredLevel)
				return false;
		}

		return true;
	}
}

@@ -299,16 +299,149 @@
 tory.*;%0A
+import net.minecraft.util.ChatComponentText;%0Aimport net.minecraft.util.EnumChatFormatting;%0Aimport net.minecraft.util.IChatComponent;%0A
 import n
@@ -2056,16 +2056,499 @@
 dLevel)%0A
+%09%09%09%7B%0A%09%09%09%09if (!world.isRemote)%0A%09%09%09%09%7B%0A%09%09%09%09%09// TODO(cadyyan): this will need to be translated%0A%09%09%09%09%09IChatComponent chatComponent = new ChatComponentText(%0A%09%09%09%09%09%09%09EnumChatFormatting.ITALIC +%0A%09%09%09%09%09%09%09%09%09%22You think you could create something like this but you're not quite skilled enough.%22 +%0A%09%09%09%09%09%09%09%09%09EnumChatFormatting.RED + %22Requires %22 + requiredLevel + %22 %22 + skill%0A%09%09%09%09%09%09%09%09%09.getUnlocalizedName() +%0A%09%09%09%09%09%09%09%09%09EnumChatFormatting.RESET%0A%09%09%09%09%09);%0A%09%09%09%09%09player.addChatMessage(chatComponent);%0A%09%09%09%09%7D%0A%0A
 %09%09%09%09retu
@@ -2557,16 +2557,21 @@
  false;%0A
+%09%09%09%7D%0A
 %09%09%7D%0A%0A%09%09r

Add hint about possible recipe