package net.mcft.copy.betterstorage.misc.handlers;

import net.mcft.copy.betterstorage.BetterStorage;
import net.mcft.copy.betterstorage.item.ItemKey;
import net.mcft.copy.betterstorage.item.ItemLock;
import net.mcft.copy.betterstorage.utils.InventoryUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.ICraftingHandler;

/** Handles key and lock crafting. */
public class CraftingHandler implements ICraftingHandler {
	
	@Override
	public void onCrafting(EntityPlayer player, ItemStack item, IInventory craftMatrix) {
		// If item crafted is a key ...
		if (item.getItem() instanceof ItemKey) {
			
			// Get the key used in the crafting recipe, if there was one.
			int keyIndex = InventoryUtils.findItemSlot(craftMatrix, BetterStorage.key);
			ItemStack key = ((keyIndex >= 0) ? craftMatrix.getStackInSlot(keyIndex) : null);
			
			// See if a key was modified by checking if no gold was used in the recipe.
			boolean modifyKey = !InventoryUtils.hasItem(craftMatrix, Item.ingotGold);
			
			// If a key is being modified, remove it from the crafting matrix.
			if (modifyKey) craftMatrix.setInventorySlotContents(keyIndex, null);
			// Otherwise, if a new key is crafted (not duplicated),
			// set the the damege of the key to a random value.
			else if (key == null) item.setItemDamage(-32000 + BetterStorage.random.nextInt(64000));
			
		}
		// If item crafted is a lock, copy the damage value from the key.
		if (item.getItem() instanceof ItemLock)
			item.setItemDamage(craftMatrix.getStackInSlot(4).getItemDamage());
	}
	@Override
	public void onSmelting(EntityPlayer player, ItemStack item) {  }
	
}

@@ -1215,17 +1215,21 @@
 difyKey)
- 
+%0A%09%09%09%09
 craftMat
@@ -1412,17 +1412,21 @@
 == null)
- 
+%0A%09%09%09%09
 item.set
@@ -1440,17 +1440,8 @@
 age(
--32000 + 
 Bett
@@ -1469,10 +1469,10 @@
 Int(
-64
+32
 000)
@@ -1662,19 +1662,21 @@
 age());%0A
-
 %09%7D%0A
+%09%0A
 %09@Overri

Change random key ID range to only positive