    001package net.minecraft.block;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import net.minecraft.block.material.Material;
    006import net.minecraft.client.renderer.texture.IconRegister;
    007import net.minecraft.creativetab.CreativeTabs;
    008import net.minecraft.entity.item.EntityItem;
    009import net.minecraft.entity.player.EntityPlayer;
    010import net.minecraft.item.Item;
    011import net.minecraft.item.ItemStack;
    012import net.minecraft.tileentity.TileEntity;
    013import net.minecraft.tileentity.TileEntityRecordPlayer;
    014import net.minecraft.util.Icon;
    015import net.minecraft.world.World;
    016
    017public class BlockJukeBox extends BlockContainer
    018{
    019    @SideOnly(Side.CLIENT)
    020    private Icon field_94450_a;
    021
    022    protected BlockJukeBox(int par1)
    023    {
    024        super(par1, Material.wood);
    025        this.setCreativeTab(CreativeTabs.tabDecorations);
    026    }
    027
    028    @SideOnly(Side.CLIENT)
    029
    030    /**
    031     * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
    032     */
    033    public Icon getBlockTextureFromSideAndMetadata(int par1, int par2)
    034    {
    035        return par1 == 1 ? this.field_94450_a : this.field_94336_cN;
    036    }
    037
    038    /**
    039     * Called upon block activation (right click on the block.)
    040     */
    041    public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
    042    {
    043        if (par1World.getBlockMetadata(par2, par3, par4) == 0)
    044        {
    045            return false;
    046        }
    047        else
    048        {
    049            this.ejectRecord(par1World, par2, par3, par4);
    050            return true;
    051        }
    052    }
    053
    054    /**
    055     * Insert the specified music disc in the jukebox at the given coordinates
    056     */
    057    public void insertRecord(World par1World, int par2, int par3, int par4, ItemStack par5ItemStack)
    058    {
    059        if (!par1World.isRemote)
    060        {
    061            TileEntityRecordPlayer tileentityrecordplayer = (TileEntityRecordPlayer)par1World.getBlockTileEntity(par2, par3, par4);
    062
    063            if (tileentityrecordplayer != null)
    064            {
    065                tileentityrecordplayer.func_96098_a(par5ItemStack.copy());
    066                par1World.setBlockMetadataWithNotify(par2, par3, par4, 1, 2);
    067            }
    068        }
    069    }
    070
    071    /**
    072     * Ejects the current record inside of the jukebox.
    073     */
    074    public void ejectRecord(World par1World, int par2, int par3, int par4)
    075    {
    076        if (!par1World.isRemote)
    077        {
    078            TileEntityRecordPlayer tileentityrecordplayer = (TileEntityRecordPlayer)par1World.getBlockTileEntity(par2, par3, par4);
    079
    080            if (tileentityrecordplayer != null)
    081            {
    082                ItemStack itemstack = tileentityrecordplayer.func_96097_a();
    083
    084                if (itemstack != null)
    085                {
    086                    par1World.playAuxSFX(1005, par2, par3, par4, 0);
    087                    par1World.playRecord((String)null, par2, par3, par4);
    088                    tileentityrecordplayer.func_96098_a((ItemStack)null);
    089                    par1World.setBlockMetadataWithNotify(par2, par3, par4, 0, 2);
    090                    float f = 0.7F;
    091                    double d0 = (double)(par1World.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
    092                    double d1 = (double)(par1World.rand.nextFloat() * f) + (double)(1.0F - f) * 0.2D + 0.6D;
    093                    double d2 = (double)(par1World.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
    094                    ItemStack itemstack1 = itemstack.copy();
    095                    EntityItem entityitem = new EntityItem(par1World, (double)par2 + d0, (double)par3 + d1, (double)par4 + d2, itemstack1);
    096                    entityitem.delayBeforeCanPickup = 10;
    097                    par1World.spawnEntityInWorld(entityitem);
    098                }
    099            }
    100        }
    101    }
    102
    103    /**
    104     * ejects contained items into the world, and notifies neighbours of an update, as appropriate
    105     */
    106    public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
    107    {
    108        this.ejectRecord(par1World, par2, par3, par4);
    109        super.breakBlock(par1World, par2, par3, par4, par5, par6);
    110    }
    111
    112    /**
    113     * Drops the block items with a specified chance of dropping the specified items
    114     */
    115    public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7)
    116    {
    117        if (!par1World.isRemote)
    118        {
    119            super.dropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, 0);
    120        }
    121    }
    122
    123    /**
    124     * Returns a new instance of a block's tile entity class. Called on placing the block.
    125     */
    126    public TileEntity createNewTileEntity(World par1World)
    127    {
    128        return new TileEntityRecordPlayer();
    129    }
    130
    131    @SideOnly(Side.CLIENT)
    132    public void func_94332_a(IconRegister par1IconRegister)
    133    {
    134        this.field_94336_cN = par1IconRegister.func_94245_a("musicBlock");
    135        this.field_94450_a = par1IconRegister.func_94245_a("jukebox_top");
    136    }
    137
    138    public boolean func_96468_q_()
    139    {
    140        return true;
    141    }
    142
    143    public int func_94328_b_(World par1World, int par2, int par3, int par4, int par5)
    144    {
    145        ItemStack itemstack = ((TileEntityRecordPlayer)par1World.getBlockTileEntity(par2, par3, par4)).func_96097_a();
    146        return itemstack == null ? 0 : itemstack.itemID + 1 - Item.record13.itemID;
    147    }
    148}