Skip to content

Instantly share code, notes, and snippets.

@Earthcomputer
Last active October 2, 2021 17:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Earthcomputer/41addf80c12d001dfa4391c3a0d03be8 to your computer and use it in GitHub Desktop.
Save Earthcomputer/41addf80c12d001dfa4391c3a0d03be8 to your computer and use it in GitHub Desktop.
A description of the big oak tree growth algorithm in Minecraft

Big Oak Tree Growth Algorithm

Outline

A big oak tree is made up of a main trunk and multiple branches. A "branch" always contains leaves, but may not always contain logs.

Parameters

  • heightLimit: The actual height of the tree, including leaf blocks at the top (between 5 and 16)
  • trunkHeight: The height of the trunk
  • leafDistanceLimit: The distance from a log that leaves can generate, set to 4 for sapling growth, though appears to be set to 5 for natural growth for some reason
  • heightAttenuation: The ratio between the heightLimit to the trunkHeight, equal to 1/phi (0.618)
  • branchCount: The number of branches per y-layer
  • branchSlope: The slope/gradient of a branch, equal to 0.381

Steps

  1. Check if the tree is in a valid spawn location
  2. Prepare for growth: choose branch positions
  3. Generate leaves
  4. Generate trunk
  5. Generate logs in branches

Check if the tree is in a valid spawn location

  1. The spawn location is invalid if the block standing on is not dirt, grass or farmland.
  2. heightLimit is set to a random value between 5 and 16.
  3. The spawn location is invalid while there is an obstruction between the sapling and the sapling plus the heightLimit.
  4. The heightLimit is decreased until the spawn location is valid. The growth algorithm does not give up just because there was an obstruction at the start.
  5. If the heightLimit is now less than 6, the spawn location is invalid.

Prepare for growth: choose branch positions

A branch is defined by two coordinates, the coordinates of the end of the branch, and the coordinates in the trunk at the start of the branch.

  1. trunkHeight is set to heightLimit * heightAttenuation, rounded down.
  2. branchCount is set to 2 if the heightLimit is 11 or more, and 1 otherwise.
  3. A branch is added at the top of the trunk. Because its end is inside the trunk no extra logs are generated, but extra leaves are.
  4. For each y-layer from heightLimit - leafDistanceLimit to heightLimit * 0.3 rounded up, generate branchCount branches which end at that y-level.
  5. The maximum horizontal distance from the trunk to the end of each branch is such that all branches will fit entirely inside a sphere of radius heightLimit * 0.664 centered at height heightLimit / 2.
  6. The actual distance from the trunk to the end of the branch is randomized so that the minimum length is 0.247 times the maximum length.
  7. The branch connects to the trunk at a lower y-position, respecting the branchSlope.
  8. The branch will not generate if there is an obstruction in the straight line between its connection to the trunk and its end.

Generate leaves

Leaves are generated in a sphere of radius leafDistanceLimit around the end of each branch.

Generate trunk

trunkHeight + 1 log blocks are generated for the trunk.

Generate logs in branches

  1. A branch will only generate logs if the place it connects to the tree is more than 0.2 of the way up to heightLimit.
  2. A branch generates logs in a straight line from its connection to the trunk to its end.
  3. If the branch is further from the trunk in the x-direction, there will be one log per x-coordinate. Otherwise there will be one log per z-coordinate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment