001 package net.minecraft.src; 002 003 import cpw.mods.fml.common.registry.GameRegistry; 004 005 public class SlotFurnace extends Slot 006 { 007 /** The player that is using the GUI where this slot resides. */ 008 private EntityPlayer thePlayer; 009 private int field_75228_b; 010 011 public SlotFurnace(EntityPlayer par1EntityPlayer, IInventory par2IInventory, int par3, int par4, int par5) 012 { 013 super(par2IInventory, par3, par4, par5); 014 this.thePlayer = par1EntityPlayer; 015 } 016 017 /** 018 * Check if the stack is a valid item for this slot. Always true beside for the armor slots. 019 */ 020 public boolean isItemValid(ItemStack par1ItemStack) 021 { 022 return false; 023 } 024 025 /** 026 * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new 027 * stack. 028 */ 029 public ItemStack decrStackSize(int par1) 030 { 031 if (this.getHasStack()) 032 { 033 this.field_75228_b += Math.min(par1, this.getStack().stackSize); 034 } 035 036 return super.decrStackSize(par1); 037 } 038 039 /** 040 * Called when the player picks up an item from an inventory slot 041 */ 042 public void onPickupFromSlot(ItemStack par1ItemStack) 043 { 044 this.onCrafting(par1ItemStack); 045 super.onPickupFromSlot(par1ItemStack); 046 } 047 048 /** 049 * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an 050 * internal count then calls onCrafting(item). 051 */ 052 protected void onCrafting(ItemStack par1ItemStack, int par2) 053 { 054 this.field_75228_b += par2; 055 this.onCrafting(par1ItemStack); 056 } 057 058 /** 059 * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. 060 */ 061 protected void onCrafting(ItemStack par1ItemStack) 062 { 063 par1ItemStack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.field_75228_b); 064 065 if (!this.thePlayer.worldObj.isRemote) 066 { 067 int var2 = this.field_75228_b; 068 float var3 = FurnaceRecipes.smelting().getExperience(par1ItemStack.itemID); 069 int var4; 070 071 if (var3 == 0.0F) 072 { 073 var2 = 0; 074 } 075 else if (var3 < 1.0F) 076 { 077 var4 = MathHelper.floor_float((float)var2 * var3); 078 079 if (var4 < MathHelper.ceiling_float_int((float)var2 * var3) && (float)Math.random() < (float)var2 * var3 - (float)var4) 080 { 081 ++var4; 082 } 083 084 var2 = var4; 085 } 086 087 while (var2 > 0) 088 { 089 var4 = EntityXPOrb.getXPSplit(var2); 090 var2 -= var4; 091 this.thePlayer.worldObj.spawnEntityInWorld(new EntityXPOrb(this.thePlayer.worldObj, this.thePlayer.posX, this.thePlayer.posY + 0.5D, this.thePlayer.posZ + 0.5D, var4)); 092 } 093 } 094 095 096 this.field_75228_b = 0; 097 098 GameRegistry.onItemSmelted(thePlayer, par1ItemStack); 099 100 if (par1ItemStack.itemID == Item.ingotIron.shiftedIndex) 101 { 102 this.thePlayer.addStat(AchievementList.acquireIron, 1); 103 } 104 105 if (par1ItemStack.itemID == Item.fishCooked.shiftedIndex) 106 { 107 this.thePlayer.addStat(AchievementList.cookFish, 1); 108 } 109 } 110 }