2 Installation and configuration

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:

# install.packages("remotes")
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.

The bigger task is to install a Minecraft server that is using the RaspberryJuice plugin. You can use Spigot to set up your own server, even locally on your machine. The installation process doesn’t take too long, but it helps to have some command line experience.

2.1 Mac OS X

The first installation step on a Mac is of the Java SE (standard edition) development kit (JSK). The latest version should probably work. We got JDK version 26 You’ll get a .dmg installer file named something like jdk-26_macos-aarch64_bin.dmg or jdk-26_macos-x64_bin.dmg. Double-click to run and go through the installation screens.

Second, open a terminal (in Applications/Utilities). Verify that java was installed correctly by typing

java -version
javac -version

They both should show 26.0.1 (or whatever version number you installed).

The rest of the installation is just like for Linux (below). Though maybe you won’t have wget available and will need to download the files from a web browser and move them into place.

The ~/minecraft directory that you create will take up about 600 MB.

2.2 Windows

We’re focusing here on Windows 11. We presume that you’ve already installed R and likely RStudio Desktop. You will also need to install RTools; pick the version that corresponds to the version of R that you installed.

Install the Java SE Development Kit. And of course install Minecraft JAva edition. (You’ll need to pay for a copy of Minecraft.)

Also install Git for Windows, which we want primarily for “Git Bash”, which we will use for the rest of the installation. You will need to choose an editor, which could be notepad, but if you’re goihng to be doing more editing of software files, you might want to install Notepad++ or Atom.

Open Git Bash, and let’s first check that we have access to Java:

java -version
javac -version

The both should show the same version. For us, we got java 26.0.1.

Now type the following, to make and enter a directory that will contain your minecraft server:

mkdir ~/minecraft
cd ~/minecraft

Use curl to download the code:

curl -OL https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar

Now let’s compile the minecraft code and do an initial start of the server.

java -jar BuildTools.jar --rev 26.1.2
java -jar -Xms1024M -Xmx4G spigot-26.1.2.jar nogui

It will stop and ask you to accept the EULA, which you can do by editing the file eula.txt to have the line eula=true, or you can do it at the command line:

echo "eula=true" > eula.txt

Now you might want to edit the server settings in server.properties. In particular, you might change gamemode from survival to creative and change force-gamemode from false to true, so players entering the game are forced to be in the default creative gamemode.

Now we create a plugins directory, download the Raspberry Juice plugin, and move it into plugins.

mkdir plugins
curl -OL https://github.com/zhuowei/RaspberryJuice/raw/master/jars/raspberryjuice-1.12.1.jar
cp raspberryjuice-1.12.1.jar plugins/

To start the server, run that last line of java again, or you can create a simple start.sh script:

#!/bin/sh
java -jar -Xms1024M -Xmx4G spigot-26.1.2.jar nogui

Note that -Xms sets the initial memory usage and -Xmx sets the maximum available memory.

Then make it an executable, and run it:

chmod +x start.sh
./start.sh

2.3 Linux

These instructions describe how to set up a Minecraft Server on Linux with the Raspberry Juice plugin. Once installed, you can connect to the server with the Microsoft game and with R via the miner package. If you are new to Minecraft, you will first have to make a one time purchase of a Minecraft license.

2.3.1 Installation

First, make sure you have installed Java. Then make a directory for Minecraft and change into it.

mkdir ~/minecraft
cd ~/minecraft

Download Buildtools.jar from Spigot, a popular site for Minecraft server downloads. You will use the Buildtools program to complete the install. Run the jar file. This step will fail to start the server but will successfully create the plugin directory and the EULA.

wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
java -jar BuildTools.jar --rev 26.1.2
java -jar -Xms1024M -Xmx2048M spigot-26.1.2.jar nogui

Edit the file eula.txt so that the line eula=false is instead eula=true

Note that -Xms sets the initial memory usage and -Xmx sets the maximum available memory.

Start up the server again. This will take a while (because it’s building the world), but not as long as the initial compiling.

java -jar -Xms1024M -Xmx2048M spigot-26.1.2.jar nogui

Your Minecraft server should now be running. Open your Minecraft game on your desktop and connect to your server IP in multiplayer mode. (Choose “Direct Connection” and type the IP address of the computer that’s running the Minecraft server, which you can determine by ifconfig -a or ip a; for the latter you may need to run sudo apt install iproute2. If you’re playing Minecraft on the same computer where the server is running, you likely can just type “localhost” for the IP address.) You can make a player an operator by typing op <playername> into the server prompt. When you are finished playing type stop in the server prompt to stop the server.

