From 7243b2a05d751463168568420d8735257092ff26 Mon Sep 17 00:00:00 2001 From: sk89q Date: Mon, 14 Jul 2014 20:35:29 -0700 Subject: [PATCH] Write yaw/pitch in degrees rather than in radians with schematic files. --- .../extent/clipboard/io/SchematicReader.java | 41 +++---------------- .../extent/clipboard/io/SchematicWriter.java | 4 +- 2 files changed, 7 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java b/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java index ad0e9bbf8..bae3ae753 100644 --- a/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java +++ b/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicReader.java @@ -40,6 +40,7 @@ import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.registry.WorldData; +import com.sk89q.worldedit.world.storage.NBTConversions; import javax.annotation.Nullable; import java.io.IOException; @@ -230,12 +231,11 @@ public class SchematicReader implements ClipboardReader { for (Tag tag : entityTags) { if (tag instanceof CompoundTag) { CompoundTag compound = (CompoundTag) tag; - StringTag idTag = getTag(compound, StringTag.class, "id"); - Vector position = getVector(getTag(compound, ListTag.class, "Pos")); + String id = compound.getString("id"); + Location location = NBTConversions.toLocation(clipboard, compound.getListTag("Pos"), compound.getListTag("Rotation")); - if (idTag != null & position != null) { - Location location = readRotation(getTag(compound, ListTag.class, "Rotation"), new Location(clipboard, position)); - BaseEntity state = new BaseEntity(idTag.getValue(), compound); + if (!id.isEmpty()) { + BaseEntity state = new BaseEntity(id, compound); clipboard.createEntity(location, state); } } @@ -246,37 +246,6 @@ public class SchematicReader implements ClipboardReader { return clipboard; } - @Nullable - private static Vector getVector(@Nullable ListTag tag) { - if (tag != null) { - List tags = tag.getValue(); - - if (tags.size() == 3 && tags.get(0) instanceof DoubleTag) { - double x = ((DoubleTag) tags.get(0)).getValue(); - double y = ((DoubleTag) tags.get(1)).getValue(); - double z = ((DoubleTag) tags.get(2)).getValue(); - return new Vector(x, y, z); - } - } - - return null; - } - - @Nullable - private static Location readRotation(@Nullable ListTag tag, Location location) { - if (tag != null) { - List tags = tag.getValue(); - - if (tags.size() == 2 && tags.get(0) instanceof FloatTag) { - float yaw = ((FloatTag) tags.get(0)).getValue(); - float pitch = ((FloatTag) tags.get(1)).getValue(); - location = location.setDirection(yaw, pitch); - } - } - - return location; - } - private static T requireTag(Map items, String key, Class expected) throws IOException { if (!items.containsKey(key)) { throw new IOException("Schematic file is missing a \"" + key + "\" tag"); diff --git a/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicWriter.java b/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicWriter.java index 6e907cb0e..d5bf31e4f 100644 --- a/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicWriter.java +++ b/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicWriter.java @@ -206,8 +206,8 @@ public class SchematicWriter implements ClipboardWriter { private Tag writeRotation(Location location, String name) { List list = new ArrayList(); - list.add(new FloatTag("", location.getYaw())); - list.add(new FloatTag("", location.getPitch())); + list.add(new FloatTag("", (float) Math.toDegrees(location.getYaw()))); + list.add(new FloatTag("", (float) Math.toDegrees(location.getPitch()))); return new ListTag(name, FloatTag.class, list); }