Write yaw/pitch in degrees rather than in radians with schematic files.

This commit is contained in:
sk89q 2014-07-14 20:35:29 -07:00
parent e2082ee8a4
commit 7243b2a05d
2 changed files with 7 additions and 38 deletions

View File

@ -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<Tag> 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<Tag> 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 extends Tag> T requireTag(Map<String, Tag> items, String key, Class<T> expected) throws IOException {
if (!items.containsKey(key)) {
throw new IOException("Schematic file is missing a \"" + key + "\" tag");

View File

@ -206,8 +206,8 @@ public class SchematicWriter implements ClipboardWriter {
private Tag writeRotation(Location location, String name) {
List<FloatTag> list = new ArrayList<FloatTag>();
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);
}