2.3.2 Connect with miner

You can use the RaspberryJuice plugin to connect to your Minecraft Server via the miner package. Download the plugin by visiting its page and clicking the “Download Now” button in the upper-right. Move this .jar file to the plugins directory.

wget https://github.com/zhuowei/RaspberryJuice/raw/master/jars/raspberryjuice-1.12.jar
mv raspberryjuice-1.12.jar ~/minecraft/plugins

Connect to your server from R using mc_connect("<server-ip>"). If you’re running R on the same computer where the Minecraft server is running, you can use “localhost” for the server IP, or just leave it off as this is the default, so try mc_connect().

library(miner)
mc_connect("<server-ip>")

Now test the connection by posting something to chat.

chatPost("Hello Minecraft!")

2.3.3 Configuration

The ~/minecraft/server.properties file contains a list of configuration parameters for your Minecraft server. You will probably want to set gamemode=1 and force-gamemode=true. If you want to create a superflat world also set level-type=FLAT.

gamemode=1
force-gamemode=true
level-type=FLAT

If you want to run Minecraft in the background, then you can create a simple start.sh script:

#!/bin/sh
java -Xms512M -Xmx1G -XX:+UseConcMarkSweepGC -jar spigot-26.1.2.jar

Note that -Xms sets the initial memory usage and -Xmx sets the maximum available memory.

Then make it an executable, and run it with nohup:

chmod +x start.sh
nohup ./start.sh

If you need to use a different port, use the -p option. (See other options.)

java -jar -Xms1024M -Xmx2048M spigot-26.1.2.jar -p25566 nogui

If you’re having a hard time connecting, verify that your ports are open. The standard port for Minecraft is 25565. The standard port for the miner package is 4711.

telnet <server-ip> 25565
telnet <server-ip> 4711

2.4 Docker

2.4.1 What is Docker?

Docker is a program that runs on runs on Linux, OSX or Windows to set up a tiny operating system on your compute, like having a computer in your computer. The advantage of this is that it can save a lot of bother troubleshooting problem relating to the unique configuration details of your computer. With Docker we can set up an isolated operating system on your computer that is already equipped up with a Minecraft server and the various dependencies described above, so we don’t have to worry to about installing and configuring each item. Using a Docker container can take a lot of the bother out of a complicated setup like this.

The main disadvantage of Docker is that it will re-create the Minecraft world each time you run it, so anything you create in one instance will be lost in the next.

2.4.2 The miner Dockerfile

The miner package includes a Dockerfile, which is a plain text file that gives Docker the recipe for setting up an appropriate container.

