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());
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);
}
} catch (Exception e) {

View File

@ -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,7 +120,13 @@ public class SpongeSchematicWriter implements ClipboardWriter {
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);
if (block.getNbtData() != null) {
Map<String, Tag> values = new HashMap<>();
@ -145,7 +152,7 @@ public class SpongeSchematicWriter implements ClipboardWriter {
} else {
blockId = paletteMax;
palette.put(blockKey, blockId);
paletteMax ++;
paletteMax++;
}
while ((blockId & -128) != 0) {
@ -154,6 +161,8 @@ public class SpongeSchematicWriter implements ClipboardWriter {
}
buffer.write(blockId);
}
}
}
schematic.put("PaletteMax", new IntTag(paletteMax));

View File

@ -40,14 +40,14 @@ public interface Region extends Iterable<BlockVector>, 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<BlockVector>, 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<BlockVector>, 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<BlockVector>, 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<BlockVector>, 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<BlockVector>, 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<Vector2D> getChunks();
Set<Vector2D> getChunks();
/**
* Return a list of 16*16*16 chunks in a region
*
* @return the chunk cubes this region overlaps with
*/
public Set<Vector> getChunkCubes();
Set<Vector> 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<BlockVector>, Cloneable {
* @param maxPoints maximum number of points to generate. -1 for no limit.
* @return the points.
*/
public List<BlockVector2D> polygonize(int maxPoints);
List<BlockVector2D> polygonize(int maxPoints);
}