Skip to content

Commit

Permalink
Fixed up tile entities in Sponge schematics.
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Aug 4, 2018
1 parent b2769be commit 38cff7c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
Expand Up @@ -73,7 +73,7 @@ public boolean isFormat(File file) {

// Check
Map<String, Tag> schematic = schematicTag.getValue();
if (!schematic.containsKey("Blocks")) {
if (!schematic.containsKey("Materials")) {
return false;
}
} catch (IOException e) {
Expand Down
Expand Up @@ -110,18 +110,18 @@ private Clipboard readVersion1(Map<String, Tag> schematic) throws IOException {
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));
}

Expand Down Expand Up @@ -160,7 +160,7 @@ private Clipboard readVersion1(Map<String, Tag> schematic) throws IOException {

for (Map<String, Tag> 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());
Expand Down
Expand Up @@ -97,20 +97,21 @@ private Map<String, Tag> write1(Clipboard clipboard) throws IOException {
schematic.put("Version", new IntTag(1));

Map<String, Tag> 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));

schematic.put("Width", new ShortTag((short) width));
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;
Expand All @@ -136,9 +137,9 @@ private Map<String, Tag> write1(Clipboard clipboard) throws IOException {

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);
Expand Down

0 comments on commit 38cff7c

Please sign in to comment.