Jump to content

Firing event when a sapling grows


Strontium

Recommended Posts

Hi. I am trying to use an event to run some code whenever a Sapling grows into a Tree (using SaplingGrowTreeEvent). The event DOES work, however, I noticed it fires every time a tree generates in the world, not just growing from a sapling. Is there any way to check if the tree is from a sapling, and not worldgen?

Link to comment
Share on other sites

Well, event (or rather method used to grow trees) is indeed called by both block and world-gen. Code is quite big so can't really analize it fast, but it might be worth checking if event.pos contains a sapling block (world-gen might generate trees without it, but I doubt it, at least it doesn't seem like so).

 

So if block check will not work (just an idea), you might have to look at quite unorthodox methods.

This is again just an idea (idk if there are better ways);

 

Seems like DecorateBiomeEvent has EventType.TREE, so one might think you could use Pre sub-event to collect event.pos into per-chunk data (save in WorldSavedData?) and then inside SaplingGrowTreeEvent check agains saved position to check if sapling was generated by decorator.

 

This is quite a long shot but might work (I don't know anything about decorator tho). :)

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Thank you! I didn't realize the event fired before the tree was actually placed... so thats why the sapling is there, I guess.

 

If anyone in the future ends up here looking for a solution:

I just added

        if (!(event.getWorld().getBlockState(event.getPos()).getBlock() instanceof BlockSapling))
            return;

to the beginning of my function so that the rest of the code only runs if there is a sapling.

Link to comment
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.
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.