Building structures in Minecraft is made much easier when you can use drones. A drone is an invisible robot that can move around and place blocks and entities at its location. Here, you start building structures in Minecraft using drones — knowledge that comes in handy when you need to build large structures.
Creating a drone isn’t complicated, but it does require you to use a new coding feature: variables. A variable is a way to name an object. For these instructions, you can follow along with the description of the Drones challenge in the LearnToMod online software.
Open the Drones challenge, and follow these steps:
To be able to give commands to the drone, you need to name it. You name an object, like a drone, by assigning it to a variable. First drag a variable block into the main function.
Always give objects names that make sense to you and that you can easily remember. In this example, create a new variable by clicking on the arrow next to item.
Name it d for drone.
To create a drone, you have to assign a new one to the variable you just made. This is where you find the new Drone block.
This is where you put it in the d assign block.
Now that you have a drone, you can access it by using its name, d, and you can tell it to perform certain actions, such as place blocks or spawn entities.
After you give the new drone a name, you can give it commands. This is where to find the place block code block.
This code block requires you to specify a type of block that the drone will put down, like a brick or diamond block. This is where you can find the brick type.
Here’s the completed code.
If you run this code in Minecraft or the simulator, you see a scene like this.
Your structure appears in the area in which you’re looking, so move to an empty area when you build. You can even go into Creative mode and build in the sky: Double-click the spacebar to hover, and then press the spacebar again to move upward.
Continuing with Step 3 of the Drones challenge, you should add a move block to your mod. You can find the block under the Minecraft category and then Drones, just like the place block code block you found.
If you run the code again, you see the same result. The drone is invisible, so moving it around has no visible effect.
Continue working to complete this challenge by adding three more lines of code. Check out the completed code needed to earn this badge.
Before you run the mod, predict on paper what you will see. Then run the mod in the simulator, and compare your prediction to what you see.
If your prediction was incorrect, go back to the code and trace it either on paper or on the computer. To trace using the computer, disable all blocks of code by right-clicking and choosing Disable Block. Then reenable one block at a time, testing the mod every time you enable one, to see whether you understand what is going on.