Skip to content

Commit be6f867

Browse files
authored
Merge pull request #41 from koca2000/NBS4.0
Support for NBS v4.0 features
2 parents 53f7067 + 2de59ac commit be6f867

File tree

17 files changed

+372
-166
lines changed

17 files changed

+372
-166
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.xxmicloxx</groupId>
77
<artifactId>NoteBlockAPI</artifactId>
8-
<version>1.4.5-SNAPSHOT</version>
8+
<version>1.5.0-SNAPSHOT</version>
99
<name>NoteBlockAPI</name>
1010

1111
<properties>
@@ -29,7 +29,7 @@
2929
<dependency>
3030
<groupId>org.spigotmc</groupId>
3131
<artifactId>spigot-api</artifactId>
32-
<version>1.14-R0.1-SNAPSHOT</version>
32+
<version>1.15.2-R0.1-SNAPSHOT</version>
3333
<scope>provided</scope>
3434
</dependency>
3535
<dependency>

src/main/java/com/xxmicloxx/NoteBlockAPI/model/Layer.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class Layer {
1111

1212
private HashMap<Integer, Note> notesAtTicks = new HashMap<Integer, Note>();
1313
private byte volume = 100;
14+
private int panning = 100;
1415
private String name = "";
1516

1617
/**
@@ -72,4 +73,19 @@ public void setVolume(byte volume) {
7273
this.volume = volume;
7374
}
7475

76+
/**
77+
* Gets the panning of all notes in the Layer
78+
* @return byte representing the panning
79+
*/
80+
public int getPanning() {
81+
return panning;
82+
}
83+
84+
/**
85+
* Sets the panning for all notes in the Layer
86+
* @param panning
87+
*/
88+
public void setPanning(int panning) {
89+
this.panning = panning;
90+
}
7591
}

src/main/java/com/xxmicloxx/NoteBlockAPI/model/Note.java

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,20 @@ public class Note {
99

1010
private byte instrument;
1111
private byte key;
12-
12+
private byte velocity;
13+
private int panning;
14+
private short pitch;
15+
1316
public Note(byte instrument, byte key) {
17+
this(instrument, key, (byte) 100, (byte) 100, (short) 0);
18+
}
19+
20+
public Note(byte instrument, byte key, byte velocity, int panning, short pitch) {
1421
this.instrument = instrument;
1522
this.key = key;
23+
this.velocity = velocity;
24+
this.panning = panning;
25+
this.pitch = pitch;
1626
}
1727

1828
/**
@@ -29,11 +39,74 @@ public void setInstrument(byte instrument) {
2939
this.instrument = instrument;
3040
}
3141

42+
/**
43+
* Returns note key number (Minecraft key 0 corresponds to key 33)
44+
* @return
45+
*/
3246
public byte getKey() {
3347
return key;
3448
}
3549

50+
/**
51+
* Sets note key number (Minecraft key 0 corresponds to key 33)
52+
* @param key
53+
*/
3654
public void setKey(byte key) {
3755
this.key = key;
3856
}
57+
58+
/**
59+
* Returns note pitch.
60+
* 100 = 1 key
61+
* 1200 = 1 octave
62+
* @return
63+
*/
64+
public short getPitch() {
65+
return pitch;
66+
}
67+
68+
/**
69+
* Sets note pitch.
70+
* 100 = 1 key
71+
* 1200 = 1 octave
72+
* @param pitch note pitch
73+
*/
74+
public void setPitch(short pitch) {
75+
this.pitch = pitch;
76+
}
77+
78+
/**
79+
* Returns note velocity (volume)
80+
* @return
81+
*/
82+
public byte getVelocity() {
83+
return velocity;
84+
}
85+
86+
/**
87+
* Sets note velocity (volume)
88+
* @param velocity number from 0 - 100
89+
*/
90+
public void setVelocity(byte velocity) {
91+
if (velocity < 0) velocity = 0;
92+
if (velocity > 100) velocity = 100;
93+
94+
this.velocity = velocity;
95+
}
96+
97+
/**
98+
* Returns stereo panning of this note
99+
* @return
100+
*/
101+
public int getPanning() {
102+
return panning;
103+
}
104+
105+
/**
106+
* Sets stereo panning of this note
107+
* @param panning
108+
*/
109+
public void setPanning(int panning) {
110+
this.panning = panning;
111+
}
39112
}

