77import java .io .FileNotFoundException ;
88import java .io .IOException ;
99import java .io .InputStream ;
10+ import java .util .ArrayList ;
11+ import java .util .Arrays ;
1012import java .util .HashMap ;
1113
1214import 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 ();
0 commit comments