    001package net.minecraft.inventory;
    002
    003import cpw.mods.fml.common.registry.GameRegistry;
    004import net.minecraft.entity.item.EntityXPOrb;
    005import net.minecraft.entity.player.EntityPlayer;
    006import net.minecraft.item.Item;
    007import net.minecraft.item.ItemStack;
    008import net.minecraft.item.crafting.FurnaceRecipes;
    009import net.minecraft.stats.AchievementList;
    010import net.minecraft.util.MathHelper;
    011
    012public 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 i = this.field_75228_b;
    072            float f = FurnaceRecipes.smelting().getExperience(par1ItemStack);
    073            int j;
    074
    075            if (f == 0.0F)
    076            {
    077                i = 0;
    078            }
    079            else if (f < 1.0F)
    080            {
    081                j = MathHelper.floor_float((float)i * f);
    082
    083                if (j < MathHelper.ceiling_float_int((float)i * f) && (float)Math.random() < (float)i * f - (float)j)
    084                {
    085                    ++j;
    086                }
    087
    088                i = j;
    089            }
    090
    091            while (i > 0)
    092            {
    093                j = EntityXPOrb.getXPSplit(i);
    094                i -= j;
    095                this.thePlayer.worldObj.spawnEntityInWorld(new EntityXPOrb(this.thePlayer.worldObj, this.thePlayer.posX, this.thePlayer.posY + 0.5D, this.thePlayer.posZ + 0.5D, j));
    096            }
    097        }
    098
    099        this.field_75228_b = 0;
    100
    101        GameRegistry.onItemSmelted(thePlayer, par1ItemStack);
    102
    103        if (par1ItemStack.itemID == Item.ingotIron.itemID)
    104        {
    105            this.thePlayer.addStat(AchievementList.acquireIron, 1);
    106        }
    107
    108        if (par1ItemStack.itemID == Item.fishCooked.itemID)
    109        {
    110            this.thePlayer.addStat(AchievementList.cookFish, 1);
    111        }
    112    }
    113}