## Exporting 3D Plots to Minecraft using Maple 15

Maple 15

In part due to a large number of requests on MaplePrimes, the command ?plottools,getdata was added to Maple 15. This new command gives programmers a better way to access the internals of plots and do things with the data they contain.

I was trying to come up with something really fun to do with this command, and another recent obsession came to mind: the game Minecraft.  Minecraft is nice, since like Maple it is written in Java and runs on lots of platforms!  For the uninitiated, Minecraft is a a sort of mostly unstructured "sandbox" game. The player starts in alone in a procedurally generated landscape consisting of blocks. They player can collect blocks with their hands or with tools and they use them to build new things. The wide array of things that people create in Minecraft is staggering.

So, I thought I would write some commands to export 3D plots in Maple to block structures in Minecraft.

That code is available in this worksheet (updated!):Minecraft-Exports.mw. It requires Maple 15 or better (an enterprising Maple programmer could make it work with earlier versions with a little bit of work, however).

There were two cases to handle to make the exporter. The easy case is 3D Grids. These are the most basic of 3D surfaces:

```(**) plottools:-getdata( plot3d( -2*x^2-2*y^2,x=-1..1,y=-1..1 ) );
["grid", [

-31
-1. .. 1., -1. .. 1., -4.00000000000000178 .. -0.277333911991761963 10   ],

[ 25 by 25 Matrix ]

]
```

Here each entry in the Matrix returned by getdata is the height of the surface above the point in a regular grid in the x-y plane. This is quite easy to render as cubes. In this case you just put a tall enough stack of cubes at each point in order to make a surface without gaps. My Minecraft plotter renders the paraboloid like this:

To use my Maple code you supply a filename:

`(**) MinecraftPlotter("Paraboloid", P1, block="Glass", zscale=.66);`

and Maple saves a five called "Parabloid.schematic" to the current directory. This file gives a complete description of a Minecraft structure. In order to actually put this structure into a game world, you can use a editor like MCEdit. And here is what that paraboloid looks like as glass in Minecraft:

Of course, the most interesting 3D plots are not representable as simple grids, and are instead rendered as meshes:

```(**) plottools:-getdata( plot3d([1,x,y], x=0..2*Pi, y=0..2*Pi, coords=toroidal(10) ) );
["mesh", [-21.6395341365836025 .. 21.6395341365836025,

-21.6395341365836025 .. 21.6395341365836025,

-8.45847962781308382 .. 8.45847962781307672],

[ 25 by 25 by 3 Array ]

]
```

Here getdata returns a 3-dimensional Array. It easiest to think of it as a Matrix where the entries are points in 3-space. The grid structure of the Matrix describes the interconnectedness of the points. The mesh is rendered by drawing rectangular patches between adjacent points. i.e. for the mesh M, a patch is drawn with corners M[1,1], M[1,2], M[2,2], and M[2,1], etc. This is slightly harder to render as cubes. The method I used in the included worksheet is an inefficient but effective brute force inspection of each mesh patch. It works nicely on the torus:

And in Minecraft wooden planks it looks like:

For something slightly weirder, here is a Klein bottle too:

Exported to Minecraft as cobblestones.  From below:

To give a better idea of what these look like in the game (and to see "inside" the Klein bottle), I made this short video:

And, finally, here is a silly (and slightly too long) video of me setting the torus on fire in a game of Minecraft:

Update:  Here is a zip file with all the Minecraft schematic files generated by the attached worksheet:MapleSchematics.zip

﻿