From 845360f46f6b3300bc62310638233cf8b0e14776 Mon Sep 17 00:00:00 2001 From: Karl Broman Date: Mon, 11 Feb 2019 14:15:23 -0600 Subject: [PATCH] Add setPlayerRotation(), setPlayerPitch(), and setPlayerDirection() --- NAMESPACE | 3 ++ NEWS.md | 5 ++- R/setPlayerOrientation.R | 95 +++++++++++++++++++++++++++++++++++++++ man/setPlayerDirection.Rd | 35 +++++++++++++++ man/setPlayerPitch.Rd | 28 ++++++++++++ man/setPlayerRotation.Rd | 29 ++++++++++++ 6 files changed, 193 insertions(+), 2 deletions(-) create mode 100644 R/setPlayerOrientation.R create mode 100644 man/setPlayerDirection.Rd create mode 100644 man/setPlayerPitch.Rd create mode 100644 man/setPlayerRotation.Rd diff --git a/NAMESPACE b/NAMESPACE index 32691f5..3108cc3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -20,7 +20,10 @@ export(mc_close) export(mc_connect) export(setBlock) export(setBlocks) +export(setPlayerDirection) +export(setPlayerPitch) export(setPlayerPos) +export(setPlayerRotation) export(spawnEntity) importFrom(stats,setNames) importFrom(utils,assignInMyNamespace) diff --git a/NEWS.md b/NEWS.md index 23e4c15..3198f9a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,9 +7,10 @@ - A bunch of new functions available with the latest version of the RaspberryJuice plugin (1.11): `getPlayerId()`, `getPlayerName()`, - `getEntityTypes()` + `getEntityTypes()`, `spawnEntity()`, `setDirection()`, + `setRotation()`, and `setPitch()`. -- Added `find_entity()` for search the output of `getEntityTypes()` to +- Added `find_entity()` for searching the output of `getEntityTypes()` to find a particular type of entity. This is similar to `find_item()`. diff --git a/R/setPlayerOrientation.R b/R/setPlayerOrientation.R new file mode 100644 index 0000000..7cea7b6 --- /dev/null +++ b/R/setPlayerOrientation.R @@ -0,0 +1,95 @@ +#' Set a player's rotation +#' +#' Set a player's rotation +#' +#' @md +#' +#' @param angle Angle of rotation (0-360) +#' @param id Player or entity ID +#' +#' @examples +#' \dontrun{ +#' mc_connect() +#' getPlayerIds() +#' current <- getPlayerRotation(355) +#' setPlayerRotation(current + 90, 355) +#' } +#' +#' @seealso [getPlayerRotation()], [setPlayerPitch()], [setPlayerDirection()], +#' [setPlayerPos()] +#' +#' @export +#' + +setPlayerRotation <- function(angle, id) +{ + + mc_sendreceive(merge_data("entity.setRotation", angle, id)) + +} + + +#' Set a player's pitch +#' +#' Set a player's pitch +#' +#' @md +#' +#' @param angle Angle of pitch (-90 is straight up and +90 is straight down) +#' @param id Player or entity ID +#' +#' @examples +#' \dontrun{ +#' mc_connect() +#' getPlayerIds() +#' setPlayerPitch(45, 355) +#' } +#' +#' @seealso [getPlayerPitch()], [setPlayerRotation()], [setPlayerDirection()], +#' [setPlayerPos()] +#' +#' @export +#' + +setPlayerPitch <- function(angle, id) +{ + + mc_send(merge_data("player.setPitch", angle, id)) + +} + + + + +#' Set a player's direction +#' +#' Set a player's direction +#' +#' @md +#' +#' @param x east/west direction +#' @param y up/down direction +#' @param z north/south direction +#' @param id Player or entity ID +#' +#' @details (`x`, `y`, `z`) define a unit vector to which the player will now point. +#' +#' @examples +#' \dontrun{ +#' mc_connect() +#' getPlayerIds() +#' setPlayerDirection(45, 355) +#' } +#' +#' @seealso [getPlayerDirection()], [setPlayerRotation()], [setPlayerPitch()], +#' [setPlayerPos()] +#' +#' @export +#' + +setPlayerDirection <- function(x, y, z, id) +{ + + mc_send(merge_data("player.setDirection", x, y, z, id)) + +} diff --git a/man/setPlayerDirection.Rd b/man/setPlayerDirection.Rd new file mode 100644 index 0000000..933946f --- /dev/null +++ b/man/setPlayerDirection.Rd @@ -0,0 +1,35 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/setPlayerOrientation.R +\name{setPlayerDirection} +\alias{setPlayerDirection} +\title{Set a player's direction} +\usage{ +setPlayerDirection(x, y, z, id) +} +\arguments{ +\item{x}{east/west direction} + +\item{y}{up/down direction} + +\item{z}{north/south direction} + +\item{id}{Player or entity ID} +} +\description{ +Set a player's direction +} +\details{ +(\code{x}, \code{y}, \code{z}) define a unit vector to which the player will now point. +} +\examples{ +\dontrun{ +mc_connect() +getPlayerIds() +setPlayerDirection(45, 355) +} + +} +\seealso{ +\code{\link[=getPlayerDirection]{getPlayerDirection()}}, \code{\link[=setPlayerRotation]{setPlayerRotation()}}, \code{\link[=setPlayerPitch]{setPlayerPitch()}}, +\code{\link[=setPlayerPos]{setPlayerPos()}} +} diff --git a/man/setPlayerPitch.Rd b/man/setPlayerPitch.Rd new file mode 100644 index 0000000..104ddd0 --- /dev/null +++ b/man/setPlayerPitch.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/setPlayerOrientation.R +\name{setPlayerPitch} +\alias{setPlayerPitch} +\title{Set a player's pitch} +\usage{ +setPlayerPitch(angle, id) +} +\arguments{ +\item{angle}{Angle of pitch (-90 is straight up and +90 is straight down)} + +\item{id}{Player or entity ID} +} +\description{ +Set a player's pitch +} +\examples{ +\dontrun{ +mc_connect() +getPlayerIds() +setPlayerPitch(45, 355) +} + +} +\seealso{ +\code{\link[=getPlayerPitch]{getPlayerPitch()}}, \code{\link[=setPlayerRotation]{setPlayerRotation()}}, \code{\link[=setPlayerDirection]{setPlayerDirection()}}, +\code{\link[=setPlayerPos]{setPlayerPos()}} +} diff --git a/man/setPlayerRotation.Rd b/man/setPlayerRotation.Rd new file mode 100644 index 0000000..d72b7c6 --- /dev/null +++ b/man/setPlayerRotation.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/setPlayerOrientation.R +\name{setPlayerRotation} +\alias{setPlayerRotation} +\title{Set a player's rotation} +\usage{ +setPlayerRotation(angle, id) +} +\arguments{ +\item{angle}{Angle of rotation (0-360)} + +\item{id}{Player or entity ID} +} +\description{ +Set a player's rotation +} +\examples{ +\dontrun{ +mc_connect() +getPlayerIds() +current <- getPlayerRotation(355) +setPlayerRotation(current + 90, 355) +} + +} +\seealso{ +\code{\link[=getPlayerRotation]{getPlayerRotation()}}, \code{\link[=setPlayerPitch]{setPlayerPitch()}}, \code{\link[=setPlayerDirection]{setPlayerDirection()}}, +\code{\link[=setPlayerPos]{setPlayerPos()}} +}