From 1f1c5de303240d29709a58532e34853f01f367f4 Mon Sep 17 00:00:00 2001 From: Hunter Kvalevog Date: Sat, 4 Jul 2020 06:02:24 -0500 Subject: [PATCH] Add "/player look at" subcommand --- src/main/java/carpet/commands/PlayerCommand.java | 10 ++++++++++ .../java/carpet/helpers/EntityPlayerActionPack.java | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/src/main/java/carpet/commands/PlayerCommand.java b/src/main/java/carpet/commands/PlayerCommand.java index e6d99c12..34f5b46a 100644 --- a/src/main/java/carpet/commands/PlayerCommand.java +++ b/src/main/java/carpet/commands/PlayerCommand.java @@ -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 context) + { + return manipulate(context, ap -> { + try { + ap.lookAt(Vec3ArgumentType.getVec3(context, "position")); + } catch (CommandSyntaxException ignored) {} + }); + } + @FunctionalInterface interface SupplierWithCommandSyntaxException { diff --git a/src/main/java/carpet/helpers/EntityPlayerActionPack.java b/src/main/java/carpet/helpers/EntityPlayerActionPack.java index d33694a2..6f3d0a76 100644 --- a/src/main/java/carpet/helpers/EntityPlayerActionPack.java +++ b/src/main/java/carpet/helpers/EntityPlayerActionPack.java @@ -2,6 +2,7 @@ package carpet.helpers; import carpet.fakes.ServerPlayerEntityInterface; import net.minecraft.block.BlockState; +import net.minecraft.command.arguments.EntityAnchorArgumentType; import net.minecraft.entity.Entity; import net.minecraft.entity.passive.HorseBaseEntity; import net.minecraft.entity.player.PlayerInventory; @@ -127,6 +128,12 @@ public class EntityPlayerActionPack return this; } + public EntityPlayerActionPack lookAt(Vec3d position) + { + player.lookAt(EntityAnchorArgumentType.EntityAnchor.EYES, position); + return this; + } + public EntityPlayerActionPack turn(float yaw, float pitch) { return look(player.yaw + yaw, player.pitch + pitch);