Fixed a few issues with Sponge schematic handling.

This commit is contained in:
Matthew Miller 2018-08-03 19:49:36 +10:00
parent 2c1b234e38
commit 7773ef6f9a
3 changed files with 59 additions and 51 deletions

View File

@ -159,7 +159,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
.collect(Collectors.toList()); .collect(Collectors.toList());
for (Map<String, Tag> tileEntity : tileEntityTags) { for (Map<String, Tag> 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); tileEntitiesMap.put(new BlockVector(pos[0], pos[1], pos[2]), tileEntity);
} }
} catch (Exception e) { } catch (Exception e) {

View File

@ -30,6 +30,7 @@ import com.sk89q.jnbt.NBTOutputStream;
import com.sk89q.jnbt.ShortTag; import com.sk89q.jnbt.ShortTag;
import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag; import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
@ -119,7 +120,13 @@ public class SpongeSchematicWriter implements ClipboardWriter {
ByteArrayOutputStream buffer = new ByteArrayOutputStream(width * height * length); ByteArrayOutputStream buffer = new ByteArrayOutputStream(width * height * length);
for (Vector point : region) { 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); BaseBlock block = clipboard.getFullBlock(point);
if (block.getNbtData() != null) { if (block.getNbtData() != null) {
Map<String, Tag> values = new HashMap<>(); Map<String, Tag> values = new HashMap<>();
@ -145,7 +152,7 @@ public class SpongeSchematicWriter implements ClipboardWriter {
} else { } else {
blockId = paletteMax; blockId = paletteMax;
palette.put(blockKey, blockId); palette.put(blockKey, blockId);
paletteMax ++; paletteMax++;
} }
while ((blockId & -128) != 0) { while ((blockId & -128) != 0) {
@ -154,6 +161,8 @@ public class SpongeSchematicWriter implements ClipboardWriter {
} }
buffer.write(blockId); buffer.write(blockId);
} }
}
}
schematic.put("PaletteMax", new IntTag(paletteMax)); schematic.put("PaletteMax", new IntTag(paletteMax));

View File

@ -40,14 +40,14 @@ public interface Region extends Iterable<BlockVector>, Cloneable {
* *
* @return min. point * @return min. point
*/ */
public Vector getMinimumPoint(); Vector getMinimumPoint();
/** /**
* Get the upper point of a region. * Get the upper point of a region.
* *
* @return max. point * @return max. point
*/ */
public Vector getMaximumPoint(); Vector getMaximumPoint();
/** /**
* Get the center point of a region. * Get the center point of a region.
@ -56,35 +56,35 @@ public interface Region extends Iterable<BlockVector>, Cloneable {
* *
* @return center point * @return center point
*/ */
public Vector getCenter(); Vector getCenter();
/** /**
* Get the number of blocks in the region. * Get the number of blocks in the region.
* *
* @return number of blocks * @return number of blocks
*/ */
public int getArea(); int getArea();
/** /**
* Get X-size. * Get X-size.
* *
* @return width * @return width
*/ */
public int getWidth(); int getWidth();
/** /**
* Get Y-size. * Get Y-size.
* *
* @return height * @return height
*/ */
public int getHeight(); int getHeight();
/** /**
* Get Z-size. * Get Z-size.
* *
* @return length * @return length
*/ */
public int getLength(); int getLength();
/** /**
* Expand the region. * Expand the region.
@ -92,7 +92,7 @@ public interface Region extends Iterable<BlockVector>, Cloneable {
* @param changes array/arguments with multiple related changes * @param changes array/arguments with multiple related changes
* @throws RegionOperationException * @throws RegionOperationException
*/ */
public void expand(Vector... changes) throws RegionOperationException; void expand(Vector... changes) throws RegionOperationException;
/** /**
* Contract the region. * Contract the region.
@ -100,7 +100,7 @@ public interface Region extends Iterable<BlockVector>, Cloneable {
* @param changes array/arguments with multiple related changes * @param changes array/arguments with multiple related changes
* @throws RegionOperationException * @throws RegionOperationException
*/ */
public void contract(Vector... changes) throws RegionOperationException; void contract(Vector... changes) throws RegionOperationException;
/** /**
* Shift the region. * Shift the region.
@ -108,7 +108,7 @@ public interface Region extends Iterable<BlockVector>, Cloneable {
* @param change the change * @param change the change
* @throws RegionOperationException * @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. * Returns true based on whether the region contains the point.
@ -116,43 +116,42 @@ public interface Region extends Iterable<BlockVector>, Cloneable {
* @param position the position * @param position the position
* @return true if contained * @return true if contained
*/ */
public boolean contains(Vector position); boolean contains(Vector position);
/** /**
* Get a list of chunks. * Get a list of chunks.
* *
* @return a list of chunk coordinates * @return a list of chunk coordinates
*/ */
public Set<Vector2D> getChunks(); Set<Vector2D> getChunks();
/** /**
* Return a list of 16*16*16 chunks in a region * Return a list of 16*16*16 chunks in a region
* *
* @return the chunk cubes this region overlaps with * @return the chunk cubes this region overlaps with
*/ */
public Set<Vector> getChunkCubes(); Set<Vector> getChunkCubes();
/** /**
* Sets the world that the selection is in. * Sets the world that the selection is in.
* *
* @return the world, or null * @return the world, or null
*/ */
@Nullable @Nullable World getWorld();
public World getWorld();
/** /**
* Sets the world that the selection is in. * Sets the world that the selection is in.
* *
* @param world the world, which may be null * @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. * Make a clone of the region.
* *
* @return a cloned version * @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. * 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<BlockVector>, Cloneable {
* @param maxPoints maximum number of points to generate. -1 for no limit. * @param maxPoints maximum number of points to generate. -1 for no limit.
* @return the points. * @return the points.
*/ */
public List<BlockVector2D> polygonize(int maxPoints); List<BlockVector2D> polygonize(int maxPoints);
} }