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