From 38cff7c7b2c09b9c948e717ee70fbdd67b295784 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Sat, 4 Aug 2018 10:59:14 +1000 Subject: [PATCH] Fixed up tile entities in Sponge schematics. --- .../clipboard/io/BuiltInClipboardFormat.java | 2 +- .../clipboard/io/SpongeSchematicReader.java | 16 ++++++++-------- .../clipboard/io/SpongeSchematicWriter.java | 19 ++++++++++--------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/BuiltInClipboardFormat.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/BuiltInClipboardFormat.java index 5c8672f08..3f3063032 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/BuiltInClipboardFormat.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/BuiltInClipboardFormat.java @@ -73,7 +73,7 @@ public enum BuiltInClipboardFormat implements ClipboardFormat { // Check Map schematic = schematicTag.getValue(); - if (!schematic.containsKey("Blocks")) { + if (!schematic.containsKey("Materials")) { return false; } } catch (IOException e) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java index 92a468c3f..73f0cee8c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java @@ -110,18 +110,18 @@ public class SpongeSchematicReader extends NBTSchematicReader { throw new IOException("Invalid offset specified in schematic."); } - Vector offset = new Vector(offsetParts[0], offsetParts[1], offsetParts[2]); + Vector min = new Vector(offsetParts[0], offsetParts[1], offsetParts[2]); - if (metadata.containsKey("WEOriginX")) { + if (metadata.containsKey("WEOffsetX")) { // We appear to have WorldEdit Metadata - int originX = requireTag(metadata, "WEOriginX", IntTag.class).getValue(); - int originY = requireTag(metadata, "WEOriginY", IntTag.class).getValue(); - int originZ = requireTag(metadata, "WEOriginZ", IntTag.class).getValue(); - Vector min = new Vector(originX, originY, originZ); + int offsetX = requireTag(metadata, "WEOffsetX", IntTag.class).getValue(); + int offsetY = requireTag(metadata, "WEOffsetY", IntTag.class).getValue(); + int offsetZ = requireTag(metadata, "WEOffsetZ", IntTag.class).getValue(); + Vector offset = new Vector(offsetX, offsetY, offsetZ); origin = min.subtract(offset); region = new CuboidRegion(origin, origin.add(width, height, length).subtract(Vector.ONE)); } else { - origin = Vector.ZERO.subtract(offset); + origin = min; region = new CuboidRegion(origin, origin.add(width, height, length).subtract(Vector.ONE)); } @@ -160,7 +160,7 @@ public class SpongeSchematicReader extends NBTSchematicReader { for (Map tileEntity : tileEntityTags) { int[] pos = requireTag(tileEntity, "Pos", IntArrayTag.class).getValue(); - tileEntitiesMap.put(new BlockVector(pos[0], pos[1], pos[2]), tileEntity); + tileEntitiesMap.put(origin.add(new BlockVector(pos[0], pos[1], pos[2])).toBlockVector(), tileEntity); } } catch (Exception e) { throw new IOException("Failed to load Tile Entities: " + e.getMessage()); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java index a737ff266..e93b498e3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java @@ -97,9 +97,9 @@ public class SpongeSchematicWriter implements ClipboardWriter { schematic.put("Version", new IntTag(1)); Map metadata = new HashMap<>(); - metadata.put("WEOriginX", new IntTag(min.getBlockX())); - metadata.put("WEOriginY", new IntTag(min.getBlockY())); - metadata.put("WEOriginZ", new IntTag(min.getBlockZ())); + metadata.put("WEOffsetX", new IntTag(offset.getBlockX())); + metadata.put("WEOffsetY", new IntTag(offset.getBlockY())); + metadata.put("WEOffsetZ", new IntTag(offset.getBlockZ())); schematic.put("Metadata", new CompoundTag(metadata)); @@ -107,10 +107,11 @@ public class SpongeSchematicWriter implements ClipboardWriter { schematic.put("Height", new ShortTag((short) height)); schematic.put("Length", new ShortTag((short) length)); + // The Sponge format Offset refers to the 'min' points location in the world. That's our 'Origin' schematic.put("Offset", new IntArrayTag(new int[]{ - offset.getBlockX(), - offset.getBlockY(), - offset.getBlockZ(), + min.getBlockX(), + min.getBlockY(), + min.getBlockZ(), })); int paletteMax = 0; @@ -136,9 +137,9 @@ public class SpongeSchematicWriter implements ClipboardWriter { values.put("Id", new StringTag(block.getNbtId())); values.put("Pos", new IntArrayTag(new int[]{ - point.getBlockX(), - point.getBlockY(), - point.getBlockZ() + x, + y, + z })); CompoundTag tileEntityTag = new CompoundTag(values);