For younger ones it may be better to start by using a visual tool like Scratch to understand how to use the drone, described as “an (invisible) object you create every time you execute any of the building or movement functions”.
Scriptcraft doesn’t include an http server to listen for commands from an external source, but there is an external module, created also by W Higgins, that can be added to support MQTT protocol – scriptcraft-extras-mqtt. An MQTT broker is also needed, so I used Mosquitto, which is open-source and available for Windows, Mac and Linux.
In order to send commands from Scratch as MQTT messages, I used the solution described by Dave Locke on Visual programming and integration with Scratch, Node-Red and MQTT: Scratch 2.0 offline with experimental extensions (based on http communication) which allow it to talk to external world + Node-RED, a tool based on Node.js which is used to “wire” all the above components together.
To enable the use of a Scriptcraft drone, I created a Scratch extension with a few new blocks:
connect – tells the MC server which player will be followed by the drone (the drone is usually created at a player’s location)
drone – controls drone movement
box, box0 – for creating cuboids solid or empty
blockType and blockData are report blocks that return the block at the current drone’s positions
The code for building a pyramid looks like this:
Each user can connect to his MC player on the server and has its own drone to control. He can see the result of drone actions in the MC client window. On users’ computers the only needed components are MC client, Scratch offline and the extension file.
For reading the values of a block type and data Scratch polls the server 30 times per second, while Scriptcraft posts the values (using http) after each build command. Values are also kept in an array, serving correct data based on the IP of the client.
Currently I’m struggling with the out of order execution of drone commands even if they are buffered on the MC server before receiving the “build” command. The same problems occur when reading data. To avoid this I use delays in Scratch programmes but I hope to find a smarter and more reliable solution.
An obvious and quick improvement will be to create blocks that allow choosing the material for a building command from a list, using names instead of numbers for block types, making it easier to use.
Later edit: see this post for a simpler and more stable configuration (with all needed files): Using Scratch with Minecraft & Scriptcraft – step by step instructions