Skip to content
This repository was archived by the owner on May 27, 2023. It is now read-only.

Commit 56b15fb

Browse files
TechnerderLooFifteen
authored andcommitted
MCEdit schematic support
1 parent 049bcb7 commit 56b15fb

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/main/java/net/crystalgames/scaffolding/schematic/impl/MCEditSchematic.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,36 @@ public class MCEditSchematic implements Schematic {
2828

2929
private boolean read = false;
3030

31+
private int offsetX;
32+
private int offsetY;
33+
private int offsetZ;
34+
3135
@Override
3236
public void read(NBTCompound nbtTag) throws NBTException {
3337
if (!nbtTag.containsKey("Blocks")) throw new NBTException("Invalid Schematic: No Blocks");
3438

3539
readSizes(nbtTag);
3640
readBlocksData(nbtTag);
41+
readOffsets(nbtTag);
3742
readBlocks();
3843

3944
read = true;
4045
}
4146

47+
private void readOffsets(@NotNull NBTCompound nbtTag) throws NBTException {
48+
Integer weOffsetX = nbtTag.getInt("WEOffsetX");
49+
if (weOffsetX == null) throw new NBTException("Invalid Schematic: No WEOffsetX");
50+
this.offsetX = weOffsetX;
51+
52+
Integer weOffsetY = nbtTag.getInt("WEOffsetY");
53+
if (weOffsetY == null) throw new NBTException("Invalid Schematic: No WEOffsetY");
54+
this.offsetY = weOffsetY;
55+
56+
Integer weOffsetZ = nbtTag.getInt("WEOffsetZ");
57+
if (weOffsetZ == null) throw new NBTException("Invalid Schematic: No WEOffsetZ");
58+
this.offsetZ = weOffsetZ;
59+
}
60+
4261
private void readSizes(@NotNull NBTCompound nbtTag) throws NBTException {
4362
Short width = nbtTag.getShort("Width");
4463
if (width == null) throw new NBTException("Invalid Schematic: No Width");
@@ -86,7 +105,7 @@ public void readBlocks() {
86105
for (int z = 0; z < length; ++z) {
87106
int index = y * width * length + z * width + x;
88107
short stateId = this.blocks[index];
89-
regionBlocks.add(new Region.Block(new Pos(x, y, z), stateId));
108+
regionBlocks.add(new Region.Block(new Pos(x+offsetX, y+offsetY, z+offsetZ), stateId));
90109
}
91110
}
92111
}
@@ -114,7 +133,7 @@ public CompletableFuture<Region> build(Instance instance, Pos position) {
114133
}
115134
}
116135

117-
blockBatch.apply(instance, () -> future.complete(new Region(instance, position, position.add(width, height, length))));
136+
blockBatch.apply(instance, () -> future.complete(new Region(instance, position, position)));
118137
});
119138
return future;
120139
}

src/main/java/net/crystalgames/scaffolding/schematic/impl/SpongeSchematic.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ public class SpongeSchematic implements Schematic {
3333

3434
private boolean read = false;
3535

36-
private int offsetX, offsetY, offsetZ;
36+
private int offsetX;
37+
private int offsetY;
38+
private int offsetZ;
3739

3840
@Override
3941
public void read(NBTCompound nbtTag) throws NBTException {
@@ -130,7 +132,6 @@ private void readBlocks() throws NBTException {
130132
String block = paletteKeys.get(value);
131133
short stateId = getStateId(block);
132134

133-
// Is adding the height to y needed?
134135
this.regionBlocks.add(new Region.Block(new Pos(x + offsetX, y + offsetY, z + offsetZ), stateId));
135136

136137
index++;

0 commit comments

Comments
 (0)