    001package net.minecraft.block;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import net.minecraft.client.renderer.texture.IconRegister;
    006import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
    007import net.minecraft.dispenser.IBehaviorDispenseItem;
    008import net.minecraft.inventory.IInventory;
    009import net.minecraft.item.ItemStack;
    010import net.minecraft.tileentity.TileEntity;
    011import net.minecraft.tileentity.TileEntityDispenser;
    012import net.minecraft.tileentity.TileEntityDropper;
    013import net.minecraft.tileentity.TileEntityHopper;
    014import net.minecraft.util.Facing;
    015import net.minecraft.world.World;
    016
    017public class BlockDropper extends BlockDispenser
    018{
    019    private final IBehaviorDispenseItem field_96474_cR = new BehaviorDefaultDispenseItem();
    020
    021    protected BlockDropper(int par1)
    022    {
    023        super(par1);
    024    }
    025
    026    @SideOnly(Side.CLIENT)
    027    public void func_94332_a(IconRegister par1IconRegister)
    028    {
    029        this.field_94336_cN = par1IconRegister.func_94245_a("furnace_side");
    030        this.field_94463_c = par1IconRegister.func_94245_a("furnace_top");
    031        this.field_94462_cO = par1IconRegister.func_94245_a("dropper_front");
    032        this.field_96473_e = par1IconRegister.func_94245_a("dropper_front_vertical");
    033    }
    034
    035    protected IBehaviorDispenseItem func_96472_a(ItemStack par1ItemStack)
    036    {
    037        return this.field_96474_cR;
    038    }
    039
    040    /**
    041     * Returns a new instance of a block's tile entity class. Called on placing the block.
    042     */
    043    public TileEntity createNewTileEntity(World par1World)
    044    {
    045        return new TileEntityDropper();
    046    }
    047
    048    protected void dispense(World par1World, int par2, int par3, int par4)
    049    {
    050        BlockSourceImpl blocksourceimpl = new BlockSourceImpl(par1World, par2, par3, par4);
    051        TileEntityDispenser tileentitydispenser = (TileEntityDispenser)blocksourceimpl.func_82619_j();
    052
    053        if (tileentitydispenser != null)
    054        {
    055            int l = tileentitydispenser.getRandomStackFromInventory();
    056
    057            if (l < 0)
    058            {
    059                par1World.playAuxSFX(1001, par2, par3, par4, 0);
    060            }
    061            else
    062            {
    063                ItemStack itemstack = tileentitydispenser.getStackInSlot(l);
    064                int i1 = par1World.getBlockMetadata(par2, par3, par4) & 7;
    065                IInventory iinventory = TileEntityHopper.func_96117_b(par1World, (double)(par2 + Facing.offsetsXForSide[i1]), (double)(par3 + Facing.offsetsYForSide[i1]), (double)(par4 + Facing.offsetsZForSide[i1]));
    066                ItemStack itemstack1;
    067
    068                if (iinventory != null)
    069                {
    070                    itemstack1 = TileEntityHopper.func_94117_a(iinventory, itemstack.copy().splitStack(1), Facing.faceToSide[i1]);
    071
    072                    if (itemstack1 == null)
    073                    {
    074                        itemstack1 = itemstack.copy();
    075
    076                        if (--itemstack1.stackSize == 0)
    077                        {
    078                            itemstack1 = null;
    079                        }
    080                    }
    081                    else
    082                    {
    083                        itemstack1 = itemstack.copy();
    084                    }
    085                }
    086                else
    087                {
    088                    itemstack1 = this.field_96474_cR.dispense(blocksourceimpl, itemstack);
    089
    090                    if (itemstack1 != null && itemstack1.stackSize == 0)
    091                    {
    092                        itemstack1 = null;
    093                    }
    094                }
    095
    096                tileentitydispenser.setInventorySlotContents(l, itemstack1);
    097            }
    098        }
    099    }
    100}