#949: Add Vector#fromJOML() overloads for read-only vector types

By: Parker Hawke <hawkeboyz2@hotmail.com>
This commit is contained in:
Bukkit/Spigot 2023-12-19 19:11:12 +11:00
parent b1ba1b1b8d
commit 9ce011cf3b

View File

@ -12,8 +12,11 @@ import org.bukkit.configuration.serialization.SerializableAs;
import org.jetbrains.annotations.NotNull;
import org.joml.RoundingMode;
import org.joml.Vector3d;
import org.joml.Vector3dc;
import org.joml.Vector3f;
import org.joml.Vector3fc;
import org.joml.Vector3i;
import org.joml.Vector3ic;
/**
* Represents a mutable vector. Because the components of Vectors are mutable,
@ -948,6 +951,39 @@ public class Vector implements Cloneable, ConfigurationSerializable {
return new Vector(vector.x(), vector.y(), vector.z());
}
/**
* Gets a vector with components that match the provided JOML {@link Vector3fc}.
*
* @param vector the vector to match
* @return the new vector
*/
@NotNull
public static Vector fromJOML(@NotNull Vector3fc vector) {
return new Vector(vector.x(), vector.y(), vector.z());
}
/**
* Gets a vector with components that match the provided JOML {@link Vector3dc}.
*
* @param vector the vector to match
* @return the new vector
*/
@NotNull
public static Vector fromJOML(@NotNull Vector3dc vector) {
return new Vector(vector.x(), vector.y(), vector.z());
}
/**
* Gets a vector with components that match the provided JOML {@link Vector3ic}.
*
* @param vector the vector to match
* @return the new vector
*/
@NotNull
public static Vector fromJOML(@NotNull Vector3ic vector) {
return new Vector(vector.x(), vector.y(), vector.z());
}
@Override
@NotNull
public Map<String, Object> serialize() {