1
1
package net .crystalgames .scaffolding .schematic .impl ;
2
2
3
- import java .io .OutputStream ;
4
- import java .util .ArrayList ;
5
- import java .util .HashMap ;
6
- import java .util .LinkedHashMap ;
7
- import java .util .List ;
8
- import java .util .Map ;
9
- import java .util .Set ;
10
- import java .util .concurrent .CompletableFuture ;
11
3
import net .crystalgames .scaffolding .region .Region ;
12
4
import net .crystalgames .scaffolding .schematic .Schematic ;
13
5
import net .minestom .server .coordinate .Pos ;
19
11
import org .jglrxavpok .hephaistos .nbt .NBTCompound ;
20
12
import org .jglrxavpok .hephaistos .nbt .NBTException ;
21
13
14
+ import java .io .OutputStream ;
15
+ import java .util .ArrayList ;
16
+ import java .util .HashMap ;
17
+ import java .util .LinkedHashMap ;
18
+ import java .util .List ;
19
+ import java .util .Map ;
20
+ import java .util .Set ;
21
+ import java .util .concurrent .CompletableFuture ;
22
+
22
23
// https://github.com/EngineHub/WorldEdit/blob/303f5a76b2df70d63480f2126c9ef4b228eb3c59/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java#L261-L297
23
24
public class SpongeSchematic implements Schematic {
24
25
@@ -32,15 +33,34 @@ public class SpongeSchematic implements Schematic {
32
33
33
34
private boolean read = false ;
34
35
36
+ private int offsetX , offsetY , offsetZ ;
37
+
35
38
@ Override
36
39
public void read (NBTCompound nbtTag ) throws NBTException {
37
40
readSizes (nbtTag );
38
41
readBlockPalette (nbtTag );
42
+ readOffsets (nbtTag );
39
43
readBlocks ();
40
-
41
44
read = true ;
42
45
}
43
46
47
+ private void readOffsets (@ NotNull NBTCompound nbtTag ) throws NBTException {
48
+ NBTCompound metaData = nbtTag .getCompound ("Metadata" );
49
+ if (metaData == null ) throw new NBTException ("Invalid Schematic: No Metadata" );
50
+
51
+ Integer weOffsetX = metaData .getInt ("WEOffsetX" );
52
+ if (weOffsetX == null ) throw new NBTException ("Invalid Schematic: No WEOffsetX In Metadata" );
53
+ this .offsetX = weOffsetX ;
54
+
55
+ Integer weOffsetY = metaData .getInt ("WEOffsetY" );
56
+ if (weOffsetY == null ) throw new NBTException ("Invalid Schematic: No WEOffsetY In Metadata" );
57
+ this .offsetY = weOffsetY ;
58
+
59
+ Integer weOffsetZ = metaData .getInt ("WEOffsetZ" );
60
+ if (weOffsetZ == null ) throw new NBTException ("Invalid Schematic: No WEOffsetZ In Metadata" );
61
+ this .offsetZ = weOffsetZ ;
62
+ }
63
+
44
64
private void readSizes (@ NotNull NBTCompound nbtTag ) throws NBTException {
45
65
Short width = nbtTag .getShort ("Width" );
46
66
if (width == null ) throw new NBTException ("Invalid Schematic: No Width" );
@@ -63,9 +83,10 @@ private void readBlockPalette(@NotNull NBTCompound nbtTag) throws NBTException {
63
83
if (nbtPalette == null ) throw new NBTException ("Invalid Schematic: No Palette" );
64
84
65
85
Set <String > keys = nbtPalette .getKeys ();
66
- if (keys .size () != maxPalette ) throw new NBTException ("Invalid Schematic: PaletteMax does not match Palette size" );
86
+ if (keys .size () != maxPalette )
87
+ throw new NBTException ("Invalid Schematic: PaletteMax does not match Palette size" );
67
88
68
- for (String key : keys ) {
89
+ for (String key : keys ) {
69
90
Integer value = nbtPalette .getInt (key );
70
91
if (value == null ) throw new NBTException ("Invalid Schematic: Palette contains invalid value" );
71
92
@@ -74,7 +95,7 @@ private void readBlockPalette(@NotNull NBTCompound nbtTag) throws NBTException {
74
95
75
96
palette = palette .entrySet ().stream ()
76
97
.sorted (Map .Entry .comparingByValue ())
77
- .collect (LinkedHashMap ::new ,(map , entry ) -> map .put (entry .getKey (), entry .getValue ()), LinkedHashMap ::putAll );
98
+ .collect (LinkedHashMap ::new , (map , entry ) -> map .put (entry .getKey (), entry .getValue ()), LinkedHashMap ::putAll );
78
99
79
100
ImmutableByteArray blocksData = nbtTag .getByteArray ("BlockData" );
80
101
if (blocksData == null || blocksData .getSize () == 0 ) throw new NBTException ("Invalid Schematic: No BlockData" );
@@ -110,7 +131,7 @@ private void readBlocks() throws NBTException {
110
131
short stateId = getStateId (block );
111
132
112
133
// Is adding the height to y needed?
113
- this .regionBlocks .add (new Region .Block (new Pos (x , y + height , z ), stateId ));
134
+ this .regionBlocks .add (new Region .Block (new Pos (x + offsetX , y + offsetY , z + offsetZ ), stateId ));
114
135
115
136
index ++;
116
137
}
@@ -137,8 +158,7 @@ public CompletableFuture<Region> build(Instance instance, Pos position) {
137
158
blockBatch .setBlock (blockPosition .add (position ), block );
138
159
}
139
160
}
140
-
141
- blockBatch .apply (instance , () -> future .complete (new Region (instance , position , position .add (width , height , length ))));
161
+ blockBatch .apply (instance , () -> future .complete (new Region (instance , position , position )));
142
162
});
143
163
return future ;
144
164
}
0 commit comments