Jump to content

Better leaf block pruning


Bossman

Recommended Posts

(Pun intended)

I had a very tall pine tree grow in a valley next to a spire and I wasn't in the mood to prune the top by hand, so I chopped it down. Imagine my surprise when not all of the tree came down:

2023-06-23_01-49-56.thumb.png.869161083f26b3f4a3916d24a703bf06.png

Those are leaf blocks, holding the treetop onto the rock face horizontally. I think there needs to be some better rules about what makes leaf and branch blocks pop.

My proposal is that leaf and leafy branch blocks are considered 'supported' and don't pop if:

  • There is any solid block beneath them.
  • There is an adjacent log block of the same tree type in any direction.
  • There is an adjacent leafy branch block of the same tree type that is 'supported' in any direction (will require recursion over branch blocks to find a base).

Essentially, leaf blocks should not support other leaf blocks or branches. If there are two trees close enough that their leaves are touching, cutting down one tree will remove its top, leaving the other's. This may mean adjusting tree generation so that there are more branch blocks for structure but will leave shrubs intact.

Edited by Bossman
  • Like 1
Link to comment
Share on other sites

Thing is... these suggestions of yours? They're already in the game. That's how trees have always worked.

The problem is that a leaf block needs to realize it is no longer supported in order to make the decision to despawn. And you cannot just have the game update every block all the time. The game would be so busy doing that it wouldn't do anything else, like for example letting you play. There are just too many blocks in the world.

Most of the time, leaf blocks get updated when adjacent blocks get updated. But there's also the dedicated treechop subroutine, which is tasked with bringing the whole tree down when you chop just a single block at the bottom. This routine must guess what the tree actually is. You as a human may see a tree, but the game only sees tables of coordinates with block IDs assigned to them. So there is a heuristic in place that recursively looks for adjacent log and leaf blocks. But it can't be just that, because if it was, you could chop an entire forest down at once so long as any single chain of leaf blocks keeps connecting tree after tree after tree. No, that heuristic must also be able to guess when a tree stops. When a connected block is no longer part of the same tree. And that is actually the most complicated and difficult part of that entire piece of code.

For the longest time, Vintage Story's tree chopping heuristic was very... optimistic, shall we say, about the size of trees. It pretty much always sheared neighboring trees of their leaves whenever you chopped down a tree, which was not just an eyesore but also risked wasting seeds of valuable trees because leaf blocks destroyed from treechopping drop far fewer seeds (and sticks) than leaf blocks broken directly by the player. In 1.18, this heuristic was adjusted to be more conservative, in an attempt to stop this from happening.

But in return, we now have the rare instance where the heuristic is too conservative, and leaves some leaf blocks untouched that it should really have brought down. Those blocks do not receive any updates (because the heuristic didn't identify them), and thus do not realize that they are no longer supported, and thus they do not decide to despawn. To be clear, this happens only very rarely. Maybe one out of fifty trees, in my nonscientific anecdotal gut feeling guess. But it can happen. It's a tradeoff.

 

Edited by Streetwind
Link to comment
Share on other sites

10 hours ago, Streetwind said:

Thing is... these suggestions of yours? They're already in the game. That's how trees have always worked.

Except my picture shows it clearly isn't. Non-branch leaf blocks are supporting the rest of treetop. I was able to remove all of those blocks by hand without removing the two leaf blocks that were next to the cliff. Every time I popped a block, the chunk update should have removed the rest, but it didn't. Because the current rules allow stone and soil to support leaves from any direction instead of just below, and non-branch blocks are allowed to support both kinds of leaf block.

Edited by Bossman
Link to comment
Share on other sites

  • 2 weeks later...
On 6/24/2023 at 3:03 AM, Streetwind said:

Thing is... these suggestions of yours? They're already in the game. That's how trees have always worked.

The problem is that a leaf block needs to realize it is no longer supported in order to make the decision to despawn. And you cannot just have the game update every block all the time. The game would be so busy doing that it wouldn't do anything else, like for example letting you play. There are just too many blocks in the world.

Most of the time, leaf blocks get updated when adjacent blocks get updated. But there's also the dedicated treechop subroutine, which is tasked with bringing the whole tree down when you chop just a single block at the bottom. This routine must guess what the tree actually is. You as a human may see a tree, but the game only sees tables of coordinates with block IDs assigned to them. So there is a heuristic in place that recursively looks for adjacent log and leaf blocks. But it can't be just that, because if it was, you could chop an entire forest down at once so long as any single chain of leaf blocks keeps connecting tree after tree after tree. No, that heuristic must also be able to guess when a tree stops. When a connected block is no longer part of the same tree. And that is actually the most complicated and difficult part of that entire piece of code.

For the longest time, Vintage Story's tree chopping heuristic was very... optimistic, shall we say, about the size of trees. It pretty much always sheared neighboring trees of their leaves whenever you chopped down a tree, which was not just an eyesore but also risked wasting seeds of valuable trees because leaf blocks destroyed from treechopping drop far fewer seeds (and sticks) than leaf blocks broken directly by the player. In 1.18, this heuristic was adjusted to be more conservative, in an attempt to stop this from happening.

But in return, we now have the rare instance where the heuristic is too conservative, and leaves some leaf blocks untouched that it should really have brought down. Those blocks do not receive any updates (because the heuristic didn't identify them), and thus do not realize that they are no longer supported, and thus they do not decide to despawn. To be clear, this happens only very rarely. Maybe one out of fifty trees, in my nonscientific anecdotal gut feeling guess. But it can happen. It's a tradeoff.

 

Streetwind makes some good points, I'm not sure you can actually fix this with the current system as it'll always have small errors no matter how much find tuning you do. 

Not really sure what the solution is for this one, we may have to live with this sort of error if the system is not entirely changed. 

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.