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