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