Extra functions to control Minecraft

R-CMD-check r-universe badge zenodo DOI

Introduction craft logo

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.

Installation

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:

install.packages("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:

library(miner)
mc_connect('52.1.2.3') ## use your minecraft server IP address here

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:

mc_connect()
mc_connect('127.0.0.1')
mc_connect('localhost')

Full installation instructions are provided in the online book, R programming with Minecraft.

Overview of craft commands

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.

Building stuff

There are a number of functions for building stuff:

Useful tools

We’ve added a number of useful tools:

Drawing stuff

Games

Alternate setBlocks functions

There are a couple of alternative versions of miner::setBlocks taking a block style argument, or a random mixture of blocks

Vector-based functions

The 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).

Being Elsa from Frozen

Give your player Elsa powers in Minecraft:

Random walk

The following are for making your player walk randomly around the Minecraft world, as in Chapter 11 of our ebook:

Dangerous functions

Finally, you can run R code directly from Minecraft by typing it in the chat. But enable this feature with great care.

Acknowledgments and references

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.