@@ -26,11 +26,10 @@ public class MCEditSchematic extends AbstractSchematic {
26
26
private short width ;
27
27
private short height ;
28
28
private short length ;
29
-
30
- private String materials ;
31
- private byte [] addId ;
32
29
private short [] blocks ;
33
30
31
+ private boolean read = false ;
32
+
34
33
public MCEditSchematic (InputStream inputStream ) throws IOException , NBTException {
35
34
super (inputStream );
36
35
}
@@ -46,6 +45,8 @@ public void read() throws NBTException {
46
45
readSizes (nbtTag );
47
46
readBlocksData (nbtTag );
48
47
readBlocks ();
48
+
49
+ read = true ;
49
50
}
50
51
51
52
private void readSizes (@ NotNull NBTCompound nbtTag ) throws NBTException {
@@ -66,7 +67,6 @@ private void readSizes(@NotNull NBTCompound nbtTag) throws NBTException {
66
67
private void readBlocksData (@ NotNull NBTCompound nbtTag ) throws NBTException {
67
68
String materials = nbtTag .getString ("Materials" );
68
69
if (materials == null || !materials .equals ("Alpha" )) throw new NBTException ("Invalid Schematic: Invalid Materials" );
69
- this .materials = materials ;
70
70
71
71
ImmutableByteArray blockIdPre = nbtTag .getByteArray ("Blocks" );
72
72
if (blockIdPre == null ) throw new NBTException ("Invalid Schematic: No Blocks" );
@@ -76,15 +76,16 @@ private void readBlocksData(@NotNull NBTCompound nbtTag) throws NBTException {
76
76
if (blocksData == null ) throw new NBTException ("Invalid Schematic: No Block Data" );
77
77
blocksData .copyArray ();
78
78
79
+ byte [] addId ;
79
80
if (nbtTag .containsKey ("AddBlocks" )) addId = Objects .requireNonNull (nbtTag .getByteArray ("AddBlocks" )).copyArray ();
80
81
else addId = new byte [0 ];
81
82
82
83
blocks = new short [blockId .length ];
83
84
for (int index = 0 ; index < blockId .length ; index ++) {
84
- if ((index >> 1 ) >= this . addId .length ) this .blocks [index ] = (short ) (blockId [index ] & 0xFF );
85
+ if ((index >> 1 ) >= addId .length ) this .blocks [index ] = (short ) (blockId [index ] & 0xFF );
85
86
else {
86
- if ((index & 1 ) == 0 ) this .blocks [index ] = (short ) (((this . addId [index >> 1 ] & 0x0F ) << 8 ) + (blockId [index ] & 0xFF ));
87
- else this .blocks [index ] = (short ) (((this . addId [index >> 1 ] & 0xF0 ) << 4 ) + (blockId [index ] & 0xFF ));
87
+ if ((index & 1 ) == 0 ) this .blocks [index ] = (short ) (((addId [index >> 1 ] & 0x0F ) << 8 ) + (blockId [index ] & 0xFF ));
88
+ else this .blocks [index ] = (short ) (((addId [index >> 1 ] & 0xF0 ) << 4 ) + (blockId [index ] & 0xFF ));
88
89
}
89
90
}
90
91
}
@@ -108,6 +109,7 @@ public void write(Region region) {
108
109
109
110
@ Override
110
111
public CompletableFuture <Region > build (Instance instance , Pos position ) {
112
+ if (!read ) throw new IllegalStateException ("Schematic not read" );
111
113
CompletableFuture <Region > future = new CompletableFuture <>();
112
114
CompletableFuture .runAsync (() -> {
113
115
AbsoluteBlockBatch blockBatch = new AbsoluteBlockBatch ();
0 commit comments