Skip to content

Commit 6230f35

Browse files
committed
Added compatibility for 1.12 instruments on 1.8 - 1.11 servers via resource pack.
Fixed issue #4
1 parent 6107b09 commit 6230f35

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

Instruments-1-12.zip

36.7 KB
Binary file not shown.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.xxmicloxx</groupId>
88
<artifactId>NoteBlockAPI</artifactId>
9-
<version>1.1.9</version>
9+
<version>1.2.0</version>
1010

1111
<properties>
1212
<maven.compiler.source>1.8</maven.compiler.source>

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.lang.reflect.InvocationTargetException;
44
import java.lang.reflect.Method;
5+
import java.util.ArrayList;
56

67
import org.bukkit.Bukkit;
78
import org.bukkit.Location;
@@ -111,4 +112,14 @@ public static void playSound(Player p, Location location, Sound sound, SoundCate
111112
e.printStackTrace();
112113
}
113114
}
115+
116+
public static ArrayList<CustomInstrument> get1_12Instruments(){
117+
ArrayList<CustomInstrument> instruments = new ArrayList<>();
118+
instruments.add(new CustomInstrument((byte) 0, "Guitar", "guitar.ogg", (byte) 0, (byte) 0));
119+
instruments.add(new CustomInstrument((byte) 0, "Flute", "flute.ogg", (byte) 0, (byte) 0));
120+
instruments.add(new CustomInstrument((byte) 0, "Bell", "bell.ogg", (byte) 0, (byte) 0));
121+
instruments.add(new CustomInstrument((byte) 0, "Chime", "icechime.ogg", (byte) 0, (byte) 0));
122+
instruments.add(new CustomInstrument((byte) 0, "Xylophone", "xylobone.ogg", (byte) 0, (byte) 0));
123+
return instruments;
124+
}
114125
}

src/main/java/com/xxmicloxx/NoteBlockAPI/NBSDecoder.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import java.io.FileNotFoundException;
88
import java.io.IOException;
99
import java.io.InputStream;
10+
import java.util.ArrayList;
11+
import java.util.Arrays;
1012
import java.util.HashMap;
1113

1214
import org.bukkit.Bukkit;
@@ -29,6 +31,7 @@ public static Song parse(InputStream inputStream) {
2931

3032
private static Song parse(InputStream inputStream, File decodeFile) {
3133
HashMap<Integer, Layer> layerHashMap = new HashMap<Integer, Layer>();
34+
byte biggestInstrumentIndex = -1;
3235
try {
3336
DataInputStream dis = new DataInputStream(inputStream);
3437
short length = readShort(dis);
@@ -64,7 +67,11 @@ private static Song parse(InputStream inputStream, File decodeFile) {
6467
}
6568
layer += jumpLayers;
6669
//System.out.println("Layer: " + layer);
67-
setNote(layer, tick, dis.readByte() /* instrument */, dis.readByte() /* note */, layerHashMap);
70+
byte instrument = dis.readByte();
71+
if (instrument > biggestInstrumentIndex){
72+
biggestInstrumentIndex = instrument;
73+
}
74+
setNote(layer, tick, instrument /* instrument */, dis.readByte() /* note */, layerHashMap);
6875
}
6976
}
7077
for (int i = 0; i < songHeight; i++) {
@@ -84,6 +91,13 @@ private static Song parse(InputStream inputStream, File decodeFile) {
8491
for (int i = 0; i < custom; i++) {
8592
customInstruments[i] = new CustomInstrument((byte)i, readString(dis), readString(dis), dis.readByte(), dis.readByte());
8693
}
94+
95+
if (Instrument.isCustomInstrument((byte) (biggestInstrumentIndex - custom))){
96+
ArrayList<CustomInstrument> ci = CompatibilityUtils.get1_12Instruments();
97+
ci.addAll(Arrays.asList(customInstruments));
98+
customInstruments = ci.toArray(customInstruments);
99+
}
100+
87101
return new Song(speed, layerHashMap, songHeight, length, title, author, description, decodeFile, customInstruments);
88102
} catch (FileNotFoundException e) {
89103
e.printStackTrace();

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: NoteBlockAPI
22

33
main: com.xxmicloxx.NoteBlockAPI.NoteBlockPlayerMain
4-
version: 1.1.9
4+
version: 1.2.0
55

66
description: a developer interface to play nbs-files ingame
77
authors: [xxmicloxx, michidk, koca2000, Luck]

0 commit comments

Comments
 (0)