User Tools

Site Tools


labs:minecraft

This is an old revision of the document!


Parallelization in Minecraft

In this lab you will program robots to play Minecraft and optimize their operation by using multiple threads to control multiple robots. You are provided a modded version of Minecraft which allows you to connect to a running game world to obtain a robot called a “turtle”. When you close the connection, the robot disappears. You may also open multiple connections to obtain multiple robots which can then work in parallel.

The setup is based on the mod ComputerCraft and as such provides the same API. A small example demonstrating some of the turtles' functions can be found here.

Even though most tasks can be solved using only one turtle, parallelization is the key to do them quickly. This introduces a few synchronization issues that you need to deal with: how to divide the task among the turtles and how to prevent turtles from crashing into each other.

Important: To finish setting up your machine, you need to download this script and execute it. You can then select the “forge” profile in the Minecraft launcher to start the modded version of Minecraft. We will provide you with Minecraft accounts for this lab.

Exercise 0

Your first task is to build a simple 3×3 grid of blocks at height y = 90 centered right above the spawning location. The goal here is to get accustomed to the API. Keep in mind that turtles need to collect some blocks before being able to place any!

Exercise 1

Now that you have understood the basics, it is time to add some parallelization! Build tower hollow of height 10 with a 5×5 area and a few holes in the side (see whiteboard). The tower should be made of cobblestone only (block name “minecraft:cobblestone”).

Try to complete this task as quickly as possible by using as many turtles as you can handle!

To tell the mod to detect the tower, download this config file and place it in your /home/ubuntu/.minecraft/config folder. Again, the tower should start at y = 90 and be centered around the spawning location.

Exercise 2

The room will be divided into two teams, each of which will be provided a server. The goal is to collaboratively build a cobblestone pyramid larger than that of the other team!

Hints

  • When creating a world, you may want to turn cheats on to allow you to switch to spectator mode using the command “/gamemode 3” (press 'T' to open a text box in game).
  • A random seed for a world without much obstruction near the spawn point is “qwer”.
  • Singleplayer worlds pause when the window loses focus unless you select “Open to LAN” in the menu.
  • In Minecraft the y coordinate is used for the height axis: near 0 you will encounter indestructible bedrock blocks, while ocean level is 64.
  • Turtles have an inventory of 16 slots labeled 1 through 16, all starting out empty. A slot can hold up to 64 of any single block type. When a block is mined it is placed in the first slot of its type (if there is any) or into the first empty slot (if there is not). Use the select(int slot) function to choose which slot is used for actions, e.g., for placing blocks from.
  • All function calls are blocking, i.e., they only return once the operation is complete or has failed.
  • If a turtle function call fails (i.e., returns false), you can use the getFailureReason() method to obtain a string containing the reason. The reason will also be output to stderr.
  • A turtle can interact with the 3 blocks in front of, above and below them. To access other blocks it needs to move or turn.
  • We extended the Turtle API by 2 additional methods to allow a turtle to determine its position and orientation in the world: getLocation() and getFacing().

Installing from scratch

If you want to run the mod at home, you need to install Minecraft Forge for Minecraft 1.8.9 over an existing Minecraft Installation to add the “forge” profile to the launcher. Then copy the mod into the ~/.minecraft/mods folder. After launching the first time with the mod installed, a configuration file with default values for the measured goal will appear in ~/.minecraft/config.

You may also be interested in the original ComputerCraft mod in which turtles are programmed directly in the game in Lua.

labs/minecraft.1463779087.txt.gz · Last modified: 2020/08/31 21:03 (external edit)