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        public void func_82870_a(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack)
040        {
041            this.onCrafting(par2ItemStack);
042            super.func_82870_a(par1EntityPlayer, par2ItemStack);
043        }
044    
045        /**
046         * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
047         * internal count then calls onCrafting(item).
048         */
049        protected void onCrafting(ItemStack par1ItemStack, int par2)
050        {
051            this.field_75228_b += par2;
052            this.onCrafting(par1ItemStack);
053        }
054    
055        /**
056         * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
057         */
058        protected void onCrafting(ItemStack par1ItemStack)
059        {
060            par1ItemStack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.field_75228_b);
061    
062            if (!this.thePlayer.worldObj.isRemote)
063            {
064                int var2 = this.field_75228_b;
065                float var3 = FurnaceRecipes.smelting().getExperience(par1ItemStack);
066                int var4;
067    
068                if (var3 == 0.0F)
069                {
070                    var2 = 0;
071                }
072                else if (var3 < 1.0F)
073                {
074                    var4 = MathHelper.floor_float((float)var2 * var3);
075    
076                    if (var4 < MathHelper.ceiling_float_int((float)var2 * var3) && (float)Math.random() < (float)var2 * var3 - (float)var4)
077                    {
078                        ++var4;
079                    }
080    
081                    var2 = var4;
082                }
083    
084                while (var2 > 0)
085                {
086                    var4 = EntityXPOrb.getXPSplit(var2);
087                    var2 -= var4;
088                    this.thePlayer.worldObj.spawnEntityInWorld(new EntityXPOrb(this.thePlayer.worldObj, this.thePlayer.posX, this.thePlayer.posY + 0.5D, this.thePlayer.posZ + 0.5D, var4));
089                }
090            }
091    
092    
093            this.field_75228_b = 0;
094    
095            GameRegistry.onItemSmelted(thePlayer, par1ItemStack);
096    
097            if (par1ItemStack.itemID == Item.ingotIron.shiftedIndex)
098            {
099                this.thePlayer.addStat(AchievementList.acquireIron, 1);
100            }
101    
102            if (par1ItemStack.itemID == Item.fishCooked.shiftedIndex)
103            {
104                this.thePlayer.addStat(AchievementList.cookFish, 1);
105            }
106        }
107    }