Add "/player look at" subcommand

This commit is contained in:
Hunter Kvalevog committed 2020-07-04 06:02:24 -05:00
1 parent 41258e8494
commit 1f1c5de303
2 files changed
+17

No files matched your search

@@ -73,6 +73,7 @@ public class PlayerCommand
.then(literal("west").executes(manipulation(ap -> ap.look(Direction.WEST))))
.then(literal("up").executes(manipulation(ap -> ap.look(Direction.UP))))
.then(literal("down").executes(manipulation(ap -> ap.look(Direction.DOWN))))
.then(literal("at").then(argument("position", Vec3ArgumentType.vec3()).executes(PlayerCommand::lookAt)))
.then(argument("direction", RotationArgumentType.rotation())
.executes(c -> manipulate(c, ap -> ap.look(RotationArgumentType.getRotation(c, "direction").toAbsoluteRotation(c.getSource())))))
).then(literal("turn")
@@ -204,6 +205,15 @@ public class PlayerCommand
return 1;
}
private static int lookAt(CommandContext<ServerCommandSource> context)
{
return manipulate(context, ap -> {
try {
ap.lookAt(Vec3ArgumentType.getVec3(context, "position"));
} catch (CommandSyntaxException ignored) {}
});
}
@FunctionalInterface
interface SupplierWithCommandSyntaxException<T>
{