# Get all Blocks from a tree when player hits a log

## Recommended Posts

Hey there - i wanna get an array of all blocks belonging to a tree when the player hits/destroys one of the logs of it. I searched for a way but didn't find anything like that in vanilla classes - how can i do that?

##### Share on other sites

there is no way to do that implemented in vanilla.

you will need to write your own algorithm for it

##### Share on other sites

A well okay Im pasting it here once ive done it.

##### Share on other sites

I'd suggest looking at how mods like Treecapitator or Tinker's Construct (i.e. the Lumber Axe) achieve this.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

##### Share on other sites

I wrote an algorithm once. It was recursive and likely not the best, but it worked.

Kill current block and every log above this one.

Then recurse for every adjacent log next to this one, if the block above is air, also recurse for its neighbors.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

DO NOT PM ME WITH PROBLEMS. No help will be given.

##### Share on other sites

I wrote an algorithm once. It was recursive and likely not the best, but it worked.

Kill current block and every log above this one.

Then recurse for every adjacent log next to this one, if the block above is air, also recurse for its neighbors.

Yea - i thought of that one too, but i need everything of the tree - logs&leaf's. I thought of making a List of all the trees with their logposition and then when a log is destroyed i loop through the list and look for the destroyed log. If it is is in one of the generated trees im gonna loop through the rest of the BlockPos-Array from this tree. All i need is a possibility to get every Block that is generated for a tree from the WorldGenTrees class. Is that possible? Or do i will have to use some class transformers?

##### Share on other sites

I've written a recursive method to do this myself. One tip if you plan to write your own. make sure you are not going from log to leaf & back to log again.

If you don't in a biome like Roofed forest you'll get 1/2 the forest otherwise very OP but very lag inducing.

I'd share mine but i'm not 100% happy with it yet. It still leaves some hanging logs in the big oak trees that have random logs that are not on the up, down,north , south, east, west sides but instead are diagonals or not connected at all.

Its been low priority on my todo list so far.

##### Share on other sites

Extend my method such that you have a log version (recurses itself and calls the leaf version) and a leaf version (recurses only itself).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

DO NOT PM ME WITH PROBLEMS. No help will be given.

##### Share on other sites

My way was to do it recursive with the logs and every time you check for a log destroy each leaf in radius x

##### Share on other sites

Yes, how i would destroy the leaves is clear, but i wanna get a list of blocks for each tree when they are generated - isn't this the best way? Cuz when i do with a fixed radius, i will destroy other trees and when i do it with neighbor blocks it will go on forever until there are no leaf blocks anymore

##### Share on other sites

Not really, no.

My algorithm is the closest I came. It does very well even in the roofed forest, though it can occasionally trim the tops of a neighboring tree.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

DO NOT PM ME WITH PROBLEMS. No help will be given.

##### Share on other sites

Also, tree's usually have their own box radius, in that even within a roofed forest you have a limit imposed, so really it's about scoring weight per block within that radius that depends on the distance between logs. You could do recursive but i suspect that's also a bit of an overkill given the nature of Tree Generation... the first pass in a loop could just audit the 16x16 area using the player as a centre point. Put this into two arrays (leaves and logs). Then using the SQRT functions you can simply infer likelihood that the block belongs to the trunk of an adjacent tree by its type and distance from root (which you'd define as being the source of the hit or objectMouseOver position).

I've done this already and although its not "accurate" the illusion stays intact and that's all that really matters, if the player believes it to be so, it is honest to goodness true

For the leaves you can create a random noise true/false statement for all blocks say 8x8 away from your harvest zone...that way it will look less like you took out a clean square of blocks but more so that some linger. If they are orphan leaf blocks the server will clean that up for you aswell.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

### Announcements

×

• #### Activity

×
• Create New...