Skip to content

Commit 75b19d0

Browse files
committed
Add support for Trumpet
1 parent 5319a09 commit 75b19d0

File tree

5 files changed

+112
-56
lines changed

5 files changed

+112
-56
lines changed

Instruments.zip

191 KB
Binary file not shown.

InstrumentsBE.mcpack

190 KB
Binary file not shown.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ public enum Sound {
2929
NOTE_COW_BELL("BLOCK_NOTE_BLOCK_COW_BELL"),
3030
NOTE_DIDGERIDOO("BLOCK_NOTE_BLOCK_DIDGERIDOO"),
3131
NOTE_BIT("BLOCK_NOTE_BLOCK_BIT"),
32-
NOTE_BANJO("BLOCK_NOTE_BLOCK_BANJO");
32+
NOTE_BANJO("BLOCK_NOTE_BLOCK_BANJO"),
33+
NOTE_TRUMPET("BLOCK_NOTE_BLOCK_TRUMPET"),
34+
NOTE_TRUMPET_EXPOSED("BLOCK_NOTE_BLOCK_TRUMPET_EXPOSED"),
35+
NOTE_TRUMPET_WEATHERED("BLOCK_NOTE_BLOCK_TRUMPET_WEATHERED"),
36+
NOTE_TRUMPET_OXIDIZED("BLOCK_NOTE_BLOCK_TRUMPET_OXIDIZED");
3337

3438
private String[] versionDependentNames;
3539
private org.bukkit.Sound cached = null;

src/main/java/com/xxmicloxx/NoteBlockAPI/utils/CompatibilityUtils.java

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.lang.reflect.Method;
55
import java.util.ArrayList;
66
import java.util.HashMap;
7+
import java.util.List;
78

89
import org.bukkit.Bukkit;
910
import org.bukkit.Location;
@@ -26,6 +27,7 @@ public class CompatibilityUtils {
2627
private static HashMap<String, Method> playSoundMethod = new HashMap<>();
2728

2829
private static float serverVersion = -1;
30+
private static List<CustomInstrument> customInstrumentsForDefaultInstruments = null;
2931

3032
/**
3133
* Gets NMS class from given name
@@ -225,13 +227,14 @@ public static ArrayList<CustomInstrument> get1_12Instruments(){
225227
}
226228

227229
/**
228-
* Return list of instuments which were added in specified version
230+
* Return list of instruments which were added in specified version
229231
* @param serverVersion 1.12 = 0.0112f, 1.14 = 0.0114f,...
230-
* @return list of custom instruments, if no instuments were added in specified version returns empty list
232+
* @return list of custom instruments, if no instruments were added in specified version returns empty list
231233
*/
232234
public static ArrayList<CustomInstrument> getVersionCustomInstruments(float serverVersion){
233235
ArrayList<CustomInstrument> instruments = new ArrayList<>();
234-
if (serverVersion == 0.0112f){
236+
float epsilon = 0.0001F;
237+
if (Math.abs(serverVersion - 0.0112f) < epsilon){
235238
instruments.add(new CustomInstrument((byte) 0, "Guitar", "block.note_block.guitar.ogg"));
236239
instruments.add(new CustomInstrument((byte) 0, "Flute", "block.note_block.flute.ogg"));
237240
instruments.add(new CustomInstrument((byte) 0, "Bell", "block.note_block.bell.ogg"));
@@ -240,7 +243,7 @@ public static ArrayList<CustomInstrument> getVersionCustomInstruments(float serv
240243
return instruments;
241244
}
242245

243-
if (serverVersion == 0.0114f){
246+
if (Math.abs(serverVersion - 0.0114f) < epsilon){
244247
instruments.add(new CustomInstrument((byte) 0, "Iron Xylophone", "block.note_block.iron_xylophone.ogg"));
245248
instruments.add(new CustomInstrument((byte) 0, "Cow Bell", "block.note_block.cow_bell.ogg"));
246249
instruments.add(new CustomInstrument((byte) 0, "Didgeridoo", "block.note_block.didgeridoo.ogg"));
@@ -249,6 +252,14 @@ public static ArrayList<CustomInstrument> getVersionCustomInstruments(float serv
249252
instruments.add(new CustomInstrument((byte) 0, "Pling", "block.note_block.pling.ogg"));
250253
return instruments;
251254
}
255+
256+
if (Math.abs(serverVersion - 0.2601f) < epsilon){
257+
instruments.add(new CustomInstrument((byte) 0, "Trumpet", "block.note_block.trumpet.ogg"));
258+
instruments.add(new CustomInstrument((byte) 0, "Exposed Trumpet", "block.note_block.trumpet_exposed.ogg"));
259+
instruments.add(new CustomInstrument((byte) 0, "Weathered Trumpet", "block.note_block.trumpet_weathered.ogg"));
260+
instruments.add(new CustomInstrument((byte) 0, "Oxidized Trumpet", "block.note_block.trumpet_oxidized.ogg"));
261+
return instruments;
262+
}
252263
return instruments;
253264
}
254265

@@ -260,18 +271,20 @@ public static ArrayList<CustomInstrument> getVersionCustomInstruments(float serv
260271
public static ArrayList<CustomInstrument> getVersionCustomInstrumentsForSong(int firstCustomInstrumentIndex){
261272
ArrayList<CustomInstrument> instruments = new ArrayList<>();
262273

263-
if (getServerVersion() < 0.0112f){
264-
if (firstCustomInstrumentIndex == 10) {
265-
instruments.addAll(getVersionCustomInstruments(0.0112f));
266-
} else if (firstCustomInstrumentIndex == 16){
267-
instruments.addAll(getVersionCustomInstruments(0.0112f));
268-
instruments.addAll(getVersionCustomInstruments(0.0114f));
269-
}
270-
} else if (getServerVersion() < 0.0114f){
271-
if (firstCustomInstrumentIndex == 16){
272-
instruments.addAll(getVersionCustomInstruments(0.0114f));
273-
}
274-
}
274+
if (customInstrumentsForDefaultInstruments == null) {
275+
customInstrumentsForDefaultInstruments = new ArrayList<>();
276+
customInstrumentsForDefaultInstruments.addAll(getVersionCustomInstruments(0.0112f));
277+
customInstrumentsForDefaultInstruments.addAll(getVersionCustomInstruments(0.0114f));
278+
customInstrumentsForDefaultInstruments.addAll(getVersionCustomInstruments(0.2601f));
279+
}
280+
281+
byte serverFirstCustomInstrumentIndex = InstrumentUtils.getCustomInstrumentFirstIndex();
282+
for (int i = serverFirstCustomInstrumentIndex; i < firstCustomInstrumentIndex; i++) {
283+
int customInstrumentIndex = i - 5;
284+
if (customInstrumentIndex < customInstrumentsForDefaultInstruments.size()) {
285+
instruments.add(customInstrumentsForDefaultInstruments.get(customInstrumentIndex));
286+
}
287+
}
275288

276289
return instruments;
277290
}

src/main/java/com/xxmicloxx/NoteBlockAPI/utils/InstrumentUtils.java

Lines changed: 78 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ public static String getSoundNameByInstrument(byte instrument) {
9999
case 15:
100100
//noinspection SpellCheckingInspection
101101
return "minecraft:block.note_block.pling";
102+
case 16:
103+
return "minecraft:block.note_block.trumpet";
104+
case 17:
105+
return "minecraft:block.note_block.trumpet_exposed";
106+
case 18:
107+
return "minecraft:block.note_block.trumpet_weathered";
108+
case 19:
109+
return "minecraft:block.note_block.trumpet_oxidized";
102110
default:
103111
return "minecraft:block.note_block.harp";
104112
}
@@ -145,10 +153,18 @@ public static String getInstrumentName(byte instrument) {
145153
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_BANJO").name();
146154
case 15:
147155
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_PLING").name();
156+
case 16:
157+
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_TRUMPET").name();
158+
case 17:
159+
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_TRUMPET_EXPOSED").name();
160+
case 18:
161+
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_TRUMPET_WEATHERED").name();
162+
case 19:
163+
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_TRUMPET_OXIDIZED").name();
148164
default:
149165
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_HARP").name();
150166
}
151-
}
167+
}
152168

153169
/**
154170
* Returns the name of the org.bukkit.Instrument enum for the current server version
@@ -167,43 +183,62 @@ public static Instrument getBukkitInstrument(byte instrument) {
167183
return Instrument.SNARE_DRUM;
168184
case 4:
169185
return Instrument.STICKS;
170-
default: {
171-
if (CompatibilityUtils.getServerVersion() >= 0.0112f) {
172-
switch (instrument) {
173-
case 5:
174-
return Instrument.valueOf("GUITAR");
175-
case 6:
176-
return Instrument.valueOf("FLUTE");
177-
case 7:
178-
return Instrument.valueOf("BELL");
179-
case 8:
180-
return Instrument.valueOf("CHIME");
181-
case 9:
182-
return Instrument.valueOf("XYLOPHONE");
183-
default: {
184-
if (CompatibilityUtils.getServerVersion() >= 0.0114f) {
185-
switch (instrument) {
186-
case 10:
187-
return Instrument.valueOf("IRON_XYLOPHONE");
188-
case 11:
189-
return Instrument.valueOf("COW_BELL");
190-
case 12:
191-
return Instrument.valueOf("DIDGERIDOO");
192-
case 13:
193-
return Instrument.valueOf("BIT");
194-
case 14:
195-
return Instrument.valueOf("BANJO");
196-
case 15:
197-
return Instrument.valueOf("PLING");
198-
}
199-
}
200-
return Instrument.PIANO;
201-
}
202-
}
203-
}
204-
return Instrument.PIANO;
205-
}
186+
default:
187+
// Not in this version
206188
}
189+
190+
if (CompatibilityUtils.getServerVersion() >= 0.0112F) {
191+
switch (instrument) {
192+
case 5:
193+
return Instrument.valueOf("GUITAR");
194+
case 6:
195+
return Instrument.valueOf("FLUTE");
196+
case 7:
197+
return Instrument.valueOf("BELL");
198+
case 8:
199+
return Instrument.valueOf("CHIME");
200+
case 9:
201+
return Instrument.valueOf("XYLOPHONE");
202+
default:
203+
// Not in this version
204+
}
205+
}
206+
207+
if (CompatibilityUtils.getServerVersion() >= 0.0114F) {
208+
switch (instrument) {
209+
case 10:
210+
return Instrument.valueOf("IRON_XYLOPHONE");
211+
case 11:
212+
return Instrument.valueOf("COW_BELL");
213+
case 12:
214+
return Instrument.valueOf("DIDGERIDOO");
215+
case 13:
216+
return Instrument.valueOf("BIT");
217+
case 14:
218+
return Instrument.valueOf("BANJO");
219+
case 15:
220+
return Instrument.valueOf("PLING");
221+
default:
222+
// Not in this version
223+
}
224+
}
225+
226+
if (CompatibilityUtils.getServerVersion() >= 0.2601F) {
227+
switch (instrument) {
228+
case 16:
229+
return Instrument.valueOf("TRUMPET");
230+
case 17:
231+
return Instrument.valueOf("TRUMPET_EXPOSED");
232+
case 18:
233+
return Instrument.valueOf("TRUMPET_WEATHERED");
234+
case 19:
235+
return Instrument.valueOf("TRUMPET_OXIDIZED");
236+
default:
237+
// Not in this version
238+
}
239+
}
240+
241+
return Instrument.PIANO;
207242
}
208243

209244
/**
@@ -221,10 +256,14 @@ public static boolean isCustomInstrument(byte instrument) {
221256
* @return index where an instrument can be added
222257
*/
223258
public static byte getCustomInstrumentFirstIndex() {
224-
if (CompatibilityUtils.getServerVersion() >= 0.0114f) {
259+
float serverVersion = CompatibilityUtils.getServerVersion();
260+
if (serverVersion >= 0.2601f) {
261+
return 20;
262+
}
263+
if (serverVersion >= 0.0114f) {
225264
return 16;
226265
}
227-
if (CompatibilityUtils.getServerVersion() >= 0.0112f) {
266+
if (serverVersion >= 0.0112f) {
228267
return 10;
229268
}
230269
return 5;

0 commit comments

Comments
 (0)