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        /**
036         * Inserts the given record into the JukeBox.
037         */
038        public void insertRecord(World par1World, int par2, int par3, int par4, int par5)
039        {
040            if (!par1World.isRemote)
041            {
042                TileEntityRecordPlayer var6 = (TileEntityRecordPlayer)par1World.getBlockTileEntity(par2, par3, par4);
043    
044                if (var6 != null)
045                {
046                    var6.record = par5;
047                    var6.onInventoryChanged();
048                    par1World.setBlockMetadataWithNotify(par2, par3, par4, 1);
049                }
050            }
051        }
052    
053        /**
054         * Ejects the current record inside of the jukebox.
055         */
056        public void ejectRecord(World par1World, int par2, int par3, int par4)
057        {
058            if (!par1World.isRemote)
059            {
060                TileEntityRecordPlayer var5 = (TileEntityRecordPlayer)par1World.getBlockTileEntity(par2, par3, par4);
061    
062                if (var5 != null)
063                {
064                    int var6 = var5.record;
065    
066                    if (var6 != 0)
067                    {
068                        par1World.playAuxSFX(1005, par2, par3, par4, 0);
069                        par1World.playRecord((String)null, par2, par3, par4);
070                        var5.record = 0;
071                        var5.onInventoryChanged();
072                        par1World.setBlockMetadataWithNotify(par2, par3, par4, 0);
073                        float var7 = 0.7F;
074                        double var8 = (double)(par1World.rand.nextFloat() * var7) + (double)(1.0F - var7) * 0.5D;
075                        double var10 = (double)(par1World.rand.nextFloat() * var7) + (double)(1.0F - var7) * 0.2D + 0.6D;
076                        double var12 = (double)(par1World.rand.nextFloat() * var7) + (double)(1.0F - var7) * 0.5D;
077                        EntityItem var14 = new EntityItem(par1World, (double)par2 + var8, (double)par3 + var10, (double)par4 + var12, new ItemStack(var6, 1, 0));
078                        var14.delayBeforeCanPickup = 10;
079                        par1World.spawnEntityInWorld(var14);
080                    }
081                }
082            }
083        }
084    
085        /**
086         * ejects contained items into the world, and notifies neighbours of an update, as appropriate
087         */
088        public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
089        {
090            this.ejectRecord(par1World, par2, par3, par4);
091            super.breakBlock(par1World, par2, par3, par4, par5, par6);
092        }
093    
094        /**
095         * Drops the block items with a specified chance of dropping the specified items
096         */
097        public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7)
098        {
099            if (!par1World.isRemote)
100            {
101                super.dropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, 0);
102            }
103        }
104    
105        /**
106         * Returns a new instance of a block's tile entity class. Called on placing the block.
107         */
108        public TileEntity createNewTileEntity(World par1World)
109        {
110            return new TileEntityRecordPlayer();
111        }
112    }