[racket] racket library for minecraft pi edition

From: Sean Kanaley (skanaley at gmail.com)
Date: Mon Jun 10 21:31:26 EDT 2013

I found a short write-up on the API.  It shows

setBlocks(x1, y1, z1, x2, y2, z2, blockType, blockData) - set lots of 
blocks all at the same time by providing 2 sets of co-ordinates (x, y, 
z) and fill the gap between with a blockType

If a similar function is available for get blocks, that would speed up 
your code hugely.  Every single command sent over TCP has overhead 
associated with it, so attempting to read 128^3 times over a network is 
going to take a while.  The main advice I can give is to do as much as 
possible per command.  "Reasonable" lisp code will be 1000000000000x 
times faster than network commands, so whatever you can do "all at once" 
in lisp will save time, especially if you have to wait for round trips, 
e.g. getting a block to determine how to set another block and sending 
them sequentially like that. Ideally, you'd get a bunch of blocks with 
as few commands as possible, then set a bunch with as few as possible, 
or whatever, but mainly try to avoid the network portion as much as 
possible.

As for the data structure, lisp has multi-dimensional arrays:

http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/fun_make-array.html

(make-array '(128 128 128))

with a variety of keywords to control how its created.  That website in 
general has everything on lisp.

For a modern computer, such data is in no way too large (~2 million * 
size of data...say 64 bits = 8 bytes so 16 MB total).  BUT sending 2 
million TCP commands is too many!

On 06/10/2013 09:01 PM, grant centauri wrote:
> hello, i've been exploring the educational possibilities of connecting 
> a Lisp language to the Minecraft Pi Edition.  I started by writing a 
> tutorial using Common Lisp 
> http://www.lincolnix.net/gcentauri/build-tower.html which uses a basic 
> connection API I wrote.  This is really my first attempt at a coding 
> project, and I'm scraping together understanding of things from a 
> variety of sources.
>
> the code i have now establishes a socket connection, and i have 
> written a "send-command" function with its own helper functions to 
> prepare the proper string for the Minecraft API.  There are only a few 
> functions that receive data, so I decided to have each one handle its 
> reading of the input socket on its own. this is very basic, and i'd 
> actually like to write this in a better way, if possible.  i have only 
> included one example function here.  i'd like the writing of this 
> library to serve as a tutorial as well, because it has helped me 
> understand a lot about some basic programming tasks.  here's the code:
>
> https://gist.github.com/anonymous/5745976
>
> my question is mainly about creating a data structure to represent the 
> whole 128x128x128 world, and then sending the "get-block" command to 
> the Minecraft server for every coordinate, and retrieving all of the 
> integers.  is this feasable?
>
> I have been able to write a function to set a column of blocks 
> recursively (see the build-tower tutorial in CL) which performs very 
> quickly, even when sent from another machine on the network.  but the 
> function i wrote (and must have deleted?) to GET a column of block id 
> numbers took a few seconds to complete.  i don't know enough about TCP 
> connections and how to send and receive data properly.  i'm also 
> unsure of the best way to process this function, as what i'd like to 
> end up with is a "world" data structure containing coordinate/block-id 
> pairs.  the idea is that then you could write a function to perhaps 
> turn all the "water" blocks into "air", draining the oceans and 
> rivers.  i don't know if this kind of function even makes sense to try 
> with the way the Minecraft API works.  I'm unsure about the size of 
> the data, and if it is too big to efficiently operate on in this way.
>
> i'm sure i'll have more questions too.  but i'm hoping to document the 
> process of learning about this so other learners can benefit from my 
> struggle.
>
> thanks,
> -grant
>
>
> ____________________
>    Racket Users list:
>    http://lists.racket-lang.org/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130610/7c00e44a/attachment.html>

Posted on the users mailing list.