| Title: | Control Minecraft with RaspberryJuice API |
|---|---|
| Description: | Following the code in py3minepi, allows one to connect to the minecraft from R. |
| Authors: | Karl Broman [aut, cre], Brooke Anderson [aut], Gergely Daróczi [aut], Ali Zaidi [aut], Mario Inchiosa [aut], David Smith [aut] |
| Maintainer: | Karl Broman <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.3.2 |
| Built: | 2026-06-01 16:41:53 UTC |
| Source: | https://github.com/kbroman/miner |
Post a message to Minecraft chat.
chatPost(text)chatPost(text)
text |
A character string with the message you would like to post. |
## Not run: chatPost('foobar') ## Post the first few digits of pi to chat for (p in strsplit(as.character(round(pi, 4)), '')[[1]]) { chatPost(p) } ## End(Not run)## Not run: chatPost('foobar') ## Post the first few digits of pi to chat for (p in strsplit(as.character(round(pi, 4)), '')[[1]]) { chatPost(p) } ## End(Not run)
Find a Minecraft entity by name.
find_entity(name)find_entity(name)
name |
Character string with a Minecraft entity name (can be a partial match) |
We first look to see whether there is an exact match to
the namex column in the output of getEntityTypes(). If there
is, we return that row. If not, we use grep() with
ignore.case=TRUE and return matching rows.
Data frame with a row or set of rows from the output of
getEntityTypes() that match the queried name.
## Not run: find_entity("HORSE") find_entity("horse") ## End(Not run)## Not run: find_entity("HORSE") find_entity("horse") ## End(Not run)
Find a Minecraft item by name or ID. If querying an item by ID, the search can also specify item style.
find_item(name = NULL, id = NULL, style = 0)find_item(name = NULL, id = NULL, style = 0)
name |
Character string with the name of a Minecraft item (specify
either |
id |
A numeric or character string with the ID of a Minecraft item
(specify either |
style |
A numeric or character string with the style of a Minecraft
item (use this argument only if querying by |
If name is provided, we first look to see whether there
is an exact match to the name column in mc_items. If there
is, we return that row. If not, we use grep()
with ignore.case=TRUE and return matching rows.
If instead id is provided, we return the row with that id.
The default is to return the row with that ID and style==0,
or whatever style was provided. If style is NULL, we return
all rows with that ID.
Data frame with a row or set of rows from mc_items that
match the queried name, ID, and / or style.
find_item(name = "Oak") find_item(id = 5) find_item(id = 5, style = 5)find_item(name = "Oak") find_item(id = 5) find_item(id = 5, style = 5)
Determine the type of the block at position x (north / south),
y (height), z (east / west). By default, the block's style is
also given, although the style can be excluded from the output
using the include_style parameter.
getBlock(x, y, z, include_style = TRUE)getBlock(x, y, z, include_style = TRUE)
x |
A numeric string with north/south position |
y |
A numeric string with height |
z |
A numeric string with east/west position |
include_style |
A logical value of whether the block's style should also be included in the output (defaults to TRUE). |
A numeric vector of length one or two with the type ID
and style, if include_style is TRUE, of the block
at position (x, y, z). You can use find_item() to
find the name of the block type based on this returned ID.
## Not run: mc_connect() h <- getHeight(0,0) b_type <- getBlock(0,h,0) b_type find_item(id = b_type[1]) find_item(id = b_type[1], style = b_type[2]) getBlock(0,h,0, include_style = FALSE) ## End(Not run)## Not run: mc_connect() h <- getHeight(0,0) b_type <- getBlock(0,h,0) b_type find_item(id = b_type[1]) find_item(id = b_type[1], style = b_type[2]) getBlock(0,h,0, include_style = FALSE) ## End(Not run)
Return the most recent block hits made in the Minecraft world by an iron sword.
getBlockHits()getBlockHits()
A dataframe with columns for the coordinates, block type, and player id of recent block hits.
Only right clicks with an iron sword are logged.
## Not run: getBlockHits() library(futile.logger) while (TRUE) { flog.info(getEventsBlockHits()) Sys.sleep(1) } ## End(Not run)## Not run: getBlockHits() library(futile.logger) while (TRUE) { flog.info(getEventsBlockHits()) Sys.sleep(1) } ## End(Not run)
Determine block types in a cuboid for which one corner is at the position (x0, y0, z0) and the opposite corner is at the position (x1, y1, z1).
getBlocks(x0, y0, z0, x1, y1, z1)getBlocks(x0, y0, z0, x1, y1, z1)
x0 |
A numeric value giving the starting north / south position of the cuboid. |
y0 |
A numeric value giving the starting height of the cuboid. |
z0 |
A numeric value giving the starting east / west position of the cuboid. |
x1 |
A numeric value giving the north / south position of the opposite corner of the cuboid. |
y1 |
A numeric value giving the ending height of the opposite corner of the cuboid. |
z1 |
A numeric value giving the ending east / west position of the opposite corner of the cuboid. |
A 3-D array of integers where each integer gives the ID of the type of a block in the cuboid.
## Not run: mc_connect() h <- getHeight(0,0) block_types <- getBlocks(0, h, 0, 1, h + 3, 2) block_types find_item(id = block_types[1, 1, 1]) ## End(Not run)## Not run: mc_connect() h <- getHeight(0,0) block_types <- getBlocks(0, h, 0, 1, h + 3, 2) block_types find_item(id = block_types[1, 1, 1]) ## End(Not run)
Returns the chat posts that have been posted recently and since the
last time the function was run. It is possible that this does not
return chat posts that were posted using chatPost().
getChatPosts()getChatPosts()
A dataframe of recent chat posts with columns for the player id of the poster and the message posted
## Not run: mc_connect() getChatPosts() ## End(Not run)## Not run: mc_connect() getChatPosts() ## End(Not run)
Get a table of available entity types and their IDs.
getEntityTypes()getEntityTypes()
a data frame with two rows, id and type.
mc_items(), spawnEntity(), find_entity()
## Not run: mc_connect() getEntityTypes() ## End(Not run)## Not run: mc_connect() getEntityTypes() ## End(Not run)
Get height of the world at a given position, where the world's height is defined as the height of the highest non-air point at that location.
getHeight(x, z)getHeight(x, z)
x |
A numeric string with north/south position |
z |
A numeric string with east/west position |
Integer with height of block just above the last bit of non-air at the specified x / z position.
## Not run: mc_connect() getHeight(0,0) ## End(Not run)## Not run: mc_connect() getHeight(0,0) ## End(Not run)
Returns a unit vector describing the current direction a player is facing.
The default is to get the direction for the first player spawned in the Minecraft,
world, but the directions of other players can be gotten using the player_id
argument.
getPlayerDirection(player_id = NULL)getPlayerDirection(player_id = NULL)
player_id |
Integer giving the ID of a player. You can find IDs of all
current players using |
x is east/west with east being the positive direction. y is up/down with up being the positive direction, and z is north/south with south being the positive direction.
A numeric vector of length 3 with coordinates of the player's current direction (gaze) as a unit vector, (x,y,z).
getPlayerRotation(), getPlayerPitch(), getPlayerPos()
## Not run: getPlayerDirection() example_playerId <- getPlayerIds()[1] getPlayerDirection(example_playerId) ## End(Not run)## Not run: getPlayerDirection() example_playerId <- getPlayerIds()[1] getPlayerDirection(example_playerId) ## End(Not run)
Get the ID for a player with a given name.
getPlayerId(player_name)getPlayerId(player_name)
player_name |
Character string with name of a player. |
A number representing the ID of the player.
getPlayerIds(), getPlayerName()
## Not run: mc_connect() getPlayerIds() getPlayerId("wyldstyle") ## End(Not run)## Not run: mc_connect() getPlayerIds() getPlayerId("wyldstyle") ## End(Not run)
Get the IDs of all player currently in the world.
getPlayerIds()getPlayerIds()
A numeric vector with the IDs of each player currently in the MineCraft world. Player ids are listed in the order they joined the game world.
getPlayerId(), getPlayerName()
## Not run: mc_connect() getPlayerIds() ## End(Not run)## Not run: mc_connect() getPlayerIds() ## End(Not run)
Get the name of a player with a given ID
getPlayerName(player_id)getPlayerName(player_id)
player_id |
Integer giving the ID of a player. You can find IDs of all
current players using |
A character string with the name of the identified player.
## Not run: mc_connect() getPlayerIds() getPlayerName(322) ## End(Not run)## Not run: mc_connect() getPlayerIds() getPlayerName(322) ## End(Not run)
Return the player's pitch (angle in the up / down direction).
The default is to get the rotation for the first player spawned in the Minecraft
world, but this can be run for a different player by using the player_id
argument.
getPlayerPitch(player_id = NULL)getPlayerPitch(player_id = NULL)
player_id |
Integer giving the ID of a player. You can find IDs of all
current players using |
A numeric value between -90 and +90, giving the pitch of the player's viewpoint, with -90 indicating the player is looking straight up and +90 indicating that the player is looking straight down.
getPlayerDirection(), getPlayerRotation(), getPlayerPos()
## Not run: getPlayerPitch() example_playerId <- getPlayerIds()[1] getPlayerPitch(example_playerId) ## End(Not run)## Not run: getPlayerPitch() example_playerId <- getPlayerIds()[1] getPlayerPitch(example_playerId) ## End(Not run)
Get entity position. The default is to get the position of the first player spawned
in the game, but the positions of other players can be gotten using the
player_id argument.
getPlayerPos(player_id = NULL, tile = FALSE)getPlayerPos(player_id = NULL, tile = FALSE)
player_id |
Integer giving the ID of a player. You can find IDs of all
current players using |
tile |
Logical value specifying whether to truncate the output position to an integer (i.e., the location of the tile on which the player is positioned). |
x is east/west with east being the positive direction. y is up/down with up being the positive direction, and z is north/south with south being the positive direction.
A numeric vector of length three giving the position (x, y, and z) of the requested player.
setPlayerPos(), getPlayerRotation(),
getPlayerPitch(), and getPlayerDirection()
## Not run: mc_connect() getPlayerPos() getPlayerPos(tile = TRUE) example_entity <- getPlayerIds()[1] getPlayerPos(example_entity) ## End(Not run)## Not run: mc_connect() getPlayerPos() getPlayerPos(tile = TRUE) example_entity <- getPlayerIds()[1] getPlayerPos(example_entity) ## End(Not run)
Get the current rotation of a player. The default is to get the rotation for
the first player spawned in the Minecraft world, but this can be run for a different
player by using the player_id argument.
getPlayerRotation(player_id = NULL)getPlayerRotation(player_id = NULL)
player_id |
Integer giving the ID of a player. You can find IDs of all
current players using |
A numeric value between 0 and +360 indicating the direction that the player is facing, with 0 being south (positive z), 90 being west (negative x), 180 being north (negative z), 270 being east (positive x), and 360 being back at the south again.
getPlayerDirection(), getPlayerPitch(), getPlayerPos()
## Not run: getPlayerRotation() example_playerId <- getPlayerIds()[1] getPlayerRotation(example_playerId) ## End(Not run)## Not run: getPlayerRotation() example_playerId <- getPlayerIds()[1] getPlayerRotation(example_playerId) ## End(Not run)
Close the current connection to a Minecraft server.
mc_close()mc_close()
None.
## Not run: mc_connect() getPlayerIds() mc_close() ## End(Not run)## Not run: mc_connect() getPlayerIds() mc_close() ## End(Not run)
Create a connection to a Minecraft server
mc_connect( hostname = Sys.getenv("SPIGOT_HOSTNAME", "localhost"), port = Sys.getenv("SPIGOT_PORT", "4711") )mc_connect( hostname = Sys.getenv("SPIGOT_HOSTNAME", "localhost"), port = Sys.getenv("SPIGOT_PORT", "4711") )
hostname |
A character string with the hostname or IP address for the Minecraft Spigot server to which you want to connect. |
port |
An integer giving the port to use for the connection. |
Nothing returned, the connection is cached within the package namespace.
## Not run: mc_connect() getPlayerIds() mc_close() ## End(Not run)## Not run: mc_connect() getPlayerIds() mc_close() ## End(Not run)
Dataset with the name, ID, and style of possible Minecraft items.
data(mc_items)data(mc_items)
Data frame with columns name, id, and style.
https://minecraft-ids.grahamedgecombe.com/
data(mc_items) mc_items[grep("Dirt", mc_items$name),]data(mc_items) mc_items[grep("Dirt", mc_items$name),]
Place a block at position (x,y,z) by type id
setBlock(x, y, z, id, style = 0)setBlock(x, y, z, id, style = 0)
x |
A numeric string with north/south position |
y |
A numeric string with height |
z |
A numeric string with east/west position |
id |
A numeric or character string with the ID of a Minecraft item
(specify either |
style |
A numeric or character string with the style of a Minecraft
item (use this argument only if querying by |
None.
## Not run: mc_connect() h <- getHeight(0, 0) setBlock(0, h, 0, 46) ## End(Not run)## Not run: mc_connect() h <- getHeight(0, 0) setBlock(0, h, 0, 46) ## End(Not run)
Place blocks of a single type (specified by id) in the cuboid
with opposite corners at the positions (x0, y0, z0) and (x1, y1, z1).
setBlocks(x0, y0, z0, x1, y1, z1, id)setBlocks(x0, y0, z0, x1, y1, z1, id)
x0 |
A numeric value giving the starting north / south position of the cuboid. |
y0 |
A numeric value giving the starting height of the cuboid. |
z0 |
A numeric value giving the starting east / west position of the cuboid. |
x1 |
A numeric value giving the north / south position of the opposite corner of the cuboid. |
y1 |
A numeric value giving the ending height of the opposite corner of the cuboid. |
z1 |
A numeric value giving the ending east / west position of the opposite corner of the cuboid. |
id |
A numeric or character string with the ID of a Minecraft item
(specify either |
None.
## Not run: mc_connect() ice <- find_item(name = "Ice") h <- getHeight(0,0) setBlocks(0, h, 0, 1, h + 3, 2, id = ice$id) ## End(Not run)## Not run: mc_connect() ice <- find_item(name = "Ice") h <- getHeight(0,0) setBlocks(0, h, 0, 1, h + 3, 2, id = ice$id) ## End(Not run)
Set a player's direction vector (x,y,z)
setPlayerDirection(x, y, z, player_id = NULL)setPlayerDirection(x, y, z, player_id = NULL)
x |
east/west direction |
y |
up/down direction |
z |
north/south direction |
player_id |
Player or entity ID |
(x, y, z) define a unit vector to which the player will now point.
Only works with RaspberryJuice version 1.11 or later.
getPlayerDirection(), setPlayerRotation(), setPlayerPitch(),
setPlayerPos()
## Not run: mc_connect() getPlayerIds() setPlayerDirection(1, 0, 1) ## End(Not run)## Not run: mc_connect() getPlayerIds() setPlayerDirection(1, 0, 1) ## End(Not run)
Set a player's pitch
setPlayerPitch(angle, player_id = NULL)setPlayerPitch(angle, player_id = NULL)
angle |
Angle of pitch (-90 is straight up and +90 is straight down) |
player_id |
Player or entity ID |
Angles < -90 degrees are treated as -90 degrees (straight up), and angles > 90 degrees are treated as +90 degrees (straight down).
Only works with RaspberryJuice version 1.11 or later.
getPlayerPitch(), setPlayerRotation(), setPlayerDirection(),
setPlayerPos()
## Not run: mc_connect() getPlayerIds() setPlayerPitch(45, 355) ## End(Not run)## Not run: mc_connect() getPlayerIds() setPlayerPitch(45, 355) ## End(Not run)
Move player to position (x,y,z). The default is to move the first player who
was spawned in the Minecraft world, but other players can also be moved using
the player_id argument. If the tile argument is set to TRUE,
the player will be moved to the position specified by truncating the specified
x, y, and z to integers.
setPlayerPos(x, y, z, player_id = NULL, tile = FALSE)setPlayerPos(x, y, z, player_id = NULL, tile = FALSE)
x |
A numeric string with north/south position |
y |
A numeric string with height |
z |
A numeric string with east/west position |
player_id |
Integer giving the ID of a player. You can find IDs of all
current players using |
tile |
Logical value specifying whether to truncate the output position to an integer (i.e., the location of the tile on which the player is positioned). |
None.
## Not run: mc_connect() p <- getPlayerPos() setPlayerPos(0, p + 5, 0) example_entity <- getPlayerIds()[1] getPlayerPos(example_entity) setPlayerPos(0, p, 0, example_entity) getPlayerPos(example_entity) ## End(Not run)## Not run: mc_connect() p <- getPlayerPos() setPlayerPos(0, p + 5, 0) example_entity <- getPlayerIds()[1] getPlayerPos(example_entity) setPlayerPos(0, p, 0, example_entity) getPlayerPos(example_entity) ## End(Not run)
Set a player's rotation
setPlayerRotation(angle, player_id = NULL)setPlayerRotation(angle, player_id = NULL)
angle |
Angle of rotation (0-360) |
player_id |
Player or entity ID |
Only works with RaspberryJuice version 1.11 or later.
getPlayerRotation(), setPlayerPitch(), setPlayerDirection(),
setPlayerPos()
## Not run: mc_connect() getPlayerIds() current <- getPlayerRotation(355) setPlayerRotation(current + 90, 355) ## End(Not run)## Not run: mc_connect() getPlayerIds() current <- getPlayerRotation(355) setPlayerRotation(current + 90, 355) ## End(Not run)
Spawn an entity of a given type at a given position.
spawnEntity(x, y, z, typeid)spawnEntity(x, y, z, typeid)
x |
east/west position (east is positive) |
y |
up/down position (up is positive) |
z |
north/south position (south is positive) |
typeid |
Integer giving the type of entity. See the
output of |
A number giving the spawned entity's ID.
Only works with RaspberryJuice version 1.11 or later.
getEntityTypes(), find_entity()
## Not run: mc_connect() witch_typeid <- find_entity("witch")$id witch_id <- spawnEntity(0, 20, 0, witch_typeid) getPlayerName(witch_id) ## End(Not run)## Not run: mc_connect() witch_typeid <- find_entity("witch")$id witch_id <- spawnEntity(0, 20, 0, witch_typeid) getPlayerName(witch_id) ## End(Not run)