    001package net.minecraft.block;
    002
    003import net.minecraft.block.material.Material;
    004import net.minecraft.creativetab.CreativeTabs;
    005import net.minecraft.entity.player.EntityPlayer;
    006import net.minecraft.tileentity.TileEntity;
    007import net.minecraft.tileentity.TileEntityNote;
    008import net.minecraft.world.World;
    009
    010public class BlockNote extends BlockContainer
    011{
    012    public BlockNote(int par1)
    013    {
    014        super(par1, Material.wood);
    015        this.setCreativeTab(CreativeTabs.tabRedstone);
    016    }
    017
    018    /**
    019     * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
    020     * their own) Args: x, y, z, neighbor blockID
    021     */
    022    public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    023    {
    024        boolean flag = par1World.isBlockIndirectlyGettingPowered(par2, par3, par4);
    025        TileEntityNote tileentitynote = (TileEntityNote)par1World.getBlockTileEntity(par2, par3, par4);
    026
    027        if (tileentitynote != null && tileentitynote.previousRedstoneState != flag)
    028        {
    029            if (flag)
    030            {
    031                tileentitynote.triggerNote(par1World, par2, par3, par4);
    032            }
    033
    034            tileentitynote.previousRedstoneState = flag;
    035        }
    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.isRemote)
    044        {
    045            return true;
    046        }
    047        else
    048        {
    049            TileEntityNote tileentitynote = (TileEntityNote)par1World.getBlockTileEntity(par2, par3, par4);
    050
    051            if (tileentitynote != null)
    052            {
    053                tileentitynote.changePitch();
    054                tileentitynote.triggerNote(par1World, par2, par3, par4);
    055            }
    056
    057            return true;
    058        }
    059    }
    060
    061    /**
    062     * Called when the block is clicked by a player. Args: x, y, z, entityPlayer
    063     */
    064    public void onBlockClicked(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)
    065    {
    066        if (!par1World.isRemote)
    067        {
    068            TileEntityNote tileentitynote = (TileEntityNote)par1World.getBlockTileEntity(par2, par3, par4);
    069
    070            if (tileentitynote != null)
    071            {
    072                tileentitynote.triggerNote(par1World, par2, par3, par4);
    073            }
    074        }
    075    }
    076
    077    /**
    078     * Returns a new instance of a block's tile entity class. Called on placing the block.
    079     */
    080    public TileEntity createNewTileEntity(World par1World)
    081    {
    082        return new TileEntityNote();
    083    }
    084
    085    /**
    086     * Called when the block receives a BlockEvent - see World.addBlockEvent. By default, passes it on to the tile
    087     * entity at this location. Args: world, x, y, z, blockID, EventID, event parameter
    088     */
    089    public boolean onBlockEventReceived(World par1World, int par2, int par3, int par4, int par5, int par6)
    090    {
    091        float f = (float)Math.pow(2.0D, (double)(par6 - 12) / 12.0D);
    092        String s = "harp";
    093
    094        if (par5 == 1)
    095        {
    096            s = "bd";
    097        }
    098
    099        if (par5 == 2)
    100        {
    101            s = "snare";
    102        }
    103
    104        if (par5 == 3)
    105        {
    106            s = "hat";
    107        }
    108
    109        if (par5 == 4)
    110        {
    111            s = "bassattack";
    112        }
    113
    114        par1World.playSoundEffect((double)par2 + 0.5D, (double)par3 + 0.5D, (double)par4 + 0.5D, "note." + s, 3.0F, f);
    115        par1World.spawnParticle("note", (double)par2 + 0.5D, (double)par3 + 1.2D, (double)par4 + 0.5D, (double)par6 / 24.0D, 0.0D, 0.0D);
    116        return true;
    117    }
    118}