From 205fd3a77b5061cf4724efb971c71363246c6391 Mon Sep 17 00:00:00 2001 From: Pierre Maurice Schwang Date: Mon, 30 Sep 2024 22:47:21 +0200 Subject: [PATCH] fix: don't require WEOrigin / WEOffset in MCEdit schematics --- .../clipboard/io/MCEditSchematicReader.java | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/MCEditSchematicReader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/MCEditSchematicReader.java index 945cd6981..8e54249cd 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/MCEditSchematicReader.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/MCEditSchematicReader.java @@ -57,6 +57,7 @@ import java.io.UncheckedIOException; import java.util.HashSet; import java.util.List; import java.util.Locale; +import java.util.NoSuchElementException; import java.util.Set; /** @@ -126,18 +127,25 @@ public class MCEditSchematicReader extends NBTSchematicReader { short height = schematicTag.getTag("Height", LinTagType.shortTag()).valueAsShort(); short length = schematicTag.getTag("Length", LinTagType.shortTag()).valueAsShort(); - int originX = schematicTag.getTag("WEOriginX", LinTagType.intTag()).valueAsInt(); - int originY = schematicTag.getTag("WEOriginY", LinTagType.intTag()).valueAsInt(); - int originZ = schematicTag.getTag("WEOriginZ", LinTagType.intTag()).valueAsInt(); - BlockVector3 min = BlockVector3.at(originX, originY, originZ); + try { + int originX = schematicTag.getTag("WEOriginX", LinTagType.intTag()).valueAsInt(); + int originY = schematicTag.getTag("WEOriginY", LinTagType.intTag()).valueAsInt(); + int originZ = schematicTag.getTag("WEOriginZ", LinTagType.intTag()).valueAsInt(); + BlockVector3 min = BlockVector3.at(originX, originY, originZ); + + int offsetX = schematicTag.getTag("WEOffsetX", LinTagType.intTag()).valueAsInt(); + int offsetY = schematicTag.getTag("WEOffsetY", LinTagType.intTag()).valueAsInt(); + int offsetZ = schematicTag.getTag("WEOffsetZ", LinTagType.intTag()).valueAsInt(); + BlockVector3 offset = BlockVector3.at(offsetX, offsetY, offsetZ); + + origin = min.subtract(offset); + region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector3.ONE)); + } catch (NoSuchElementException e) { + origin = BlockVector3.ZERO; + region = new CuboidRegion(origin, origin.add(width, height, length).subtract(BlockVector3.ONE)); + } - int offsetX = schematicTag.getTag("WEOffsetX", LinTagType.intTag()).valueAsInt(); - int offsetY = schematicTag.getTag("WEOffsetY", LinTagType.intTag()).valueAsInt(); - int offsetZ = schematicTag.getTag("WEOffsetZ", LinTagType.intTag()).valueAsInt(); - BlockVector3 offset = BlockVector3.at(offsetX, offsetY, offsetZ); - origin = min.subtract(offset); - region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector3.ONE)); // ==================================================================== // Blocks