Merge pull request #366 from hkva/master

Allow "/player look" to target locations in the world with "/player look at"
This commit is contained in:
gnembon authored and GitHub committed 2020-07-06 00:22:52 -03:00
commit 307ce57c0b
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>
{
@@ -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);