Posted July 1, 20169 yr 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?
July 1, 20169 yr 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.
July 1, 20169 yr Author 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.
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.