001 package net.minecraft.src; 002 003 import net.minecraftforge.common.ForgeHooks; 004 005 import cpw.mods.fml.common.registry.GameRegistry; 006 007 public class SlotCrafting extends Slot 008 { 009 /** The craft matrix inventory linked to this result slot. */ 010 private final IInventory craftMatrix; 011 012 /** The player that is using the GUI where this slot resides. */ 013 private EntityPlayer thePlayer; 014 015 /** 016 * The number of items that have been crafted so far. Gets passed to ItemStack.onCrafting before being reset. 017 */ 018 private int amountCrafted; 019 020 public SlotCrafting(EntityPlayer par1EntityPlayer, IInventory par2IInventory, IInventory par3IInventory, int par4, int par5, int par6) 021 { 022 super(par3IInventory, par4, par5, par6); 023 this.thePlayer = par1EntityPlayer; 024 this.craftMatrix = par2IInventory; 025 } 026 027 /** 028 * Check if the stack is a valid item for this slot. Always true beside for the armor slots. 029 */ 030 public boolean isItemValid(ItemStack par1ItemStack) 031 { 032 return false; 033 } 034 035 /** 036 * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new 037 * stack. 038 */ 039 public ItemStack decrStackSize(int par1) 040 { 041 if (this.getHasStack()) 042 { 043 this.amountCrafted += Math.min(par1, this.getStack().stackSize); 044 } 045 046 return super.decrStackSize(par1); 047 } 048 049 /** 050 * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an 051 * internal count then calls onCrafting(item). 052 */ 053 protected void onCrafting(ItemStack par1ItemStack, int par2) 054 { 055 this.amountCrafted += par2; 056 this.onCrafting(par1ItemStack); 057 } 058 059 /** 060 * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. 061 */ 062 protected void onCrafting(ItemStack par1ItemStack) 063 { 064 par1ItemStack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.amountCrafted); 065 this.amountCrafted = 0; 066 067 if (par1ItemStack.itemID == Block.workbench.blockID) 068 { 069 this.thePlayer.addStat(AchievementList.buildWorkBench, 1); 070 } 071 else if (par1ItemStack.itemID == Item.pickaxeWood.shiftedIndex) 072 { 073 this.thePlayer.addStat(AchievementList.buildPickaxe, 1); 074 } 075 else if (par1ItemStack.itemID == Block.stoneOvenIdle.blockID) 076 { 077 this.thePlayer.addStat(AchievementList.buildFurnace, 1); 078 } 079 else if (par1ItemStack.itemID == Item.hoeWood.shiftedIndex) 080 { 081 this.thePlayer.addStat(AchievementList.buildHoe, 1); 082 } 083 else if (par1ItemStack.itemID == Item.bread.shiftedIndex) 084 { 085 this.thePlayer.addStat(AchievementList.makeBread, 1); 086 } 087 else if (par1ItemStack.itemID == Item.cake.shiftedIndex) 088 { 089 this.thePlayer.addStat(AchievementList.bakeCake, 1); 090 } 091 else if (par1ItemStack.itemID == Item.pickaxeStone.shiftedIndex) 092 { 093 this.thePlayer.addStat(AchievementList.buildBetterPickaxe, 1); 094 } 095 else if (par1ItemStack.itemID == Item.swordWood.shiftedIndex) 096 { 097 this.thePlayer.addStat(AchievementList.buildSword, 1); 098 } 099 else if (par1ItemStack.itemID == Block.enchantmentTable.blockID) 100 { 101 this.thePlayer.addStat(AchievementList.enchantments, 1); 102 } 103 else if (par1ItemStack.itemID == Block.bookShelf.blockID) 104 { 105 this.thePlayer.addStat(AchievementList.bookcase, 1); 106 } 107 } 108 109 /** 110 * Called when the player picks up an item from an inventory slot 111 */ 112 public void onPickupFromSlot(ItemStack par1ItemStack) 113 { 114 GameRegistry.onItemCrafted(thePlayer, par1ItemStack, craftMatrix); 115 this.onCrafting(par1ItemStack); 116 117 for (int var2 = 0; var2 < this.craftMatrix.getSizeInventory(); ++var2) 118 { 119 ItemStack var3 = this.craftMatrix.getStackInSlot(var2); 120 121 if (var3 != null) 122 { 123 this.craftMatrix.decrStackSize(var2, 1); 124 125 if (var3.getItem().hasContainerItem()) 126 { 127 ItemStack var4 = var3.getItem().getContainerItemStack(var3); 128 129 if (!var3.getItem().doesContainerItemLeaveCraftingGrid(var3) || !this.thePlayer.inventory.addItemStackToInventory(var4)) 130 { 131 if (this.craftMatrix.getStackInSlot(var2) == null) 132 { 133 this.craftMatrix.setInventorySlotContents(var2, var4); 134 } 135 else 136 { 137 this.thePlayer.dropPlayerItem(var4); 138 } 139 } 140 } 141 } 142 } 143 } 144 }