Expand ArmorStand API
Adds the following: - Add proper methods for getting and setting items in both hands. Deprecates old methods - Enable/Disable slot interactions - Allow using degrees for ArmorStand rotations (via new Rotations class) Co-authored-by: SoSeDiK <mrsosedik@gmail.com>
This commit is contained in:
101
paper-api/src/main/java/io/papermc/paper/math/Rotations.java
Normal file
101
paper-api/src/main/java/io/papermc/paper/math/Rotations.java
Normal file
@@ -0,0 +1,101 @@
|
||||
package io.papermc.paper.math;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* Rotations is an immutable object that stores rotations
|
||||
* in degrees on each axis (X, Y, Z).
|
||||
*/
|
||||
@NullMarked
|
||||
public interface Rotations {
|
||||
|
||||
/**
|
||||
* Rotations instance with every axis set to 0
|
||||
*/
|
||||
Rotations ZERO = ofDegrees(0, 0, 0);
|
||||
|
||||
/**
|
||||
* Creates a new Rotations instance holding the provided rotations
|
||||
*
|
||||
* @param x the angle for the X axis in degrees
|
||||
* @param y the angle for the Y axis in degrees
|
||||
* @param z the angle for the Z axis in degrees
|
||||
* @return Rotations instance holding the provided rotations
|
||||
*/
|
||||
static Rotations ofDegrees(final double x, final double y, final double z) {
|
||||
return new RotationsImpl(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the angle on the X axis in degrees
|
||||
*
|
||||
* @return the angle in degrees
|
||||
*/
|
||||
double x();
|
||||
|
||||
/**
|
||||
* Returns the angle on the Y axis in degrees
|
||||
*
|
||||
* @return the angle in degrees
|
||||
*/
|
||||
double y();
|
||||
|
||||
/**
|
||||
* Returns the angle on the Z axis in degrees
|
||||
*
|
||||
* @return the angle in degrees
|
||||
*/
|
||||
double z();
|
||||
|
||||
/**
|
||||
* Returns a new Rotations instance which is the result
|
||||
* of changing the X axis to the passed angle
|
||||
*
|
||||
* @param x the angle in degrees
|
||||
* @return the resultant Rotations
|
||||
*/
|
||||
Rotations withX(double x);
|
||||
|
||||
/**
|
||||
* Returns a new Rotations instance which is the result
|
||||
* of changing the Y axis to the passed angle
|
||||
*
|
||||
* @param y the angle in degrees
|
||||
* @return the resultant Rotations
|
||||
*/
|
||||
Rotations withY(double y);
|
||||
|
||||
/**
|
||||
* Returns a new Rotations instance which is the result
|
||||
* of changing the Z axis to the passed angle
|
||||
*
|
||||
* @param z the angle in degrees
|
||||
* @return the resultant Rotations
|
||||
*/
|
||||
Rotations withZ(double z);
|
||||
|
||||
/**
|
||||
* Returns a new Rotations instance which is the result of adding
|
||||
* the x, y, z components to this Rotations
|
||||
*
|
||||
* @param x the angle to add to the X axis in degrees
|
||||
* @param y the angle to add to the Y axis in degrees
|
||||
* @param z the angle to add to the Z axis in degrees
|
||||
* @return the resultant Rotations
|
||||
*/
|
||||
Rotations add(double x, double y, double z);
|
||||
|
||||
/**
|
||||
* Returns a new Rotations instance which is the result of subtracting
|
||||
* the x, y, z components from this Rotations
|
||||
*
|
||||
* @param x the angle to subtract from the X axis in degrees
|
||||
* @param y the angle to subtract from the Y axis in degrees
|
||||
* @param z the angle to subtract from the Z axis in degrees
|
||||
* @return the resultant Rotations
|
||||
*/
|
||||
default Rotations subtract(final double x, final double y, final double z) {
|
||||
return this.add(-x, -y, -z);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package io.papermc.paper.math;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
record RotationsImpl(double x, double y, double z) implements Rotations {
|
||||
|
||||
@Override
|
||||
public RotationsImpl withX(final double x) {
|
||||
return new RotationsImpl(x, this.y, this.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RotationsImpl withY(final double y) {
|
||||
return new RotationsImpl(this.x, y, this.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RotationsImpl withZ(final double z) {
|
||||
return new RotationsImpl(this.x, this.y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RotationsImpl add(final double x, final double y, final double z) {
|
||||
return new RotationsImpl(this.x + x, this.y + y, this.z + z);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user