Skip to content

Improvements to TreeGrower - #957

Open
Borito185 wants to merge 1 commit into
CivMC:mainfrom
Borito185:fix/big-tree-growth
Open

Improvements to TreeGrower#957
Borito185 wants to merge 1 commit into
CivMC:mainfrom
Borito185:fix/big-tree-growth

Conversation

@Borito185

@Borito185 Borito185 commented Jul 24, 2026

Copy link
Copy Markdown

Changes

Restoration of 2x2 saplings on failed big growth attempt

Previously there was a TODO to restore the saplings after a failed big growth attempt. I created a reusable function setSaplings to set saplings to a given material. This is used both to set them to air prior to growth and to restore the original saplings afterward on fail. This will prevent saplings from disappearing.

Added tree growth reattempt

Saw an old bug report (#198) that mentioned this fix. And thought I might as well implement this. It will try to grow the tree up to 10, before giving up. This ensures trees grow more consistently. 10 is somewhat arbitrary here. But from previous experience, most trees grow in that many attempts. Feel free to let me know whether to change or even keep this.

Updated .generateTree to non-deprecated version

world.generateTree(Location, TreeType) is deprecated since 1.21.6. I have replaced it with world.generateTree(Location, Random, TreeType). This now requires a Random object. I have scoped this to the Grower object to prevent allocations & ensure randomness.

Slightly improved performance by preventing array allocation

The previous implementation looped over a small array of relative blocks to check for both adjacentSaplingCheck and findNWSapling. I have changed this to a for loop instead. Although it's a bit harder to read, it should prevent a couple of array allocations, which improves performance.

Fixed bug preventing 2x2 growth when not initiated from NW sapling

The previous implementation correctly verified whether this sapling is part of a 2x2 setup using canGrowBig, but then checks the wrong direction for findNWSapling. Making only the NW sapling able to grow a big tree. More on this at the end.

Testing Steps

  1. Temporarily change the grow time for some of the big trees to '1m' to save you some time
  2. Place 2x2 saplings in an open space
  3. Place a block right on top of one of the saplings to prevent them from growing

The old version would delete 3 saplings. In the new version, they will remain. In addition, after removing the block and right-clicking any sapling with a stick to force an update, the tree will grow.

Usage of LLM's

I used ChatGPT 5.5 to verify code and improve documentation a bit, but not to generate code.

Important Question

Imagine a 2x2 setup of saplings like:
1 2
3 4
The old version only grew a tree iff the sapling at 1 (northwest) is fully grown. But the way it was written makes me think this was not intended, and any of 1, 2, 3, or 4 should have been able to cause the tree to grow.

What is the intended behavior? The new version assumes any of 1, 2, 3, or 4 may initiate an attempt to grow the tree.

@Borito185
Borito185 force-pushed the fix/big-tree-growth branch from 3f37fe7 to 036d2e0 Compare July 24, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant