The miner package provides a simple interface to the Minecraft world. Use R functions to connect with a Minecraft server and control the world within.
The craft includes additional functions that illustrate and extend the use of miner, including many of the examples in our ebook R Programming with Minecraft.
Install the miner and craft packages from R universe:
install.packages(c("miner", "craft"), repos=c("https://kbroman.r-universe.dev", "https://cloud.r-project.org"))Alternatively, use the remotes package to install them from GitHub. First install remotes:
Then use remotes:install_github() to install miner and craft:
library(remotes)
install_github("kbroman/miner", build_vignettes=TRUE)
install_github("kbroman/craft", build_vignettes=TRUE)Note: this should automatically install a number of
dependent packages, including Rmaze, igraph, and imager. To install imager you
may need to install Xquartz on
Mac or libx11-dev or similar on Linux.
To use the packages you will need to:
Note that if your Minecraft server is running locally (on the same
computer as you’re running R), you might not have to specify the IP, or
you might try '127.0.0.1' or 'localhost'. One
of these might work:
Full installation instructions are provided in the online book, R programming with Minecraft.
The miner package includes a bunch of basic commands for interacting with your Minecraft world. The craft package combines these commands to do bigger things, and also provides alternative versions of the basic functions, for programming convenience.
There are a number of functions for building stuff:
buildBuilding
- build a large square building around the playerbuildDoor
- build a door in the direction the player is facingbuildFence
- build a square fence around the playerbuildRlogo
- render the R logo out of blocks, as in Chapter
9 of our ebookbuildStairs
- build a set of stairs (going down or up) in the direction the player
is facingmc_maze
- build a maze, as in Chapter
10 of our ebookmc_mazer
- run a chat bot to build a maze from the Minecraft chatWe’ve added a number of useful tools:
clearSpace
- clear (ie destroy) a bunch of space around the
playermc_whoami
- figure out your player id by typing “who am i” in the chatwhereami
- figure out your positiongetPlayerCompass
- get your orientation as a compass direction with 4, 8, or 16 points
(for example north, north-west, or north-northwest)cube
- Make a solid or hollow cubesphere
- Make a solid or hollow sphere with the player at the centerdrawLine
- Draw a linemc_plot
- Render a scatterplot within Minecraftmc_clearplot
- Clear the space where you put that scatterplotwrite_text
- Write text in Minecraftnum_guess
- Play the number guessing game in Chapter
7 of our ebookmc_race
- Which player will move the farthest in a 10 second race? Based on code
from Chapter
11 of our ebooksetBlocks functionsThere are a couple of alternative versions of miner::setBlocks
taking a block style argument, or a random mixture of blocks
setBlocksStyle
- like setBlocks but accepting a block style argumentsetBlocksMix
- like setBlocks but filling a cuboid with randomly
selected block typesThe following are like the corresponding function without the
V, but accepting position (or positions) as a vector (or
vectors) rather than three separate coordinates. For example, you could
write setBlockV(pos, 46) rather than
setBlock(pos[1], pos[2], pos[3], 46).
Give your player Elsa powers in Minecraft:
elsafy
- Water turns to ice when your player steps on itde_elsafy
- Turn off the elsafy)
powerice_towers
- Wherever you hit (by right-clicking while holding an iron sword), a
tower of ice is builtThe following are for making your player walk randomly around the Minecraft world, as in Chapter 11 of our ebook:
Finally, you can run R code directly from Minecraft by typing it in the chat. But enable this feature with great care.
Many of the ideas and techniques in the miner and craft packages were adapted from or inspired by “Learn to program with Minecraft” by Craig Richardson (No Starch Press, 2016), “Adventures in Minecraft” by Martin O’Hanlon and David Whale (Wiley, 2014), and some work by Alexander Pruss.