#938: Various Sound API improvements

By: Jishuna <joshl5324@gmail.com>
This commit is contained in:
Bukkit/Spigot
2023-11-17 19:54:43 +13:00
parent 44cbcb80d4
commit 1f322369a0
4 changed files with 203 additions and 35 deletions

View File

@@ -118,6 +118,14 @@ public class Note {
}
}
private static final float[] pitchArray = new float[25];
static {
for (int i = 0; i <= 24; i++) {
// See https://minecraft.wiki/w/Note_Block#Notes
pitchArray[i] = (float) Math.pow(2, (i - 12) / 12f);
}
}
private final byte note;
/**
@@ -254,6 +262,16 @@ public class Note {
return Tone.getById(note).isSharped(note);
}
/**
* Gets the pitch of this note. This is the value used with
* {@link World#playSound} or the /playsound command.
*
* @return the pitch
*/
public float getPitch() {
return pitchArray[this.note];
}
@Override
public int hashCode() {
final int prime = 31;