Commits

Parker Hawke authored and md_5 committed 5f027d2d1a2
#949: Add Vector#fromJOML() overloads for read-only vector types
No tags

src/main/java/org/bukkit/util/Vector.java

Modified
5 5 import java.util.LinkedHashMap;
6 6 import java.util.Map;
7 7 import java.util.Random;
8 8 import org.bukkit.Location;
9 9 import org.bukkit.World;
10 10 import org.bukkit.configuration.serialization.ConfigurationSerializable;
11 11 import org.bukkit.configuration.serialization.SerializableAs;
12 12 import org.jetbrains.annotations.NotNull;
13 13 import org.joml.RoundingMode;
14 14 import org.joml.Vector3d;
15 +import org.joml.Vector3dc;
15 16 import org.joml.Vector3f;
17 +import org.joml.Vector3fc;
16 18 import org.joml.Vector3i;
19 +import org.joml.Vector3ic;
17 20
18 21 /**
19 22 * Represents a mutable vector. Because the components of Vectors are mutable,
20 23 * storing Vectors long term may be dangerous if passing code modifies the
21 24 * Vector later. If you want to keep around a Vector, it may be wise to call
22 25 * <code>clone()</code> in order to get a copy.
23 26 */
24 27 @SerializableAs("Vector")
25 28 public class Vector implements Cloneable, ConfigurationSerializable {
26 29 private static final long serialVersionUID = -2657651106777219169L;
941 944 * Gets a vector with components that match the provided JOML {@link Vector3i}.
942 945 *
943 946 * @param vector the vector to match
944 947 * @return the new vector
945 948 */
946 949 @NotNull
947 950 public static Vector fromJOML(@NotNull Vector3i vector) {
948 951 return new Vector(vector.x(), vector.y(), vector.z());
949 952 }
950 953
954 + /**
955 + * Gets a vector with components that match the provided JOML {@link Vector3fc}.
956 + *
957 + * @param vector the vector to match
958 + * @return the new vector
959 + */
960 + @NotNull
961 + public static Vector fromJOML(@NotNull Vector3fc vector) {
962 + return new Vector(vector.x(), vector.y(), vector.z());
963 + }
964 +
965 + /**
966 + * Gets a vector with components that match the provided JOML {@link Vector3dc}.
967 + *
968 + * @param vector the vector to match
969 + * @return the new vector
970 + */
971 + @NotNull
972 + public static Vector fromJOML(@NotNull Vector3dc vector) {
973 + return new Vector(vector.x(), vector.y(), vector.z());
974 + }
975 +
976 + /**
977 + * Gets a vector with components that match the provided JOML {@link Vector3ic}.
978 + *
979 + * @param vector the vector to match
980 + * @return the new vector
981 + */
982 + @NotNull
983 + public static Vector fromJOML(@NotNull Vector3ic vector) {
984 + return new Vector(vector.x(), vector.y(), vector.z());
985 + }
986 +
951 987 @Override
952 988 @NotNull
953 989 public Map<String, Object> serialize() {
954 990 Map<String, Object> result = new LinkedHashMap<String, Object>();
955 991
956 992 result.put("x", getX());
957 993 result.put("y", getY());
958 994 result.put("z", getZ());
959 995
960 996 return result;

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut