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:

  • Install a Minecraft server
  • Install a Minecraft client (the Minecraft game)
  • Connect to the Minecraft server from R
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:

  • clearSpace - clear (ie destroy) a bunch of space around the player
  • mc_whoami - figure out your player id by typing “who am i” in the chat
  • whereami - figure out your position
  • getPlayerCompass - get your orientation as a compass direction with 4, 8, or 16 points (for example north, north-west, or north-northwest)

Drawing stuff

  • cube - Make a solid or hollow cube
  • sphere - Make a solid or hollow sphere with the player at the center
  • drawLine - Draw a line
  • mc_plot - Render a scatterplot within Minecraft
  • mc_clearplot - Clear the space where you put that scatterplot
  • write_text - Write text in Minecraft

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

  • setBlocksStyle - like setBlocks but accepting a block style argument
  • setBlocksMix - like setBlocks but filling a cuboid with randomly selected block types

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:

  • elsafy - Water turns to ice when your player steps on it
  • de_elsafy - Turn off the elsafy) power
  • ice_towers - Wherever you hit (by right-clicking while holding an iron sword), a tower of ice is built

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.


CC BY