User Tools

Site Tools


labs:minecraft

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 turtles in 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

Download the example Eclipse project, and run it on a singleplayer world. If you can't find the turtle moving about, try printing its location using System.out or using a flat world (seed: “qwer”). If you have trouble understanding what's going on, be sure to check out the Hints section below!

Exercise 1

Your first real task is to build a simple 3x1x3 grid (i.e., horizontal, height 1) 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!

Note that once turtles start placing blocks in the correct spots, the progress of the building will be displayed in in-game chat.

Exercise 2

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! On world seed “qwer” 50 seconds is a good time. The assistants' record is 47.2 seconds.

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.

Hint: Use getItemDetail() to find out what materials you picked up!

Exercise 3

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

  • Don't worry, if you've never played Minecraft before. There is a lot of content to the game, but for this lab you just need to know that the world is made of a 3D grid of blocks, which can be mined (“dug”) to obtain them as “item” in one's inventory, allowing one to place them somewhere else.
  • 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”.
  • If something goes wrong, you can easily get a clean world by selecting an existing one from the menu and choosing “Re-Create”.
  • In Minecraft the y coordinate is used for the height axis: near 0 you will encounter indestructible bedrock blocks, while ocean level is 64.
  • By pressing F3 in Minecraft an overlay showing various information can be displayed. This is particularly useful for finding a certain coordinate.
  • 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().
  • Singleplayer worlds pause when the window loses focus unless you select “Open to LAN” in the menu.
labs/minecraft.txt · Last modified: 2020/08/31 21:03 (external edit)