Skip to content

Commit 6702a4a

Browse files
authored
Support sounds outside 2 octave range using resource pack (#50)
* Transpose notes * Support 6 octave range * Prefixes * Javadocs * Add SongPlayer#enable6Octave and corresponding getter and setter * Resource pack update * Resource pack fixes * Redirect original getPitch to transposed sounds * Bedrock Edition resource pack for servers using Geyser or Geyser-like * Made requested changes Use original method to get pitch Apply pitch to key first * Update resource packs * 10 octave range support * Update resourcepacks * Disable by default
1 parent e24f4b2 commit 6702a4a

File tree

13 files changed

+274
-67
lines changed

13 files changed

+274
-67
lines changed

Instruments.zip

833 KB
Binary file not shown.

InstrumentsBE.mcpack

914 KB
Binary file not shown.

src/main/java/com/xxmicloxx/NoteBlockAPI/model/playmode/ChannelMode.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
*/
1313
public abstract class ChannelMode {
1414

15+
@Deprecated
1516
public abstract void play(Player player, Location location, Song song, Layer layer, Note note,
1617
SoundCategory soundCategory, float volume, float pitch);
18+
19+
public abstract void play(Player player, Location location, Song song, Layer layer, Note note,
20+
SoundCategory soundCategory, float volume, boolean doTranspose);
1721
}

src/main/java/com/xxmicloxx/NoteBlockAPI/model/playmode/MonoMode.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.xxmicloxx.NoteBlockAPI.model.*;
44
import com.xxmicloxx.NoteBlockAPI.utils.CompatibilityUtils;
55
import com.xxmicloxx.NoteBlockAPI.utils.InstrumentUtils;
6+
import com.xxmicloxx.NoteBlockAPI.utils.NoteUtils;
67
import org.bukkit.Location;
78
import org.bukkit.entity.Player;
89

@@ -16,13 +17,25 @@ public void play(Player player, Location location, Song song, Layer layer, Note
1617
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
1718
CustomInstrument instrument = song.getCustomInstruments()[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
1819

19-
if (instrument.getSound() != null) {
20-
CompatibilityUtils.playSound(player, location, instrument.getSound(), soundCategory, volume, pitch, 0);
21-
} else {
22-
CompatibilityUtils.playSound(player, location, instrument.getSoundFileName(), soundCategory, volume, pitch, 0);
23-
}
20+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(instrument.getSoundFileName(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, 0);
2421
} else {
25-
CompatibilityUtils.playSound(player, location, InstrumentUtils.getInstrument(note.getInstrument()), soundCategory, volume, pitch, 0);
22+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(note.getInstrument(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, 0);
23+
}
24+
}
25+
26+
@Override
27+
public void play(Player player, Location location, Song song, Layer layer, Note note, SoundCategory soundCategory, float volume, boolean doTranspose) {
28+
float pitch;
29+
if(doTranspose)
30+
pitch = NoteUtils.getPitchTransposed(note);
31+
else
32+
pitch = NoteUtils.getPitchInOctave(note);
33+
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
34+
CustomInstrument instrument = song.getCustomInstruments()[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
35+
36+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(instrument.getSoundFileName(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, 0);
37+
} else {
38+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(note.getInstrument(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, 0);
2639
}
2740
}
2841
}

src/main/java/com/xxmicloxx/NoteBlockAPI/model/playmode/MonoStereoMode.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.xxmicloxx.NoteBlockAPI.model.*;
44
import com.xxmicloxx.NoteBlockAPI.utils.CompatibilityUtils;
55
import com.xxmicloxx.NoteBlockAPI.utils.InstrumentUtils;
6+
import com.xxmicloxx.NoteBlockAPI.utils.NoteUtils;
67
import org.bukkit.Location;
78
import org.bukkit.entity.Player;
89

@@ -18,16 +19,30 @@ public void play(Player player, Location location, Song song, Layer layer, Note
1819
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
1920
CustomInstrument instrument = song.getCustomInstruments()[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
2021

21-
if (instrument.getSound() != null) {
22-
CompatibilityUtils.playSound(player, location, instrument.getSound(), soundCategory, volume, pitch, distance);
23-
CompatibilityUtils.playSound(player, location, instrument.getSound(), soundCategory, volume, pitch, -distance);
24-
} else {
25-
CompatibilityUtils.playSound(player, location, instrument.getSoundFileName(), soundCategory, volume, pitch, distance);
26-
CompatibilityUtils.playSound(player, location, instrument.getSoundFileName(), soundCategory, volume, pitch, -distance);
27-
}
22+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(instrument.getSoundFileName(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, distance);
23+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(instrument.getSoundFileName(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, -distance);
2824
} else {
29-
CompatibilityUtils.playSound(player, location, InstrumentUtils.getInstrument(note.getInstrument()), soundCategory, volume, pitch, distance);
30-
CompatibilityUtils.playSound(player, location, InstrumentUtils.getInstrument(note.getInstrument()), soundCategory, volume, pitch, -distance);
25+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(note.getInstrument(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, distance);
26+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(note.getInstrument(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, -distance);
27+
}
28+
}
29+
30+
@Override
31+
public void play(Player player, Location location, Song song, Layer layer, Note note, SoundCategory soundCategory, float volume, boolean doTranspose) {
32+
float pitch;
33+
if(doTranspose)
34+
pitch = NoteUtils.getPitchTransposed(note);
35+
else
36+
pitch = NoteUtils.getPitchInOctave(note);
37+
38+
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
39+
CustomInstrument instrument = song.getCustomInstruments()[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
40+
41+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(instrument.getSoundFileName(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, distance);
42+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(instrument.getSoundFileName(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, -distance);
43+
} else {
44+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(note.getInstrument(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, distance);
45+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(note.getInstrument(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, -distance);
3146
}
3247
}
3348

src/main/java/com/xxmicloxx/NoteBlockAPI/model/playmode/StereoMode.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.xxmicloxx.NoteBlockAPI.model.*;
44
import com.xxmicloxx.NoteBlockAPI.utils.CompatibilityUtils;
55
import com.xxmicloxx.NoteBlockAPI.utils.InstrumentUtils;
6+
import com.xxmicloxx.NoteBlockAPI.utils.NoteUtils;
67
import org.bukkit.Location;
78
import org.bukkit.entity.Player;
89

@@ -30,13 +31,37 @@ public void play(Player player, Location location, Song song, Layer layer, Note
3031
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
3132
CustomInstrument instrument = song.getCustomInstruments()[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
3233

33-
if (instrument.getSound() != null) {
34-
CompatibilityUtils.playSound(player, location, instrument.getSound(), soundCategory, volume, pitch, distance);
35-
} else {
36-
CompatibilityUtils.playSound(player, location, instrument.getSoundFileName(), soundCategory, volume, pitch, distance);
37-
}
34+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(instrument.getSoundFileName(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, distance);
3835
} else {
39-
CompatibilityUtils.playSound(player, location, InstrumentUtils.getInstrument(note.getInstrument()), soundCategory, volume, pitch, distance);
36+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(note.getInstrument(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, distance);
37+
}
38+
}
39+
40+
@Override
41+
public void play(Player player, Location location, Song song, Layer layer, Note note, SoundCategory soundCategory, float volume, boolean doTranspose) {
42+
if (!song.isStereo() && fallbackChannelMode != null){
43+
fallbackChannelMode.play(player, location, song, layer, note, soundCategory, volume, doTranspose);
44+
return;
45+
}
46+
47+
float pitch;
48+
if(doTranspose)
49+
pitch = NoteUtils.getPitchTransposed(note);
50+
else
51+
pitch = NoteUtils.getPitchInOctave(note);
52+
53+
float distance = 0;
54+
if (layer.getPanning() == 100){
55+
distance = (note.getPanning() - 100) * maxDistance;
56+
} else {
57+
distance = ((layer.getPanning() - 100 + note.getPanning() - 100) / 200f) * maxDistance;
58+
}
59+
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
60+
CustomInstrument instrument = song.getCustomInstruments()[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
61+
62+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(instrument.getSoundFileName(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, distance);
63+
} else {
64+
CompatibilityUtils.playSound(player, location, InstrumentUtils.warpNameOutOfRange(note.getInstrument(), note.getKey(), note.getPitch()), soundCategory, volume, pitch, distance);
4065
}
4166
}
4267

src/main/java/com/xxmicloxx/NoteBlockAPI/songplayer/EntitySongPlayer.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
import com.xxmicloxx.NoteBlockAPI.NoteBlockAPI;
44
import com.xxmicloxx.NoteBlockAPI.event.PlayerRangeStateChangeEvent;
55
import com.xxmicloxx.NoteBlockAPI.model.*;
6-
import com.xxmicloxx.NoteBlockAPI.utils.CompatibilityUtils;
7-
import com.xxmicloxx.NoteBlockAPI.utils.InstrumentUtils;
8-
import com.xxmicloxx.NoteBlockAPI.utils.NoteUtils;
96
import org.bukkit.Bukkit;
107
import org.bukkit.entity.Entity;
118
import org.bukkit.entity.Player;
@@ -77,9 +74,8 @@ public void playTick(Player player, int tick) {
7774

7875
float volume = ((layer.getVolume() * (int) this.volume * (int) playerVolume * note.getVelocity()) / 100_00_00_00F)
7976
* ((1F / 16F) * getDistance());
80-
float pitch = NoteUtils.getPitch(note);
8177

82-
channelMode.play(player, entity.getLocation(), song, layer, note, soundCategory, volume, pitch);
78+
channelMode.play(player, entity.getLocation(), song, layer, note, soundCategory, volume, !enable10Octave);
8379

8480
if (isInRange(player)) {
8581
if (!this.playerList.get(player.getUniqueId())) {

src/main/java/com/xxmicloxx/NoteBlockAPI/songplayer/NoteBlockSongPlayer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,11 @@
1010
import com.xxmicloxx.NoteBlockAPI.NoteBlockAPI;
1111
import com.xxmicloxx.NoteBlockAPI.SongPlayer;
1212
import com.xxmicloxx.NoteBlockAPI.event.PlayerRangeStateChangeEvent;
13-
import com.xxmicloxx.NoteBlockAPI.model.CustomInstrument;
1413
import com.xxmicloxx.NoteBlockAPI.model.Layer;
1514
import com.xxmicloxx.NoteBlockAPI.model.Note;
16-
import com.xxmicloxx.NoteBlockAPI.model.NotePitch;
1715
import com.xxmicloxx.NoteBlockAPI.model.Playlist;
1816
import com.xxmicloxx.NoteBlockAPI.model.Song;
1917
import com.xxmicloxx.NoteBlockAPI.model.SoundCategory;
20-
import com.xxmicloxx.NoteBlockAPI.utils.CompatibilityUtils;
2118
import com.xxmicloxx.NoteBlockAPI.utils.InstrumentUtils;
2219

2320
/**
@@ -104,7 +101,7 @@ public void playTick(Player player, int tick) {
104101
* ((1F / 16F) * getDistance());
105102
float pitch = NoteUtils.getPitch(note);
106103

107-
channelMode.play(player, loc, song, layer, note, soundCategory, volume, pitch);
104+
channelMode.play(player, loc, song, layer, note, soundCategory, volume, !enable10Octave);
108105

109106
if (isInRange(player)) {
110107
if (!this.playerList.get(player.getUniqueId())) {

src/main/java/com/xxmicloxx/NoteBlockAPI/songplayer/PositionSongPlayer.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
package com.xxmicloxx.NoteBlockAPI.songplayer;
22

3-
import com.xxmicloxx.NoteBlockAPI.utils.NoteUtils;
43
import org.bukkit.Bukkit;
54
import org.bukkit.Location;
65
import org.bukkit.entity.Player;
76

87
import com.xxmicloxx.NoteBlockAPI.NoteBlockAPI;
98
import com.xxmicloxx.NoteBlockAPI.SongPlayer;
109
import com.xxmicloxx.NoteBlockAPI.event.PlayerRangeStateChangeEvent;
11-
import com.xxmicloxx.NoteBlockAPI.model.CustomInstrument;
1210
import com.xxmicloxx.NoteBlockAPI.model.Layer;
1311
import com.xxmicloxx.NoteBlockAPI.model.Note;
14-
import com.xxmicloxx.NoteBlockAPI.model.NotePitch;
1512
import com.xxmicloxx.NoteBlockAPI.model.Playlist;
1613
import com.xxmicloxx.NoteBlockAPI.model.Song;
1714
import com.xxmicloxx.NoteBlockAPI.model.SoundCategory;
18-
import com.xxmicloxx.NoteBlockAPI.utils.CompatibilityUtils;
19-
import com.xxmicloxx.NoteBlockAPI.utils.InstrumentUtils;
2015

2116
/**
2217
* SongPlayer created at a specified Location
@@ -91,9 +86,8 @@ public void playTick(Player player, int tick) {
9186

9287
float volume = ((layer.getVolume() * (int) this.volume * (int) playerVolume * note.getVelocity()) / 100_00_00_00F)
9388
* ((1F / 16F) * getDistance());
94-
float pitch = NoteUtils.getPitch(note);
9589

96-
channelMode.play(player, targetLocation, song, layer, note, soundCategory, volume, pitch);
90+
channelMode.play(player, targetLocation, song, layer, note, soundCategory, volume, !enable10Octave);
9791

9892
if (isInRange(player)) {
9993
if (!this.playerList.get(player.getUniqueId())) {

src/main/java/com/xxmicloxx/NoteBlockAPI/songplayer/RadioSongPlayer.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@
33
import com.xxmicloxx.NoteBlockAPI.model.playmode.ChannelMode;
44
import com.xxmicloxx.NoteBlockAPI.model.playmode.MonoMode;
55
import com.xxmicloxx.NoteBlockAPI.model.playmode.MonoStereoMode;
6-
import com.xxmicloxx.NoteBlockAPI.utils.NoteUtils;
76
import org.bukkit.entity.Player;
87

98
import com.xxmicloxx.NoteBlockAPI.NoteBlockAPI;
10-
import com.xxmicloxx.NoteBlockAPI.model.CustomInstrument;
119
import com.xxmicloxx.NoteBlockAPI.model.Layer;
1210
import com.xxmicloxx.NoteBlockAPI.model.Note;
13-
import com.xxmicloxx.NoteBlockAPI.model.NotePitch;
1411
import com.xxmicloxx.NoteBlockAPI.model.Playlist;
1512
import com.xxmicloxx.NoteBlockAPI.model.Song;
1613
import com.xxmicloxx.NoteBlockAPI.model.SoundCategory;
17-
import com.xxmicloxx.NoteBlockAPI.utils.CompatibilityUtils;
18-
import com.xxmicloxx.NoteBlockAPI.utils.InstrumentUtils;
1914

2015
/**
2116
* SongPlayer playing to everyone added to it no matter where he is
@@ -60,9 +55,8 @@ public void playTick(Player player, int tick) {
6055
}
6156

6257
float volume = (layer.getVolume() * (int) this.volume * (int) playerVolume * note.getVelocity()) / 100_00_00_00F;
63-
float pitch = NoteUtils.getPitch(note);
6458

65-
channelMode.play(player, player.getEyeLocation(), song, layer, note, soundCategory, volume, pitch);
59+
channelMode.play(player, player.getEyeLocation(), song, layer, note, soundCategory, volume, !enable10Octave);
6660
}
6761
}
6862

0 commit comments

Comments
 (0)