Blockly, Raspberry Jam Mod and WebSockets

420 views
Skip to first unread message

Alexander Pruss

unread,
Sep 23, 2015, 11:48:10 PM9/23/15
to Adventures in Minecraft Forum
I've extended Google's Blockly graphical programming environment to control a turtle in Minecraft. You will need Raspberry Jam Mod 0.50 running, and then just go to robotblocks.appspot.com . You can run the graphical code, or you can have it generate python code (the latter is untested).

Technical notes (which will matter if you want to do this with Juice or PI instead of Jam):
Blockly uses javascript, and javascript can't communicate over TCP/IP sockets, which the MCPI interface uses. However, javascript can communicate over WebSockets. I extended Raspberry Jam to communicate over WebSockets via port 14711 (no other changes in the API).

If you want to use this with Juice or PI, you can try using a WebSocket at 14711 to port 4711 proxy like websockify, or one could extend Juice to handle WebSockets.


chris thompson

unread,
Sep 24, 2015, 8:38:07 AM9/24/15
to Adventures in Minecraft Forum
This is very cool! If you don't mind I have a few questions:

How does one set the IP address of the server the blockly generated code connects to?  Does it default to localhost
Is the source for the blockly editor with support for Minecraft blocks available? 
Will you be adding additional blocks to support the full Jam API? How difficult is it to create new blocks?

Thanks again for sharing such a wonderful tool!

Alexander Pruss

unread,
Sep 24, 2015, 9:28:04 AM9/24/15
to Adventures in Minecraft Forum
1. Currently only localhost is supported. I could see a benefit of an option of using a different IP address, but right now I don't know how best to implement that, because I don't know much about javascript and css. (I guess it could be a little advanced options box on the web page, and then the the javascript code could read the contents of that box. If you know how to implement it while keeping the UI simple and clean, go ahead.)

2. Source: https://github.com/arpruss/blockly-minecraft . Look at generators/javascript/source/*, generators/python/minecraft.js and blocks/minecraft.js, and minecraft/* . If you make changes, run build.py. (Note: build.py pulls stuff in generators/javascript/source/* and creates generators/minecraft.js)

3. If you just want to generate python code, it's very easy to add new blocks. But if you want to produce javascript code that can run in the browser, it is very difficult to add any blocks that receive data (e.g., player.getPos() or world.getBlock()). It is easy to add code for blocks that don't receive data (e.g., player.setPos(), world.spawnEntity()).

The technical reason for this is that the WebSockets API is non-blocking, so it requires a callback. But it is difficult to implement non-blocking code in Blockly while keeping a simple linear structure. If you know enough about Blockly/javascript to solve this problem, tell me. Thus, I am currently limited to supporting only those commands that don't require receiving data. (I do use callbacks to initialize the Minecraft connection, and at that time I fetch the player position and angle, which I then use to initialize the turtle. But that's one-time magic, rather than something tied to a paticular block.)

In any case, I suspect that once one has done everything that the Blockly interface currently supports, it's time to move on to a text-based language. :-)

Arthur Gomes

unread,
Mar 31, 2016, 5:00:23 PM3/31/16
to Adventures in Minecraft Forum
It´s a nice work you have done with Blockly. 

I have been studying Google Blockly docs for a few days and a friend of mine sent me your work, and i´m now trying to do something new for myself for educational purposes. 


I would like to ask you, if i wanted to implement on the "Minecraft" category a new block, a new Turtle command for blockly, how could i do that? 


From what i can gather, i would have first to understand how the turtle comands works, from the code in http://robotblocks.appspot.com/static/minecraft/index.html i could figure out that the javascript code is not that hard, you have alrealdy covered the most complex parts. 

What i can´t figure out is how i´m going to get a new function into the javascript and then implemeting the new "Block" through the XML. I do now how to manipulate the Google Blocks standards blocks like functions and others, but i have no knowledge yet how to implement custom ones. 

I have some knowledge with WebSockets too, but not that much. 

So, if could enlighten me in that matter it would be very, very helpfull. I´m aiming to use blockly and minecraft to teach programming at school, because of course they all love minecraft... 


Alexander Pruss

unread,
Apr 1, 2016, 1:26:48 PM4/1/16
to Adventures in Minecraft Forum
You'll need to edit:

generators/javascript/source/minecraft-in.js
blocks/minecraft.js
minecraft/index.html

I suggest just copying and pasting another block's code for your initial experiment.

Then run the build.py script, and see if it works.

Arthur Gomes

unread,
Apr 14, 2016, 10:39:41 PM4/14/16
to Adventures in Minecraft Forum
thank you very much for the advice


Reply all
Reply to author
Forward
0 new messages