Fixed up tile entities in Sponge schematics.

This commit is contained in:
Matthew Miller 2018-08-04 10:59:14 +10:00
parent b2769befdb
commit 38cff7c7b2
3 changed files with 19 additions and 18 deletions

View File

@ -73,7 +73,7 @@ public enum BuiltInClipboardFormat implements ClipboardFormat {
// Check // Check
Map<String, Tag> schematic = schematicTag.getValue(); Map<String, Tag> schematic = schematicTag.getValue();
if (!schematic.containsKey("Blocks")) { if (!schematic.containsKey("Materials")) {
return false; return false;
} }
} catch (IOException e) { } catch (IOException e) {

View File

@ -110,18 +110,18 @@ public class SpongeSchematicReader extends NBTSchematicReader {
throw new IOException("Invalid offset specified in schematic."); 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 // We appear to have WorldEdit Metadata
int originX = requireTag(metadata, "WEOriginX", IntTag.class).getValue(); int offsetX = requireTag(metadata, "WEOffsetX", IntTag.class).getValue();
int originY = requireTag(metadata, "WEOriginY", IntTag.class).getValue(); int offsetY = requireTag(metadata, "WEOffsetY", IntTag.class).getValue();
int originZ = requireTag(metadata, "WEOriginZ", IntTag.class).getValue(); int offsetZ = requireTag(metadata, "WEOffsetZ", IntTag.class).getValue();
Vector min = new Vector(originX, originY, originZ); Vector offset = new Vector(offsetX, offsetY, offsetZ);
origin = min.subtract(offset); origin = min.subtract(offset);
region = new CuboidRegion(origin, origin.add(width, height, length).subtract(Vector.ONE)); region = new CuboidRegion(origin, origin.add(width, height, length).subtract(Vector.ONE));
} else { } else {
origin = Vector.ZERO.subtract(offset); origin = min;
region = new CuboidRegion(origin, origin.add(width, height, length).subtract(Vector.ONE)); region = new CuboidRegion(origin, origin.add(width, height, length).subtract(Vector.ONE));
} }
@ -160,7 +160,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
for (Map<String, Tag> tileEntity : tileEntityTags) { for (Map<String, Tag> tileEntity : tileEntityTags) {
int[] pos = requireTag(tileEntity, "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(origin.add(new BlockVector(pos[0], pos[1], pos[2])).toBlockVector(), tileEntity);
} }
} catch (Exception e) { } catch (Exception e) {
throw new IOException("Failed to load Tile Entities: " + e.getMessage()); throw new IOException("Failed to load Tile Entities: " + e.getMessage());

View File

@ -97,9 +97,9 @@ public class SpongeSchematicWriter implements ClipboardWriter {
schematic.put("Version", new IntTag(1)); schematic.put("Version", new IntTag(1));
Map<String, Tag> metadata = new HashMap<>(); Map<String, Tag> metadata = new HashMap<>();
metadata.put("WEOriginX", new IntTag(min.getBlockX())); metadata.put("WEOffsetX", new IntTag(offset.getBlockX()));
metadata.put("WEOriginY", new IntTag(min.getBlockY())); metadata.put("WEOffsetY", new IntTag(offset.getBlockY()));
metadata.put("WEOriginZ", new IntTag(min.getBlockZ())); metadata.put("WEOffsetZ", new IntTag(offset.getBlockZ()));
schematic.put("Metadata", new CompoundTag(metadata)); schematic.put("Metadata", new CompoundTag(metadata));
@ -107,10 +107,11 @@ public class SpongeSchematicWriter implements ClipboardWriter {
schematic.put("Height", new ShortTag((short) height)); schematic.put("Height", new ShortTag((short) height));
schematic.put("Length", new ShortTag((short) length)); 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[]{ schematic.put("Offset", new IntArrayTag(new int[]{
offset.getBlockX(), min.getBlockX(),
offset.getBlockY(), min.getBlockY(),
offset.getBlockZ(), min.getBlockZ(),
})); }));
int paletteMax = 0; int paletteMax = 0;
@ -136,9 +137,9 @@ public class SpongeSchematicWriter implements ClipboardWriter {
values.put("Id", new StringTag(block.getNbtId())); values.put("Id", new StringTag(block.getNbtId()));
values.put("Pos", new IntArrayTag(new int[]{ values.put("Pos", new IntArrayTag(new int[]{
point.getBlockX(), x,
point.getBlockY(), y,
point.getBlockZ() z
})); }));
CompoundTag tileEntityTag = new CompoundTag(values); CompoundTag tileEntityTag = new CompoundTag(values);