Using Scratch & Scriptcraft (& more) to teach kids programming in Minecraft

Scriptcraft is a fantastic tool for learning JavaScript using Minecraft and also for creating mods. It is very easy to use yet very powerful, giving access to all the functions of the API of your Minecraft server – CanaryMod or Spigot (CraftBukkit).

Kids who are 10 years old or more can use the book A Beginner’s Guide to Writing Minecraft Plugins in JavaScript (written by Walter Higgins, the creator of Scriptcraft plugin) to learn JavaScript, with or without an adult’s guidance.

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:

Screen Shot 2016-05-16 at 23.46.33connect – 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:

Screen Shot 2016-05-16 at 23.35.22

The configuration for Node-RED is not very complex, but I included some extra variables to be able to manage multiple connections. Node-RED adds the IP of the sender to the commands it transmits thru MQTT to MC and the JavaScript functions that process the message use an array of connections, identified by the IP address.

Screen Shot 2016-05-17 at 00.10.54

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


2 thoughts on “Using Scratch & Scriptcraft (& more) to teach kids programming in Minecraft

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s