Only use WorldEdit relative offset for v2 sponge schematics

This commit is contained in:
Astrash committed 2023-02-28 13:05:36 +11:00
1 parent 8deae0480c
commit 73e0899e7c
1 file changed
+15 -7
@@ -72,14 +72,16 @@ public class SpongeSchematicAddon implements AddonInitializer {
public SpongeStructure convert(InputStream in, String id) { public SpongeStructure convert(InputStream in, String id) {
try { try {
CompoundTag baseTag = (CompoundTag) new NBTDeserializer(false).fromStream(detectDecompression(in)).getTag(); CompoundTag baseTag = (CompoundTag) new NBTDeserializer(false).fromStream(detectDecompression(in)).getTag();
int ver = baseTag.getInt("Version");
int wid = baseTag.getShort("Width"); int wid = baseTag.getShort("Width");
int len = baseTag.getShort("Length"); int len = baseTag.getShort("Length");
int hei = baseTag.getShort("Height"); int hei = baseTag.getShort("Height");
CompoundTag metadata = baseTag.getCompoundTag("Metadata"); CompoundTag metadata = baseTag.getCompoundTag("Metadata");
Vector3Int offset; Vector3Int offset = switch(ver) {
// Use WorldEdit relative offset if it exists in schematic metadata case 2 -> {
// Use WorldEdit defined legacy relative offset if it exists in schematic metadata
IntTag worldEditOffsetX = metadata.getIntTag("WEOffsetX"); IntTag worldEditOffsetX = metadata.getIntTag("WEOffsetX");
IntTag worldEditOffsetY = metadata.getIntTag("WEOffsetY"); IntTag worldEditOffsetY = metadata.getIntTag("WEOffsetY");
IntTag worldEditOffsetZ = metadata.getIntTag("WEOffsetZ"); IntTag worldEditOffsetZ = metadata.getIntTag("WEOffsetZ");
@@ -87,13 +89,19 @@ public class SpongeSchematicAddon implements AddonInitializer {
if(worldEditOffsetX == null || worldEditOffsetY == null || worldEditOffsetZ == null) { if(worldEditOffsetX == null || worldEditOffsetY == null || worldEditOffsetZ == null) {
throw new IllegalArgumentException("Failed to parse Sponge schematic: Malformed WorldEdit offset"); throw new IllegalArgumentException("Failed to parse Sponge schematic: Malformed WorldEdit offset");
} }
offset = Vector3Int.of(worldEditOffsetX.asInt(), worldEditOffsetY.asInt(), worldEditOffsetZ.asInt()); yield Vector3Int.of(worldEditOffsetX.asInt(), worldEditOffsetY.asInt(), worldEditOffsetZ.asInt());
} else { } else {
// Set offset based on the 'Offset' field, not clear on if this is correct behaviour according to spec so left commented for now // Relative offset handling via 'Offset' field is ambiguous in spec 2 so just apply no offset
//int[] offsetArray = baseTag.getIntArray("Offset"); yield Vector3Int.zero();
//offset = Vector3Int.of(offsetArray[0], offsetArray[1], offsetArray[2]);
offset = Vector3Int.zero();
} }
}
case 3 -> {
// Relative offset is more concretely defined in spec 3 to use 'Offset' field
int[] offsetArray = baseTag.getIntArray("Offset");
yield Vector3Int.of(offsetArray[0], offsetArray[1], offsetArray[2]);
}
default -> throw new IllegalArgumentException("Failed to parse Sponge schematic: Unsupported format version: " + ver);
};
ByteArrayTag blocks = baseTag.getByteArrayTag("BlockData"); ByteArrayTag blocks = baseTag.getByteArrayTag("BlockData");