From 9b76de689c44520df758c95b64de64bf27175831 Mon Sep 17 00:00:00 2001 From: aromaa Date: Mon, 6 Jan 2025 02:37:23 +0200 Subject: [PATCH] Fix Axis & Direction serializationString to match vanilla --- .../java/org/spongepowered/api/util/Axis.java | 16 ++++-- .../org/spongepowered/api/util/Direction.java | 49 +++++++++++-------- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/spongepowered/api/util/Axis.java b/src/main/java/org/spongepowered/api/util/Axis.java index 4537059c7a..929abdf453 100644 --- a/src/main/java/org/spongepowered/api/util/Axis.java +++ b/src/main/java/org/spongepowered/api/util/Axis.java @@ -32,13 +32,15 @@ */ public enum Axis implements Cycleable, StringRepresentable { - X(new Vector3d(1, 0, 0)), - Y(new Vector3d(0, 1, 0)), - Z(new Vector3d(0, 0, 1)); + X("x", new Vector3d(1, 0, 0)), + Y("y", new Vector3d(0, 1, 0)), + Z("z", new Vector3d(0, 0, 1)); + private final String name; private final Vector3d direction; - Axis(final Vector3d vector3d) { + Axis(final String name, final Vector3d vector3d) { + this.name = name; this.direction = vector3d; } @@ -146,7 +148,11 @@ public Axis cycleNext() { @Override public String serializationString() { - return this.name(); + return this.name; } + @Override + public String toString() { + return this.name; + } } diff --git a/src/main/java/org/spongepowered/api/util/Direction.java b/src/main/java/org/spongepowered/api/util/Direction.java index 7ffc7dc87b..9be4dba694 100644 --- a/src/main/java/org/spongepowered/api/util/Direction.java +++ b/src/main/java/org/spongepowered/api/util/Direction.java @@ -44,30 +44,30 @@ * */ public enum Direction implements StringRepresentable { - NORTH(new Vector3d(0, 0, -1), Division.CARDINAL), - NORTH_NORTHEAST(new Vector3d(C.S8, 0, -C.C8), Division.SECONDARY_ORDINAL), - NORTHEAST(new Vector3d(1, 0, -1), Division.ORDINAL), - EAST_NORTHEAST(new Vector3d(C.C8, 0, -C.S8), Division.SECONDARY_ORDINAL), + NORTH("north", new Vector3d(0, 0, -1), Division.CARDINAL), + NORTH_NORTHEAST("north_northeast", new Vector3d(C.S8, 0, -C.C8), Division.SECONDARY_ORDINAL), + NORTHEAST("northeast", new Vector3d(1, 0, -1), Division.ORDINAL), + EAST_NORTHEAST("east_northeast", new Vector3d(C.C8, 0, -C.S8), Division.SECONDARY_ORDINAL), - EAST(new Vector3d(1, 0, 0), Division.CARDINAL), - EAST_SOUTHEAST(new Vector3d(C.C8, 0, C.S8), Division.SECONDARY_ORDINAL), - SOUTHEAST(new Vector3d(1, 0, 1), Division.ORDINAL), - SOUTH_SOUTHEAST(new Vector3d(C.S8, 0, C.C8), Division.SECONDARY_ORDINAL), + EAST("east", new Vector3d(1, 0, 0), Division.CARDINAL), + EAST_SOUTHEAST("east_southeast", new Vector3d(C.C8, 0, C.S8), Division.SECONDARY_ORDINAL), + SOUTHEAST("southeast", new Vector3d(1, 0, 1), Division.ORDINAL), + SOUTH_SOUTHEAST("south_southeast", new Vector3d(C.S8, 0, C.C8), Division.SECONDARY_ORDINAL), - SOUTH(new Vector3d(0, 0, 1), Division.CARDINAL), - SOUTH_SOUTHWEST(new Vector3d(-C.S8, 0, C.C8), Division.SECONDARY_ORDINAL), - SOUTHWEST(new Vector3d(-1, 0, 1), Division.ORDINAL), - WEST_SOUTHWEST(new Vector3d(-C.C8, 0, C.S8), Division.SECONDARY_ORDINAL), + SOUTH("south", new Vector3d(0, 0, 1), Division.CARDINAL), + SOUTH_SOUTHWEST("south_southwest", new Vector3d(-C.S8, 0, C.C8), Division.SECONDARY_ORDINAL), + SOUTHWEST("southwest", new Vector3d(-1, 0, 1), Division.ORDINAL), + WEST_SOUTHWEST("west_southwest", new Vector3d(-C.C8, 0, C.S8), Division.SECONDARY_ORDINAL), - WEST(new Vector3d(-1, 0, 0), Division.CARDINAL), - WEST_NORTHWEST(new Vector3d(-C.C8, 0, -C.S8), Division.SECONDARY_ORDINAL), - NORTHWEST(new Vector3d(-1, 0, -1), Division.ORDINAL), - NORTH_NORTHWEST(new Vector3d(-C.S8, 0, -C.C8), Division.SECONDARY_ORDINAL), + WEST("west", new Vector3d(-1, 0, 0), Division.CARDINAL), + WEST_NORTHWEST("west_northwest", new Vector3d(-C.C8, 0, -C.S8), Division.SECONDARY_ORDINAL), + NORTHWEST("northwest", new Vector3d(-1, 0, -1), Division.ORDINAL), + NORTH_NORTHWEST("north_northwest", new Vector3d(-C.S8, 0, -C.C8), Division.SECONDARY_ORDINAL), - UP(new Vector3d(0, 1, 0), Division.CARDINAL), - DOWN(new Vector3d(0, -1, 0), Division.CARDINAL), + UP("up", new Vector3d(0, 1, 0), Division.CARDINAL), + DOWN("down", new Vector3d(0, -1, 0), Division.CARDINAL), - NONE(new Vector3d(0, 0, 0), Division.NONE); + NONE("none", new Vector3d(0, 0, 0), Division.NONE); private static final Direction[] SECONDARY_ORDINAL_SET = { Direction.NORTH, Direction.NORTH_NORTHEAST, Direction.NORTHEAST, Direction.EAST_NORTHEAST, @@ -82,6 +82,7 @@ public enum Direction implements StringRepresentable { private static final Direction[] CARDINAL_SET = { Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST }; + private final String name; private final Vector3d offset; private final Vector3i blockOffset; private final Division division; @@ -114,7 +115,8 @@ public enum Direction implements StringRepresentable { Direction.SOUTH_SOUTHWEST.opposite = Direction.NORTH_NORTHEAST; } - Direction(Vector3d direction, Division division) { + Direction(final String name, final Vector3d direction, final Division division) { + this.name = name; if (direction.lengthSquared() == 0) { // Prevent normalization of the zero direction this.offset = direction; @@ -344,7 +346,12 @@ public Vector3i asBlockOffset() { @Override public String serializationString() { - return this.name(); + return this.name; + } + + @Override + public String toString() { + return this.name; } private interface C {