    001    package net.minecraft.src;
    002
    003    public class TileEntityNote extends TileEntity
    004    {
    005        /** Note to play */
    006        public byte note = 0;
    007
    008        /** stores the latest redstone state */
    009        public boolean previousRedstoneState = false;
    010
    011        /**
    012         * Writes a tile entity to NBT.
    013         */
    014        public void writeToNBT(NBTTagCompound par1NBTTagCompound)
    015        {
    016            super.writeToNBT(par1NBTTagCompound);
    017            par1NBTTagCompound.setByte("note", this.note);
    018        }
    019
    020        /**
    021         * Reads a tile entity from NBT.
    022         */
    023        public void readFromNBT(NBTTagCompound par1NBTTagCompound)
    024        {
    025            super.readFromNBT(par1NBTTagCompound);
    026            this.note = par1NBTTagCompound.getByte("note");
    027
    028            if (this.note < 0)
    029            {
    030                this.note = 0;
    031            }
    032
    033            if (this.note > 24)
    034            {
    035                this.note = 24;
    036            }
    037        }
    038
    039        /**
    040         * change pitch by -> (currentPitch + 1) % 25
    041         */
    042        public void changePitch()
    043        {
    044            this.note = (byte)((this.note + 1) % 25);
    045            this.onInventoryChanged();
    046        }
    047
    048        /**
    049         * plays the stored note
    050         */
    051        public void triggerNote(World par1World, int par2, int par3, int par4)
    052        {
    053            if (par1World.getBlockMaterial(par2, par3 + 1, par4) == Material.air)
    054            {
    055                Material var5 = par1World.getBlockMaterial(par2, par3 - 1, par4);
    056                byte var6 = 0;
    057
    058                if (var5 == Material.rock)
    059                {
    060                    var6 = 1;
    061                }
    062
    063                if (var5 == Material.sand)
    064                {
    065                    var6 = 2;
    066                }
    067
    068                if (var5 == Material.glass)
    069                {
    070                    var6 = 3;
    071                }
    072
    073                if (var5 == Material.wood)
    074                {
    075                    var6 = 4;
    076                }
    077
    078                par1World.addBlockEvent(par2, par3, par4, Block.music.blockID, var6, this.note);
    079            }
    080        }
    081    }