2 Installation and configuration

To use the miner package, you’ll need 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 kid (JSK). The latest version should probably work. We got JDK version 11. You’ll get a .dmg installer file named something like jdk-11.0.2_osx-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 11.0.2 (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.1.1 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), the 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 docker instance. [But I wasn’t able to get docker-machine to work. And I tried docker ps to get a list of containers, and docker inspect <containerID> | grep IPAddress but the IP address I found didn’t work either.] What ultimately worked for me was just to use "localhost" in place of an IP address. Within R, you can just leave off the IP, typing miner::mc_connect(), and "localhost" will be the default.

One problem I had: docker seemed to re-create the world each time, so anything I created in one instance would be lost in the next.

2.2 Windows

Installing stuff in Windows.

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 Install

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 1.13.2
java -jar -Xms1024M -Xmx2048M spigot-1.13.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-1.13.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. 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.11.jar
mv raspberryjuice-1.11.jar ~/minecraft/plugins

Connect to your server from R using mc_connect("<server-ip>"). Test your connection by retrieving your player’s location.

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

2.3.3 Configure

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-1.13.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-1.13.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.

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 Connect’, then enter the IP number for your Docker container. You can find your Docker container IP number by opening another terminal and running docker-machine IP. 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> 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> 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.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”)

Want to install the devtools package, but it has a bunch of dependencies and I hit snags on fs and later.

To get fs installed, I followed this discussion.

  • grab the github repository for the package

git clone git://github.com/r-lib/fs

  • Use nano to edit the file fs/src/Makevars. Right after the line ifeq ($UNAME), Linux), added the following line:

PKG_LIBS += -pthread

  • The install that package by typing

R CMD INSTALL fs

To install the later app, I followed this discussion.

  • Download the package

git clone git://github.com/r-lab/later

  • Edit the later/src/Makevars file using the nano editor. Add -lboost_atomic to the end of the line with PKG_LIBS.

Now you should be able to install devtools. And then use that to install the miner and craft packages. Within R, type:

install.packages("devtools")
library(devtools)
install_github("ropenscilabs/miner")
install_github("ropenscilabs/craft")

It’s possible that you’ll need to install some additional packages first, but hopefully this will happen automatically:

install.packages(c("stringr", "ggplot2", "shiny", "igraph"))
devtools::install_github("Vessy/RMaze")

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.4 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 1.13.2

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