Jump to content

[SOLVED] Trying to count Trees at World Gen : How to iterate through blocks ?


Recommended Posts

Posted

[sOLVED]

Here's the final version of the event : http://hastebin.com/xomoqahepo.java

It replaces the bottom block of each trees by a glowstone block (helped during debug to see which trees were counted).

 

----

 

Hello,

 

I'd like to iterate over all trees when they are generated and do various things like changing blocks around.

To start with something smaller, I'd like to simply find them and count them. I consider the bottom of a tree as a (hopefully unique in World gen) pattern with a block of dirt beneath a log.

 

I wrote this event : http://hastebin.com/buwomusoku.java

Unfortunately not all trees are counted. It seems only a part of the chunk is actually tagged.

I was told the decoration was done not per chunk but for intersections between 4 chunks.

I tried to simply add an offset of 8, but well the problem was just swapped between chunks.

I just don't see how to iterate properly through blocks after biome generation.

 

I'm a bit lost and I would appreciate a lot any support.

Posted

A few things I know:

Dirt under a log also detects villager farms.

Trees can also sit on top of gravel or in thin air (hooray lakes!)

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.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

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

Posted

this is no easy task because you may get false positives say for ex someone builds 2 log and puts 1 leaves block nearby cause it looks cool.

 

trees are generally minimum 3 logs high . however modded trees or jungle bushes may be only 1-2 block high but those would be bushes  not trees :D

 

all trees have leaves near all around the log. but sometimes they may be completely removed by players but then again that's a dead tree so it doesn't really count anymore :D x2

 

 

most trees spawn above  a certain height say 64 blocks and higher

 

 

best tree like thing you can check is 1 leaves block and 3 adjacent log blocks down like an inverted L . it may still produce false positives but is the best approximation. this would work on tall trees, wide trees, short trees because they will all have an inverted L shape with 1 leaves and 3 logs in them at the top of the tree. most houses would not have that pattern. once you find such a shape then just move over say 4 blocks and start counting again to make sure you don't count the same tree once more. 4 blocks (2x2) is the widest vanilla trees get so from any side over 1 (L shape) + 3 blocks over will never have another tree trunk nearby

 

esentially you wanna do this by scanning the environment for leaves block. if leaves block found then see if say N side S E W has a log. if say N has then check N -1 and N -2  to see thos are logs. If true then you got a tree. mark the leaf location as a tree then skip over 4 units and do it again. keep doing this every random tick

 

 

the OTHER way is to tap into worldgen or  chunkgen or sapling custom world gen events by subscribing to events of that kind and figure out what's being spawned that's a tree and keep a track of all the trees you got in some txt file in your save then you would keep updating it. since this system would be based on gen then it will always run when something multiblock is being spawned in the world so is perpetually running checking things that are spawned for tree purpose.

 

you can also save this data in an NBT tag in the TileEntity of the tree counter

 

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Posted

A few things I know:

Dirt under a log also detects villager farms.

Trees can also sit on top of gravel or in thin air (hooray lakes!)

I think the event I use is triggered before village generation. If it's not then checking for two vertical logs should do the trick.

About gravel trees... Damn. I could add gravel too along with dirt. Thin air trees on the other hand will be discarded, not a big deal.

 

this is no easy task because you may get false positives say for ex someone builds 2 log and puts 1 leaves block nearby cause it looks cool.

I use this at world gen, so nobody has built anything yet.

 

the OTHER way is to tap into worldgen or  chunkgen or sapling custom world gen events by subscribing to events of that kind and figure out what's being spawned that's a tree and keep a track of all the trees you got in some txt file in your save then you would keep updating it. since this system would be based on gen then it will always run when something multiblock is being spawned in the world so is perpetually running checking things that are spawned for tree purpose.

 

There's no such event, that's why I have to iterate through the blocks this way. The events are triggered before or after everything, not individual features.

 

EDIT : I think I found one of my problems. Basically, chunk.getBlockState() is NOT just a world.getBlockState() with chunk coordinates. When you use the chunk version, you only ever get terrain stuff like grass block, dirt, gravel, sand. No features at all (leaves, tall grass, flowers, logs..). I used the world version and I got what I wanted. Now just a few tweaks and I'll post here my progress.

EDIT2 : It does not get all trees, only some. Seems just 1/4 of chunk is tagged.

http://hastebin.com/buwomusoku.java

EDIT3 : Solved (Chunk coord were wrongs). I'll update OP with the latest version.

Posted

Also, for reference, when I was doing something similar, even when delaying the tree detection via Custom Ore Gen's delayed population (that is, a chunk would only get its ore generated after every adjacent chunk had generated, and I was waiting for COG's "I'm done" event) it would still miss trees.  Not very many, but some.

 

Waiting for the end of the vanilla generation phase will miss a lot of trees, due to the cross-chunk-boundary nature of their generation.

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.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

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

Posted

I compensate the cross-chunk nature by offsetting x and z by 8. I'm not iterating over the chunk anymore, I actually iterate over the intersection that should generated at the time of the event (so 4 quarters of 4 different chunks).

I have not found any missing tree yet, but I'll keep an eye.

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.

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.