src/main/java/com/xxmicloxx/NoteBlockAPI/model/NotePitch.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
/**
77
* Represents pitches of every noteblock note pre- &amp; post-1.9
8-
*
8+
* @deprecated Use NoteUtils
99
*/
10+
@Deprecated()
1011
public enum NotePitch {
1112

1213
NOTE_0(0, 0.5F, 0.50000F),
@@ -52,6 +53,7 @@ public static float getPitch(int note) {
5253
return pre1_9 ? notePitch.pitchPre1_9 : notePitch.pitchPost1_9;
5354
}
5455
}
56+
5557
return 0.0F;
5658
}
5759

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.xxmicloxx.NoteBlockAPI.model.playmode;
2+
3+
import com.xxmicloxx.NoteBlockAPI.model.Layer;
4+
import com.xxmicloxx.NoteBlockAPI.model.Note;
5+
import com.xxmicloxx.NoteBlockAPI.model.Song;
6+
import com.xxmicloxx.NoteBlockAPI.model.SoundCategory;
7+
import org.bukkit.Location;
8+
import org.bukkit.entity.Player;
9+
10+
public abstract class ChannelMode {
11+
12+
public abstract void play(Player player, Location location, Song song, Layer layer, Note note,
13+
SoundCategory soundCategory, float volume, float pitch);
14+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.xxmicloxx.NoteBlockAPI.model.playmode;
2+
3+
import com.xxmicloxx.NoteBlockAPI.model.*;
4+
import com.xxmicloxx.NoteBlockAPI.utils.CompatibilityUtils;
5+
import com.xxmicloxx.NoteBlockAPI.utils.InstrumentUtils;
6+
import org.bukkit.Location;
7+
import org.bukkit.entity.Player;
8+
9+
public class MonoMode extends ChannelMode {
10+
11+
@Override
12+
public void play(Player player, Location location, Song song, Layer layer, Note note, SoundCategory soundCategory, float volume, float pitch) {
13+
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
14+
CustomInstrument instrument = song.getCustomInstruments()[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
15+
16+
if (instrument.getSound() != null) {
17+
CompatibilityUtils.playSound(player, location, instrument.getSound(), soundCategory, volume, pitch, 0);
18+
} else {
19+
CompatibilityUtils.playSound(player, location, instrument.getSoundFileName(), soundCategory, volume, pitch, 0);
20+
}
21+
} else {
22+
CompatibilityUtils.playSound(player, location, InstrumentUtils.getInstrument(note.getInstrument()), soundCategory, volume, pitch, 0);
23+
}
24+
}
25+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.xxmicloxx.NoteBlockAPI.model.playmode;
2+
3+
import com.xxmicloxx.NoteBlockAPI.model.*;
4+
import com.xxmicloxx.NoteBlockAPI.utils.CompatibilityUtils;
5+
import com.xxmicloxx.NoteBlockAPI.utils.InstrumentUtils;
6+
import org.bukkit.Location;
7+
import org.bukkit.entity.Player;
8+
9+
public class MonoStereoMode extends ChannelMode{
10+
11+
private float distance = 2;
12+
13+
@Override
14+
public void play(Player player, Location location, Song song, Layer layer, Note note, SoundCategory soundCategory, float volume, float pitch) {
15+
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
16+
CustomInstrument instrument = song.getCustomInstruments()[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
17+
18+
if (instrument.getSound() != null) {
19+
CompatibilityUtils.playSound(player, location, instrument.getSound(), soundCategory, volume, pitch, distance);
20+
CompatibilityUtils.playSound(player, location, instrument.getSound(), soundCategory, volume, pitch, -distance);
21+
} else {
22+
CompatibilityUtils.playSound(player, location, instrument.getSoundFileName(), soundCategory, volume, pitch, distance);
23+
CompatibilityUtils.playSound(player, location, instrument.getSoundFileName(), soundCategory, volume, pitch, -distance);
24+
}
25+
} else {
26+
CompatibilityUtils.playSound(player, location, InstrumentUtils.getInstrument(note.getInstrument()), soundCategory, volume, pitch, distance);
27+
CompatibilityUtils.playSound(player, location, InstrumentUtils.getInstrument(note.getInstrument()), soundCategory, volume, pitch, -distance);
28+
}
29+
}
30+
31+
public float getDistance() {
32+
return distance;
33+
}
34+
35+
public void setDistance(float distance) {
36+
this.distance = distance;
37+
}
38+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.xxmicloxx.NoteBlockAPI.model.playmode;
2+
3+
import com.xxmicloxx.NoteBlockAPI.model.*;
4+
import com.xxmicloxx.NoteBlockAPI.utils.CompatibilityUtils;
5+
import com.xxmicloxx.NoteBlockAPI.utils.InstrumentUtils;
6+
import org.bukkit.Location;
7+
import org.bukkit.entity.Player;
8+
9+
public class StereoMode extends ChannelMode {
10+
11+
float maxDistance = 2;
12+
13+
@Override
14+
public void play(Player player, Location location, Song song, Layer layer, Note note, SoundCategory soundCategory, float volume, float pitch) {
15+
float distance = 0;
16+
if (layer.getPanning() == 100){
17+
distance = (note.getPanning() - 100) * maxDistance;
18+
} else {
19+
distance = ((layer.getPanning() - 100 + note.getPanning() - 100) / 200f) * maxDistance;
20+
}
21+
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
22+
CustomInstrument instrument = song.getCustomInstruments()[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
23+
24+
if (instrument.getSound() != null) {
25+
CompatibilityUtils.playSound(player, location, instrument.getSound(), soundCategory, volume, pitch, distance);
26+
} else {
27+
CompatibilityUtils.playSound(player, location, instrument.getSoundFileName(), soundCategory, volume, pitch, distance);
28+
}
29+
} else {
30+
CompatibilityUtils.playSound(player, location, InstrumentUtils.getInstrument(note.getInstrument()), soundCategory, volume, pitch, distance);
31+
}
32+
}
33+
}

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

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.xxmicloxx.NoteBlockAPI.model.*;
66
import com.xxmicloxx.NoteBlockAPI.utils.CompatibilityUtils;
77
import com.xxmicloxx.NoteBlockAPI.utils.InstrumentUtils;
8+
import com.xxmicloxx.NoteBlockAPI.utils.NoteUtils;
89
import org.bukkit.Bukkit;
910
import org.bukkit.entity.Entity;
1011
import org.bukkit.entity.Player;
@@ -74,26 +75,11 @@ public void playTick(Player player, int tick) {
7475
Note note = layer.getNote(tick);
7576
if (note == null) continue;
7677

77-
float volume = ((layer.getVolume() * (int) this.volume * (int) playerVolume) / 1000000F)
78+
float volume = ((layer.getVolume() * (int) this.volume * (int) playerVolume * note.getVelocity()) / 100_00_00_00F)
7879
* ((1F / 16F) * getDistance());
79-
float pitch = NotePitch.getPitch(note.getKey() - 33);
80-
81-
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
82-
CustomInstrument instrument = song.getCustomInstruments()
83-
[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
84-
85-
if (instrument.getSound() != null) {
86-
CompatibilityUtils.playSound(player, entity.getLocation(), instrument.getSound(),
87-
this.soundCategory, volume, pitch, false);
88-
} else {
89-
CompatibilityUtils.playSound(player, entity.getLocation(), instrument.getSoundFileName(),
90-
this.soundCategory, volume, pitch, false);
91-
}
92-
} else {
93-
CompatibilityUtils.playSound(player, entity.getLocation(),
94-
InstrumentUtils.getInstrument(note.getInstrument()), this.soundCategory,
95-
volume, pitch, false);
96-
}
80+
float pitch = NoteUtils.getPitch(note);
81+
82+
channelMode.play(player, entity.getLocation(), song, layer, note, soundCategory, volume, pitch);
9783

9884
if (isInRange(player)) {
9985
if (!this.playerList.get(player.getUniqueId())) {

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

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

3+
import com.xxmicloxx.NoteBlockAPI.utils.NoteUtils;
34
import org.bukkit.Bukkit;
45
import org.bukkit.Location;
56
import org.bukkit.Material;
@@ -99,25 +100,11 @@ public void playTick(Player player, int tick) {
99100
player.playNote(loc, InstrumentUtils.getBukkitInstrument(note.getInstrument()),
100101
new org.bukkit.Note(note.getKey() - 33));
101102

102-
float volume = ((layer.getVolume() * (int) this.volume * (int) playerVolume) / 1000000F)
103+
float volume = ((layer.getVolume() * (int) this.volume * (int) playerVolume * note.getVelocity()) / 100_00_00_00F)
103104
* ((1F / 16F) * getDistance());
104-
float pitch = NotePitch.getPitch(note.getKey() - 33);
105+
float pitch = NoteUtils.getPitch(note);
105106

106-
if (InstrumentUtils.isCustomInstrument(note.getInstrument())) {
107-
CustomInstrument instrument = song.getCustomInstruments()
108-
[note.getInstrument() - InstrumentUtils.getCustomInstrumentFirstIndex()];
109-
110-
if (instrument.getSound() != null) {
111-
CompatibilityUtils.playSound(player, loc,
112-
instrument.getSound(), this.soundCategory, volume, pitch, false);
113-
} else {
114-
CompatibilityUtils.playSound(player, loc,
115-
instrument.getSoundFileName(), this.soundCategory, volume, pitch, false);
116-
}
117-
} else {
118-
CompatibilityUtils.playSound(player, loc,
119-
InstrumentUtils.getInstrument(note.getInstrument()), this.soundCategory, volume, pitch, false);
120-
}
107+
channelMode.play(player, loc, song, layer, note, soundCategory, volume, pitch);
121108

122109
if (isInRange(player)) {
123110
if (!this.playerList.get(player.getUniqueId())) {

0 commit comments

Comments
 (0)