mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-26 14:00:14 +00:00
Only use WorldEdit relative offset for v2 sponge schematics
This commit is contained in:
1 parent
8deae0480c
commit
73e0899e7c
1 file changed
+23
-15
+23
-15
@@ -72,28 +72,36 @@ 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 -> {
|
||||||
IntTag worldEditOffsetX = metadata.getIntTag("WEOffsetX");
|
// Use WorldEdit defined legacy relative offset if it exists in schematic metadata
|
||||||
IntTag worldEditOffsetY = metadata.getIntTag("WEOffsetY");
|
IntTag worldEditOffsetX = metadata.getIntTag("WEOffsetX");
|
||||||
IntTag worldEditOffsetZ = metadata.getIntTag("WEOffsetZ");
|
IntTag worldEditOffsetY = metadata.getIntTag("WEOffsetY");
|
||||||
if (worldEditOffsetX != null || worldEditOffsetY != null || worldEditOffsetZ != null) {
|
IntTag worldEditOffsetZ = metadata.getIntTag("WEOffsetZ");
|
||||||
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");
|
if(worldEditOffsetX == null || worldEditOffsetY == null || worldEditOffsetZ == null) {
|
||||||
|
throw new IllegalArgumentException("Failed to parse Sponge schematic: Malformed WorldEdit offset");
|
||||||
|
}
|
||||||
|
yield Vector3Int.of(worldEditOffsetX.asInt(), worldEditOffsetY.asInt(), worldEditOffsetZ.asInt());
|
||||||
|
} else {
|
||||||
|
// Relative offset handling via 'Offset' field is ambiguous in spec 2 so just apply no offset
|
||||||
|
yield Vector3Int.zero();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
offset = Vector3Int.of(worldEditOffsetX.asInt(), worldEditOffsetY.asInt(), worldEditOffsetZ.asInt());
|
case 3 -> {
|
||||||
} else {
|
// Relative offset is more concretely defined in spec 3 to use 'Offset' field
|
||||||
// Set offset based on the 'Offset' field, not clear on if this is correct behaviour according to spec so left commented for now
|
int[] offsetArray = baseTag.getIntArray("Offset");
|
||||||
//int[] offsetArray = baseTag.getIntArray("Offset");
|
yield Vector3Int.of(offsetArray[0], offsetArray[1], offsetArray[2]);
|
||||||
//offset = Vector3Int.of(offsetArray[0], offsetArray[1], offsetArray[2]);
|
}
|
||||||
offset = Vector3Int.zero();
|
default -> throw new IllegalArgumentException("Failed to parse Sponge schematic: Unsupported format version: " + ver);
|
||||||
}
|
};
|
||||||
|
|
||||||
ByteArrayTag blocks = baseTag.getByteArrayTag("BlockData");
|
ByteArrayTag blocks = baseTag.getByteArrayTag("BlockData");
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user