This file specifies the following steps that are needed to set up the required environment and run a Spigot Minecraft Server with the RaspberryJuice plug-in:

  • Creates a directory called “minecraft” for the Minecraft server
  • Downloads all required files to build a Spigot server (https://www.spigotmc.org) and saves them in the “minecraft” direction
  • Builds the Spigot server
  • Symlink for the built Spigot server?
  • Accepts the End User License Agreement for Minecraft (“eula”) (see here to see what you are agreeing to with this step)
  • Downloads the RaspberryJuice plugin (which we’re using for API access) to a subdirectory of the “minecraft” directory called “plugins”
  • Install the RaspberryJuice plugin
  • Open up the ports required to access the game (port 25565) and the API (4711)
  • Start the Minecraft server, [explain options we’re using for that]

This Dockerfile is included in the miner package. To find it on your computer once you’ve installed the miner package, you can run:

system.file("Dockerfile", package = "miner")

This call will return the file pathname on your computer for any the file named “Dockerfile” that come with the miner package.

If you’d like to take a look at the Dockerfile, from R you can run:

edit(system.file("Dockerfile", package = "miner"))

This will open the “Dockerfile” file in the miner package in a text editor.

2.4.3 Building a Docker image

The Dockerfile is a very small plain text file and only gives the recipe for setting up the needed environment and starting a server. To get all the required pieces and be ready to run a container, you need to build a Docker image from this Dockerfile. Once you have installed Docker on your computer (which you can do from the Docker website), you open a command line (e.g., the Terminal application on MacOS, on Windows use the Docker Quickstart Terminal), move into the directory with the Dockerfile (using cd to change directory), and then build a Docker image based on this Dockerfile by running the following call from a command line:

docker build -t minecraft .

The docker build call is the basic call to build a Docker image from a Dockerfile. The option -t minecraft tells Docker to give the image the tag “minecraft”. By doing this, you can later refer to this image as “minecraft”. The . at the end of the call tells Docker to build this image based on the file called “Dockerfile” in the current working direction (.).

Once you’ve built the image, you can check to see that it’s in the Docker images on your system by running the following call from a command line:

docker images

You should see something like this:

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
minecraft           latest              2c9e2f2c16d3        3 days ago          1.03 GB
java                latest              d23bdf5b1b1b        4 months ago        643 MB

This tells you which Docker images you have on your system, when they were created, how large they are, and the Image ID. If you’d ever like to remove a Docker image from your system, you can do that with the command line call docker rmi and the image ID. For example, if you ever wanted to remove the “minecraft” image listed above that you built with the call to docker build, you could run:

docker rmi 2c9e2f2c16d3

2.4.4 Running a Docker container from the image

Once you have built a Docker image, you can run a container from it. To do that for our Minecraft server, at the command line you should run:

docker run -ti --rm -p 4711:4711 -p 25565:25565 minecraft

The docker run call is the basic call to run a Docker container from a Docker image. The minecraft at the end tells Docker which image to run. The --rm option cleans up everything from this container after you’re done running it. The -ti argument runs the call in the interactive terminal mode. The arguments -p 4711:4711 -p 25565:25565 allow the needed access to the ports for the game itself (port 25565) and the API (4711). After you press Enter you’ll see messages about server starting up in your console.

Now you can open your regular desktop Minecraft application, select ‘Multiplayer’, then ‘Direct Connection’, then enter the IP address the computer that is running the Docker container, which you can determine by ifconfig -a or ip a; for the latter you may need to run sudo apt install iproute2. If you’re playing Minecraft on the same computer where the server is running, you likely can just type “localhost” for the IP address.

After the Minecraft server has started, the Docker terminal will have a prompt like this > where you can enter commands to Minecraft. If you enter op <player_name> and press Enter in the Docker terminal, then you can grant yourself operator status, and you can run game commands such as changing the gamemode (e.g. survival/creative), time, weather, etc. in the Minecraft dekstop app, as usual. If you don’t run op <player_name> in the Docker terminal, you will get messages that you don’t have permission if you try to run commands in the desktop app.

2.4.5 Docker on Mac OS X

You can also install Docker and create a Minecraft server within a Docker container on a Mac.

Install Docker CE (community edition) for Mac. You will need to sign up for a free account in order to download Docker.

The download will give a Docker.dmg file which you double-click and then drag Docker.app to your Applications folder.

Run the Docker application. It will ask for you Mac administrator password and will then ask you to log in with your docker account and password.

We found that we needed to change the preferences to give the docker container more memory. (See this stackoverflow question.) Click on the whale in the menu bar, select “preferences” and “advanced” and then drag the memory slider to 4.0 GB.

The rest follows the Docker instructions (below), though I needed to use sudo with the docker commands.

Open a terminal and change to the miner package directory, which contains the Dockerfile. For me, this is in ~/Rlibs.

R -e "system.file('Dockerfile', package = 'miner')"
cd ~/Rlibs/miner

Then build the docker container:

sudo docker build -t minecraft .

Run the docker container:

sudo docker run -ti --rm -p 4711:4711 -p 25565:25565 minecraft

To connect to the minecraft server from your minecraft game client, or with miner::mc_connect() within R, you need to have an IP address for the computer running the docker instance. If you’re connecting to the minecraft server from the same computer, you can use "localhost" in place of an IP address. Within R, you can just leave off the IP, typing miner::mc_connect(), as "localhost" will be the default.

2.4.6 Docker on Windows

You can also install Docker and create a Minecraft server within a Docker container on Windows.

Install Docker Desktop for Windows. You will need to sign up for a free account in order to download Docker.

The rest follows the Docker instructions, run at the prompt within Git Bash.

First we need to find the Dockerfile that is distributed with the miner package. We can use system.file() to find it’s location, and file.copy() to copy it somewhere else. You can use getwd() to see where your R working directory is, which will contain the copy of the file.

dockerfile <- system.file("Dockerfile", package = "miner")
file.copy(dockerfile, ".")
getwd()

Now open Git Bash and change into the directory that contains the Dockerfile. For us that was ~/OneDrive/Documents where ~ stands for our base user directory.

cd ~/OneDrive/Documents

Build the docker container. (You’ll need to have Docker Desktop running.) This will take 5-10 minutes.

docker build -t minecraft .

Run the docker container:

docker run -ti --rm -p 4711:4711 -p 25565:25565 minecraft

To connect to the minecraft server from your minecraft game client, or with miner::mc_connect() within R, you need to have an IP address for the computer running the docker instance. Locally, you can use "localhost" in place of an IP address. Within R, you can then just leave off the IP, typing miner::mc_connect(), as "localhost" will be the default.

To connect to the server from Minecraft, select “Multiplayer” and “Direct Connection” and type “localhost” for “Server Address”.

To connect to the Minecraft server from a separate computer on the same local network, type ipconfig within Git Bash to determine the computer’s IP address.

2.5 Raspberry Pi

A Raspberry Pi is an small (credit card sized), inexpensive computer that runs a scaled-back version of Linux. There are a few different ways to interact with Minecraft and R using a Raspberry Pi. First, you can use the built-in Minecraft Pi application, which is a free, scaled-back version of Minecraft that includes the API that the miner package package interacts with. It is perhaps simplest to run Minecraft Pi on the Raspberry Pi but to connect from R that is running on a separate computer (whether it be linux, Mac, or Windows). But a second option is to install R on the Raspberry Pi itself; there are a couple of small headaches. Third, you can install a Minecraft spigot server, with the raspberryjuice plugin, on the Raspberry Pi, as we have done above. The Raspberry Pi can then act as a stand-alone Minecraft server. We will discuss each of these options, as well as how to set up a Raspberry Pi, below.

2.5.1 Setting up a Raspberry Pi

We’re working with a Raspberry Pi 3, with built-in Wifi. And we used a 32 GB micro-SD card.

  • Download the Full Raspbian; installed onto micro-SD card with Etcher.
  • Used an attached display, keyboard, and mouse for the initial set up
  • In the initial set-up screen, configure time zone, locale, and keyboard. Also, change the password and connect to wifi.
  • Run sudo raspi-config and
    • Change the host name
    • Enable ssh (under “Interfaces”)
    • If you’re going to use it as a stand-alone Minecraft server not attached to a screen, you might want to change the boot configuration, to boot to a shell rather than the desktop.
    • Expand the file system to use the full SD card (under “Advanced”)

2.5.2 Minecraft Pi

If you run Minecraft Pi on your Raspberry Pi, and if you either know the IP address for your Pi, or you have set a hostname, you should be able to connect to Minecraft from another computer on the same network and on which you are running R:

library(miner)
mc_connect("raspi.local")
chatPost("Hello, Minecraft!")

2.5.3 Installing R on a Raspberry Pi

Install some libraries

sudo apt update
sudo apt install libget2-dev libcurl4-gnutls-dev libssl-dev libboost-atomic-dev

Install R

sudo apt install r-base r-base-core r-base-dev

Run R; I got version 3.3.3 which is old but good enough.

Create an ~/.Rprofile file (use the editor nano), with one line:

options(repos=“https://cran.rstudio.com”)

Now install miner and craft 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:

install.packages("remotes")
library(remotes)
install_github("kbroman/miner", build_vignettes=TRUE)
install_github("kbroman/craft", build_vignettes=TRUE)

This should automatically install a number of dependent packages, including Rmaze, igraph, and imager. To install imager you may need to install libx11-dev. From the command line:

sudo apt update
sudo apt install libx11-dev

Now fire up Minecraft Pi, load the miner package within R, and connect to minecraft. Test that it’s working by posting to the minecraft chat.

library(miner)
mc_connect()
chatPost(“Hello, Minecraft!”)

2.5.3.1 Minecraft Server on a Raspberry Pi

Follow the instructions above, which come from http://lemire.me/blog/2016/04/02/setting-up-a-robust-minecraft-server-on-a-raspberry-pi/.

mkdir ~/minecraft
cd ~/minecraft
wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
java -Xms1024M -jar BuildTools.jar -rev 26.1.2

wget https://github.com/zhuowei/RaspberryJuice/raw/master/jars/raspberryjuice-1.12.jar
mv raspberryjuice-1.12.jar ~/minecraft/plugins