Skip to content

JoCodes

Harley O'Connor edited this page Aug 30, 2021 · 13 revisions

Encoding tree shapes as strings

We can devise a simple bytecode "script" for drawing a tree. The only commands we need are to go forward by a specified amount, turn in 1 of 6 directions, fork a path and return to a previously forked path point. Fairly uncomplicated. In my implementation I have decided to use a nybble(4 bits) to hold 16 commands which I've outlined below.

Value Action
0 Do Nothing
1 Go Forward 1
2 Go Forward 2
3 Go Forward 3
4 Go Forward 4
5 Go Forward 5
6 Go Forward 6
7 Go Forward 7
8 Turn Down
9 Turn Up
A Turn North
B Turn South
C Turn West
D Turn East
E Fork
F Return to Fork

Being able to represent 2 commands per byte is pretty tidy. If we happen to have an odd number of commands the last nybble can be 0 without affecting the output. The turn command directions are ordered per the Minecraft standard. When the interpreter runs out of commands or a return to fork command is issued when there are no forks on the stack the script is complete. The code could be represented in hexidecimal but in an attempt to compress the string for convenience we will base64 encode the string, padding it with zeros to make it fit the encoding scheme. By encoding it with base64 we can ensure it's portability as an easily copyable/pastable string. Below is an example script and it's base64 encoding.

Hex Description Base64
4 Go 4 TqKR
E Fork
A Turn North
2 Go 2
9 Turn Up
1 Go 1
F Return to Fork 8tKR
2 Go 2
D Turn East
2 Go 2
9 Turn Up
1 Go 1

The Hexidecimal number 4EA291F2D291 can be base64 encoded to "TqKR8tKR". Each 6 hex digits become 4 base64 characters.

I've taken to calling these base64 encoded models "JoCodes". Because of the way the trees grow the encoded string normally starts with "Jo". These JoCodes are the strings we store in the database to be selected and drawn during worldgen. We only need to make a sizable number of these codes that represent variations in tree structures with differing bounding radii. We need many so the repeating structures are less noticable. We'll also rotate the trees in different directions to increase the look of natural variation.

Producing tree codes

All we should need to do to produce the models is create approximated cylindrical growing chambers with opaque block walls in the game and let the trees grow. Once the tree has depleted the fertility of the root node the model code can be derived from the tree shape and stored in a look up table along with the radius of the grow chamber for later use by world generation. This process can be automated with the help of Computer Craft, and the construction of what we have called growth chambers. The process of how to construct these is detailed on the growth chambers page.

I created a set of 7 growing chambers in creative mode, one for each radius size. Each chamber features a dirt at it's center and a touch screen activated program for automating growth. The computercraft program pulses a grow signal to the entire chamber to force it to grow many times faster than normal. When the program detects that the soil fertility is zero it then reads the tree's JoCode and stores it in a file that is later uploaded to pastebin. Once the code is safely stored away the tree is killed and a new one planted with full fertility and the process repeats. My goal was to have 20 variations for each radius of each tree species for worldgen.


My solution for automating tree growth. These are the chambers used for 1.7 - 1.12

Note that in the pictures above the sides of the chambers are solid blocks so that the only light available to the tree is from directly above.