Add support for rotation argument handling (#12090)

This commit is contained in:
David
2025-02-12 23:30:41 +01:00
committed by GitHub
parent 0680485095
commit 46f4fdaae3
7 changed files with 121 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.function.Predicate;
import io.papermc.paper.math.FinePosition;
import io.papermc.paper.math.Rotation;
import org.bukkit.block.Block;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.entity.Entity;
@@ -411,6 +412,19 @@ public class Location implements Cloneable, ConfigurationSerializable, io.paperm
return this;
}
/**
* Adds rotation to this location. Not world-aware.
*
* @param rotation the rotation to add.
* @return the same location
* @see Vector
*/
@NotNull
@Contract(value = "_ -> this", mutates = "this")
public Location addRotation(@NotNull Rotation rotation) {
return addRotation(rotation.yaw(), rotation.pitch());
}
/**
* Subtracts the location by another.
*
@@ -480,6 +494,19 @@ public class Location implements Cloneable, ConfigurationSerializable, io.paperm
return this;
}
/**
* Subtracts rotation from this location.
*
* @param rotation the rotation to subtract.
* @return the same location
* @see Vector
*/
@NotNull
@Contract(value = "_ -> this", mutates = "this")
public Location subtractRotation(@NotNull Rotation rotation) {
return subtractRotation(rotation.yaw(), rotation.pitch());
}
/**
* Gets the magnitude of the location, defined as sqrt(x^2+y^2+z^2). The
* value of this method is not cached and uses a costly square-root
@@ -622,6 +649,20 @@ public class Location implements Cloneable, ConfigurationSerializable, io.paperm
return this;
}
/**
* Sets the rotation of this location and returns itself.
* <p>
* This mutates this object, clone first.
*
* @param rotation the new rotation.
* @return self (not cloned)
*/
@NotNull
@Contract(value = "_ -> this", mutates = "this")
public Location setRotation(@NotNull Rotation rotation) {
return setRotation(rotation.yaw(), rotation.pitch());
}
/**
* Takes the x/y/z from base and adds the specified x/y/z to it and returns self
* <p>