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 {
|
||||
}
|
||||
Reference in New Issue
Block a user