001/*
002 * Trident - A Multithreaded Server Alternative
003 * Copyright 2014 The TridentSDK Team
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *    http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package net.tridentsdk.base;
019
020/**
021 * Represents the instruments that can be played on a note block
022 *
023 * @author The TridentSDK Team
024 * @since 0.3-alpha-DP
025 */
026public enum Instrument {
027    /**
028     * Piano note
029     */
030    PIANO(0x0),
031    /**
032     * Bass drum note
033     */
034    BASS_DRUM(0x1),
035    /**
036     * Snare drum note
037     */
038    SNARE_DRUM(0x2),
039    /**
040     * Stick note
041     */
042    STICKS(0x3),
043    /**
044     * Bass guitar note
045     */
046    BASS_GUITAR(0x4);
047
048    final byte id;
049
050    Instrument(int i) {
051        this.id = (byte) i;
052    }
053
054    /**
055     * Resolves the Instrument from its respective Byte value
056     *
057     * @param b Byte representing the Instrument
058     * @return Instrument from the supplied Byte
059     */
060    public static Instrument fromByte(byte b) {
061        switch ((int) b) {
062            case 0x0:
063                return PIANO;
064            case 0x1:
065                return BASS_DRUM;
066            case 0x2:
067                return SNARE_DRUM;
068            case 0x3:
069                return STICKS;
070            case 0x4:
071                return BASS_GUITAR;
072            default:
073                return null;
074        }
075    }
076
077    /**
078     * Returns the {@code byte} value of the Instrument
079     *
080     * @return Byte value of the Instrument
081     */
082    public byte asByte() {
083        return this.id;
084    }
085}