From 7773ef6f9a4e77590b51459625cfa3afb45ecb25 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Fri, 3 Aug 2018 19:49:36 +1000 Subject: [PATCH] Fixed a few issues with Sponge schematic handling. --- .../clipboard/io/SpongeSchematicReader.java | 2 +- .../clipboard/io/SpongeSchematicWriter.java | 73 +++++++++++-------- .../com/sk89q/worldedit/regions/Region.java | 35 +++++---- 3 files changed, 59 insertions(+), 51 deletions(-) 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 593cd4432..92a468c3f 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 @@ -159,7 +159,7 @@ public class SpongeSchematicReader extends NBTSchematicReader { .collect(Collectors.toList()); for (Map tileEntity : tileEntityTags) { - int[] pos = requireTag(schematic, "Pos", IntArrayTag.class).getValue(); + int[] pos = requireTag(tileEntity, "Pos", IntArrayTag.class).getValue(); tileEntitiesMap.put(new BlockVector(pos[0], pos[1], pos[2]), tileEntity); } } catch (Exception e) { 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 fc97a35f6..a737ff266 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 @@ -30,6 +30,7 @@ import com.sk89q.jnbt.NBTOutputStream; import com.sk89q.jnbt.ShortTag; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; +import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.extent.clipboard.Clipboard; @@ -119,40 +120,48 @@ public class SpongeSchematicWriter implements ClipboardWriter { ByteArrayOutputStream buffer = new ByteArrayOutputStream(width * height * length); - for (Vector point : region) { - BaseBlock block = clipboard.getFullBlock(point); - if (block.getNbtData() != null) { - Map values = new HashMap<>(); - for (Map.Entry entry : block.getNbtData().getValue().entrySet()) { - values.put(entry.getKey(), entry.getValue()); + for (int y = 0; y < height; y++) { + int y0 = min.getBlockY() + y; + for (int z = 0; z < length; z++) { + int z0 = min.getBlockZ() + z; + for (int x = 0; x < width; x++) { + int x0 = min.getBlockX() + x; + BlockVector point = new BlockVector(x0, y0, z0); + BaseBlock block = clipboard.getFullBlock(point); + if (block.getNbtData() != null) { + Map values = new HashMap<>(); + for (Map.Entry entry : block.getNbtData().getValue().entrySet()) { + values.put(entry.getKey(), entry.getValue()); + } + + values.put("Id", new StringTag(block.getNbtId())); + values.put("Pos", new IntArrayTag(new int[]{ + point.getBlockX(), + point.getBlockY(), + point.getBlockZ() + })); + + CompoundTag tileEntityTag = new CompoundTag(values); + tileEntities.add(tileEntityTag); + } + + String blockKey = block.toImmutableState().getAsString(); + int blockId; + if (palette.containsKey(blockKey)) { + blockId = palette.get(blockKey); + } else { + blockId = paletteMax; + palette.put(blockKey, blockId); + paletteMax++; + } + + while ((blockId & -128) != 0) { + buffer.write(blockId & 127 | 128); + blockId >>>= 7; + } + buffer.write(blockId); } - - values.put("Id", new StringTag(block.getNbtId())); - values.put("Pos", new IntArrayTag(new int[]{ - point.getBlockX(), - point.getBlockY(), - point.getBlockZ() - })); - - CompoundTag tileEntityTag = new CompoundTag(values); - tileEntities.add(tileEntityTag); } - - String blockKey = block.toImmutableState().getAsString(); - int blockId; - if (palette.containsKey(blockKey)) { - blockId = palette.get(blockKey); - } else { - blockId = paletteMax; - palette.put(blockKey, blockId); - paletteMax ++; - } - - while ((blockId & -128) != 0) { - buffer.write(blockId & 127 | 128); - blockId >>>= 7; - } - buffer.write(blockId); } schematic.put("PaletteMax", new IntTag(paletteMax)); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java index ae72793a2..77bfa8440 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java @@ -40,14 +40,14 @@ public interface Region extends Iterable, Cloneable { * * @return min. point */ - public Vector getMinimumPoint(); + Vector getMinimumPoint(); /** * Get the upper point of a region. * * @return max. point */ - public Vector getMaximumPoint(); + Vector getMaximumPoint(); /** * Get the center point of a region. @@ -56,35 +56,35 @@ public interface Region extends Iterable, Cloneable { * * @return center point */ - public Vector getCenter(); + Vector getCenter(); /** * Get the number of blocks in the region. * * @return number of blocks */ - public int getArea(); + int getArea(); /** * Get X-size. * * @return width */ - public int getWidth(); + int getWidth(); /** * Get Y-size. * * @return height */ - public int getHeight(); + int getHeight(); /** * Get Z-size. * * @return length */ - public int getLength(); + int getLength(); /** * Expand the region. @@ -92,7 +92,7 @@ public interface Region extends Iterable, Cloneable { * @param changes array/arguments with multiple related changes * @throws RegionOperationException */ - public void expand(Vector... changes) throws RegionOperationException; + void expand(Vector... changes) throws RegionOperationException; /** * Contract the region. @@ -100,7 +100,7 @@ public interface Region extends Iterable, Cloneable { * @param changes array/arguments with multiple related changes * @throws RegionOperationException */ - public void contract(Vector... changes) throws RegionOperationException; + void contract(Vector... changes) throws RegionOperationException; /** * Shift the region. @@ -108,7 +108,7 @@ public interface Region extends Iterable, Cloneable { * @param change the change * @throws RegionOperationException */ - public void shift(Vector change) throws RegionOperationException; + void shift(Vector change) throws RegionOperationException; /** * Returns true based on whether the region contains the point. @@ -116,43 +116,42 @@ public interface Region extends Iterable, Cloneable { * @param position the position * @return true if contained */ - public boolean contains(Vector position); + boolean contains(Vector position); /** * Get a list of chunks. * * @return a list of chunk coordinates */ - public Set getChunks(); + Set getChunks(); /** * Return a list of 16*16*16 chunks in a region * * @return the chunk cubes this region overlaps with */ - public Set getChunkCubes(); + Set getChunkCubes(); /** * Sets the world that the selection is in. * * @return the world, or null */ - @Nullable - public World getWorld(); + @Nullable World getWorld(); /** * Sets the world that the selection is in. * * @param world the world, which may be null */ - public void setWorld(@Nullable World world); + void setWorld(@Nullable World world); /** * Make a clone of the region. * * @return a cloned version */ - public Region clone(); + Region clone(); /** * Polygonizes a cross-section or a 2D projection of the region orthogonal to the Y axis. @@ -160,5 +159,5 @@ public interface Region extends Iterable, Cloneable { * @param maxPoints maximum number of points to generate. -1 for no limit. * @return the points. */ - public List polygonize(int maxPoints); + List polygonize(int maxPoints); }