package net.mcft.copy.betterstorage.addon.nei;


import net.mcft.copy.betterstorage.addon.Addon;
import net.mcft.copy.betterstorage.client.gui.GuiCraftingStation;
import net.mcft.copy.betterstorage.content.BetterStorageItems;
import net.mcft.copy.betterstorage.content.BetterStorageTiles;
import net.mcft.copy.betterstorage.misc.Constants;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.oredict.ShapedOreRecipe;
import codechicken.nei.api.API;
import codechicken.nei.recipe.DefaultOverlayHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.registry.GameRegistry;

public class NEIAddon extends Addon {
	
	public NEIAddon() {
		super("NotEnoughItems");
	}
	
	@Override
	public void postInitialize() {	
		if (FMLCommonHandler.instance().getEffectiveSide().isServer()) return;
		
		NEIRecipeHandler handler = new NEIRecipeHandler();
		API.registerRecipeHandler(handler);
		API.registerUsageHandler(handler);
		
		API.registerGuiOverlay(GuiCraftingStation.class, Constants.modId + ".craftingStation");
		API.registerGuiOverlay(GuiCraftingStation.class, "crafting", -8, 11);
		
		API.registerGuiOverlayHandler(GuiCraftingStation.class,
				new StationOverlayHandler(), Constants.modId + ".craftingStation");
		API.registerGuiOverlayHandler(GuiCraftingStation.class,
				new StationOverlayHandler(-8, 11), "crafting");
		
		API.hideItem(new ItemStack(BetterStorageTiles.lockableDoor));
		
		// Fake key recipes
		GameRegistry.addRecipe(new FakeShapedRecipe(new ItemStack(BetterStorageItems.key),
				".o",
				".o",
				" o", 'o', Items.gold_ingot,
				      '.', Items.gold_nugget));
		GameRegistry.addRecipe(new FakeShapedRecipe(new ItemStack(BetterStorageItems.key),
				".o ",
				".o ",
				" ok", 'o', Items.gold_ingot,
				       '.', Items.gold_nugget,
				       'k', BetterStorageItems.key));
	}
	
	private static class StationOverlayHandler extends DefaultOverlayHandler {
		public StationOverlayHandler() {  }
		public StationOverlayHandler(int x, int y) { super(x, y); }
		
		@Override
		public boolean canMoveFrom(Slot slot, GuiContainer gui) {
			return (slot.slotNumber >= 18);
		}
	}
	
	private static class FakeShapedRecipe extends ShapedOreRecipe {
		public FakeShapedRecipe(ItemStack result, Object... recipe) { super(result, recipe); }
		
		@Override
		public boolean matches(InventoryCrafting crafting, World world) { return false; }
	}
}

@@ -1653,16 +1653,57 @@
 recipes%0A
+%09%09if (BetterStorageItems.key != null) %7B%0A%09
 %09%09GameRe
@@ -1775,24 +1775,25 @@
 Items.key),%0A
+%09
 %09%09%09%09%22.o%22,%0A%09%09
@@ -1790,30 +1790,32 @@
 %09%09%22.o%22,%0A%09%09%09%09
+%09
 %22.o%22,%0A
+%09
 %09%09%09%09%22 o%22, 'o
@@ -1835,24 +1835,25 @@
 _ingot,%0A%09%09%09%09
+%09
       '.', I
@@ -1872,16 +1872,17 @@
 gget));%0A
+%09
 %09%09GameRe
@@ -1958,31 +1958,33 @@
 s.key),%0A%09%09%09%09
+%09
 %22.o %22,%0A
+%09
 %09%09%09%09%22.o %22,%0A%09
@@ -1978,24 +1978,25 @@
 %09%09%09%09%09%22.o %22,%0A
+%09
 %09%09%09%09%22 ok%22, '
@@ -2017,24 +2017,25 @@
 _ingot,%0A%09%09%09%09
+%09
        '.', 
@@ -2053,16 +2053,17 @@
 nugget,%0A
+%09
 %09%09%09%09    
@@ -2096,16 +2096,20 @@
 .key));%0A
+%09%09%7D%0A
 %09%7D%0A%09%0A%09pr

Fix #235, adding fake key recipes when disabled