    001package net.minecraft.block;
    002
    003import net.minecraft.block.material.Material;
    004import net.minecraft.creativetab.CreativeTabs;
    005import net.minecraft.entity.item.EntityItem;
    006import net.minecraft.entity.player.EntityPlayer;
    007import net.minecraft.item.ItemStack;
    008import net.minecraft.tileentity.TileEntity;
    009import net.minecraft.world.World;
    010
    011public class BlockJukeBox extends BlockContainer
    012{
    013    protected BlockJukeBox(int par1, int par2)
    014    {
    015        super(par1, par2, Material.wood);
    016        this.setCreativeTab(CreativeTabs.tabDecorations);
    017    }
    018
    019    /**
    020     * Returns the block texture based on the side being looked at.  Args: side
    021     */
    022    public int getBlockTextureFromSide(int par1)
    023    {
    024        return this.blockIndexInTexture + (par1 == 1 ? 1 : 0);
    025    }
    026
    027    /**
    028     * Called upon block activation (right click on the block.)
    029     */
    030    public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
    031    {
    032        if (par1World.getBlockMetadata(par2, par3, par4) == 0)
    033        {
    034            return false;
    035        }
    036        else
    037        {
    038            this.ejectRecord(par1World, par2, par3, par4);
    039            return true;
    040        }
    041    }
    042
    043    /**
    044     * Insert the specified music disc in the jukebox at the given coordinates
    045     */
    046    public void insertRecord(World par1World, int par2, int par3, int par4, ItemStack par5ItemStack)
    047    {
    048        if (!par1World.isRemote)
    049        {
    050            TileEntityRecordPlayer var6 = (TileEntityRecordPlayer)par1World.getBlockTileEntity(par2, par3, par4);
    051
    052            if (var6 != null)
    053            {
    054                var6.record = par5ItemStack.copy();
    055                var6.onInventoryChanged();
    056                par1World.setBlockMetadataWithNotify(par2, par3, par4, 1);
    057            }
    058        }
    059    }
    060
    061    /**
    062     * Ejects the current record inside of the jukebox.
    063     */
    064    public void ejectRecord(World par1World, int par2, int par3, int par4)
    065    {
    066        if (!par1World.isRemote)
    067        {
    068            TileEntityRecordPlayer var5 = (TileEntityRecordPlayer)par1World.getBlockTileEntity(par2, par3, par4);
    069
    070            if (var5 != null)
    071            {
    072                ItemStack var6 = var5.record;
    073
    074                if (var6 != null)
    075                {
    076                    par1World.playAuxSFX(1005, par2, par3, par4, 0);
    077                    par1World.playRecord((String)null, par2, par3, par4);
    078                    var5.record = null;
    079                    var5.onInventoryChanged();
    080                    par1World.setBlockMetadataWithNotify(par2, par3, par4, 0);
    081                    float var7 = 0.7F;
    082                    double var8 = (double)(par1World.rand.nextFloat() * var7) + (double)(1.0F - var7) * 0.5D;
    083                    double var10 = (double)(par1World.rand.nextFloat() * var7) + (double)(1.0F - var7) * 0.2D + 0.6D;
    084                    double var12 = (double)(par1World.rand.nextFloat() * var7) + (double)(1.0F - var7) * 0.5D;
    085                    ItemStack var14 = var6.copy();
    086                    EntityItem var15 = new EntityItem(par1World, (double)par2 + var8, (double)par3 + var10, (double)par4 + var12, var14);
    087                    var15.delayBeforeCanPickup = 10;
    088                    par1World.spawnEntityInWorld(var15);
    089                }
    090            }
    091        }
    092    }
    093
    094    /**
    095     * ejects contained items into the world, and notifies neighbours of an update, as appropriate
    096     */
    097    public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
    098    {
    099        this.ejectRecord(par1World, par2, par3, par4);
    100        super.breakBlock(par1World, par2, par3, par4, par5, par6);
    101    }
    102
    103    /**
    104     * Drops the block items with a specified chance of dropping the specified items
    105     */
    106    public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7)
    107    {
    108        if (!par1World.isRemote)
    109        {
    110            super.dropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, 0);
    111        }
    112    }
    113
    114    /**
    115     * Returns a new instance of a block's tile entity class. Called on placing the block.
    116     */
    117    public TileEntity createNewTileEntity(World par1World)
    118    {
    119        return new TileEntityRecordPlayer();
    120    }
    121}