Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [SOLVED] Trying to count Trees at World Gen : How to iterate through blocks ?
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 1
Koward

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

By Koward, December 14, 2016 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Koward    3

Koward

Koward    3

  • Creeper Killer
  • Koward
  • Forge Modder
  • 3
  • 141 posts
Posted December 14, 2016

[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.

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2406

Draco18s

Draco18s    2406

  • Reality Controller
  • Draco18s
  • Members
  • 2406
  • 15936 posts
Posted December 14, 2016

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!)

  • Quote

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.

Share this post


Link to post
Share on other sites

trollworkout    4

trollworkout

trollworkout    4

  • Diamond Finder
  • trollworkout
  • Members
  • 4
  • 300 posts
Posted December 15, 2016

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

 

  • Quote

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.

Share this post


Link to post
Share on other sites

Koward    3

Koward

Koward    3

  • Creeper Killer
  • Koward
  • Forge Modder
  • 3
  • 141 posts
Posted December 15, 2016

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.

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2406

Draco18s

Draco18s    2406

  • Reality Controller
  • Draco18s
  • Members
  • 2406
  • 15936 posts
Posted December 15, 2016

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.

  • Quote

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.

Share this post


Link to post
Share on other sites

Koward    3

Koward

Koward    3

  • Creeper Killer
  • Koward
  • Forge Modder
  • 3
  • 141 posts
Posted December 15, 2016

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.

  • Quote

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • S-Spirit
      [1.16.4] Why recipe result calculated on server side?

      By S-Spirit · Posted 7 minutes ago

      For now it is impossible. My crating system is tricki a little. I didn't found way to represents necessary logic by JSON without losing my wishes about customisation. So I don't use recipes consept at all. But I hope at future resolve this problem and use it. In any case, I think your notification about cheating it a great point! So I will implement combinations calculation at client, but then send results to server for approve and apply into slots. Thanks.
    • diesieben07
      why is 3 in the middle of 7

      By diesieben07 · Posted 52 minutes ago

      1.12 is no longer supported on this forum. Please update to a modern version of Minecraft to receive support.
    • forgotendeath09
      why is 3 in the middle of 7

      By forgotendeath09 · Posted 1 hour ago

      when you load up forge 1.12.2 the top is displayed as 0/7, once it gets to 3/7 the bar below is in the middle; this is very wrong please consider changing this it drives me crazy every time i launch a modded world.
    • F0RZera
      have an error when trying to connect to LAN server with mods

      By F0RZera · Posted 1 hour ago

      Ok thanks
    • DeNub
      Cannot create a modded forge server for 1.16.4

      By DeNub · Posted 1 hour ago

      Its working all well now. Thank you for the support and being patient with me.
  • Topics

    • S-Spirit
      4
      [1.16.4] Why recipe result calculated on server side?

      By S-Spirit
      Started 23 hours ago

    • forgotendeath09
      1
      why is 3 in the middle of 7

      By forgotendeath09
      Started 1 hour ago

    • F0RZera
      10
      have an error when trying to connect to LAN server with mods

      By F0RZera
      Started 6 hours ago

    • DeNub
      27
      Cannot create a modded forge server for 1.16.4

      By DeNub
      Started 12 hours ago

    • BobbyLikesCake
      13
      1.16.4 Modded not loading singleplayer worlds

      By BobbyLikesCake
      Started 5 hours ago

  • Who's Online (See full list)

    • Umpaz
    • Kreepydude
    • SeraphicKing
    • loordgek
    • OrneryHandle
    • EnergizedAB
    • diesieben07
    • mightymoy
    • S-Spirit
    • LeoBeliik
    • ChampionAsh5357
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [SOLVED] Trying to count Trees at World Gen : How to iterate through blocks ?
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community