mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-29 19:51:30 +01:00
#844: Add methods to convert Vector to and from JOML vectors
By: Parker Hawke <hawkeboyz2@hotmail.com>
This commit is contained in:
parent
dd112b4907
commit
71089b4713
@ -10,6 +10,10 @@ import org.bukkit.World;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.joml.RoundingMode;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
/**
|
||||
* Represents a mutable vector. Because the components of Vectors are mutable,
|
||||
@ -814,6 +818,48 @@ public class Vector implements Cloneable, ConfigurationSerializable {
|
||||
return new BlockVector(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this vector as a JOML {@link Vector3f}.
|
||||
*
|
||||
* @return the JOML vector
|
||||
*/
|
||||
@NotNull
|
||||
public Vector3f toVector3f() {
|
||||
return new Vector3f((float) x, (float) y, (float) z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this vector as a JOML {@link Vector3d}.
|
||||
*
|
||||
* @return the JOML vector
|
||||
*/
|
||||
@NotNull
|
||||
public Vector3d toVector3d() {
|
||||
return new Vector3d(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this vector as a JOML {@link Vector3i}.
|
||||
*
|
||||
* @param roundingMode the {@link RoundingMode} to use for this vector's components
|
||||
* @return the JOML vector
|
||||
*/
|
||||
@NotNull
|
||||
public Vector3i toVector3i(int roundingMode) {
|
||||
return new Vector3i(x, y, z, roundingMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this vector as a JOML {@link Vector3i} with its components floored.
|
||||
*
|
||||
* @return the JOML vector
|
||||
* @see #toVector3i(int)
|
||||
*/
|
||||
@NotNull
|
||||
public Vector3i toVector3i() {
|
||||
return toVector3i(RoundingMode.FLOOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if each component of this Vector is finite.
|
||||
*
|
||||
@ -869,6 +915,39 @@ public class Vector implements Cloneable, ConfigurationSerializable {
|
||||
return new Vector(random.nextDouble(), random.nextDouble(), random.nextDouble());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a vector with components that match the provided JOML {@link Vector3f}.
|
||||
*
|
||||
* @param vector the vector to match
|
||||
* @return the new vector
|
||||
*/
|
||||
@NotNull
|
||||
public static Vector fromJOML(@NotNull Vector3f vector) {
|
||||
return new Vector(vector.x(), vector.y(), vector.z());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a vector with components that match the provided JOML {@link Vector3d}.
|
||||
*
|
||||
* @param vector the vector to match
|
||||
* @return the new vector
|
||||
*/
|
||||
@NotNull
|
||||
public static Vector fromJOML(@NotNull Vector3d vector) {
|
||||
return new Vector(vector.x(), vector.y(), vector.z());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a vector with components that match the provided JOML {@link Vector3i}.
|
||||
*
|
||||
* @param vector the vector to match
|
||||
* @return the new vector
|
||||
*/
|
||||
@NotNull
|
||||
public static Vector fromJOML(@NotNull Vector3i vector) {
|
||||
return new Vector(vector.x(), vector.y(), vector.z());
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Map<String, Object> serialize() {
|
||||
|
Loading…
Reference in New Issue
Block a user