Add support for rotation argument handling (#12090)
This commit is contained in:
@ -7,6 +7,7 @@ import io.papermc.paper.command.brigadier.argument.range.IntegerRangeProvider;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.BlockPositionResolver;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.FinePositionResolver;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.PlayerProfileListResolver;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.RotationResolver;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.EntitySelectorArgumentResolver;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
import io.papermc.paper.entity.LookAnchor;
|
||||
@ -123,6 +124,15 @@ public final class ArgumentTypes {
|
||||
return provider().finePosition(centerIntegers);
|
||||
}
|
||||
|
||||
/**
|
||||
* A rotation argument.
|
||||
*
|
||||
* @return rotation argument
|
||||
*/
|
||||
public static ArgumentType<RotationResolver> rotation() {
|
||||
return provider().rotation();
|
||||
}
|
||||
|
||||
/**
|
||||
* A blockstate argument which will provide rich parsing for specifying
|
||||
* the specific block variant and then the block entity NBT if applicable.
|
||||
|
||||
@ -7,6 +7,7 @@ import io.papermc.paper.command.brigadier.argument.range.IntegerRangeProvider;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.BlockPositionResolver;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.FinePositionResolver;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.PlayerProfileListResolver;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.RotationResolver;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.EntitySelectorArgumentResolver;
|
||||
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
|
||||
import io.papermc.paper.entity.LookAnchor;
|
||||
@ -57,6 +58,8 @@ interface VanillaArgumentProvider {
|
||||
|
||||
ArgumentType<FinePositionResolver> finePosition(boolean centerIntegers);
|
||||
|
||||
ArgumentType<RotationResolver> rotation();
|
||||
|
||||
ArgumentType<BlockState> blockState();
|
||||
|
||||
ArgumentType<ItemStack> itemStack();
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
package io.papermc.paper.command.brigadier.argument.resolvers;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.math.Rotation;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* An {@link ArgumentResolver} that's capable of resolving
|
||||
* a rotation argument value using a {@link CommandSourceStack}.
|
||||
*
|
||||
* @see io.papermc.paper.command.brigadier.argument.ArgumentTypes#rotation()
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
@ApiStatus.NonExtendable
|
||||
public interface RotationResolver extends ArgumentResolver<Rotation> {
|
||||
}
|
||||
34
paper-api/src/main/java/io/papermc/paper/math/Rotation.java
Normal file
34
paper-api/src/main/java/io/papermc/paper/math/Rotation.java
Normal file
@ -0,0 +1,34 @@
|
||||
package io.papermc.paper.math;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* Represents a rotation with specified pitch and yaw values.
|
||||
*/
|
||||
@NullMarked
|
||||
public interface Rotation {
|
||||
/**
|
||||
* Creates a new rotation with the specified yaw and pitch values.
|
||||
*
|
||||
* @param yaw the yaw component of the rotation, measured in degrees
|
||||
* @param pitch the pitch component of the rotation, measured in degrees
|
||||
* @return a new {@code Rotation} instance with the specified yaw and pitch
|
||||
*/
|
||||
static Rotation rotation(float yaw, float pitch) {
|
||||
return new RotationImpl(yaw, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the pitch component of the rotation, measured in degrees.
|
||||
*
|
||||
* @return the pitch value in degrees
|
||||
*/
|
||||
float pitch();
|
||||
|
||||
/**
|
||||
* Retrieves the yaw component of the rotation, measured in degrees.
|
||||
*
|
||||
* @return the yaw value in degrees
|
||||
*/
|
||||
float yaw();
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package io.papermc.paper.math;
|
||||
|
||||
record RotationImpl(float yaw, float pitch) implements Rotation {
|
||||
}
|
||||
@ -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>
|
||||
|
||||
Reference in New Issue
Block a user