Tree cutting

Discussion in 'Spigot Plugin Development' started by Diamond_X, Jan 11, 2019.

  1. So I was thinking of making myself a plugin that would upon destroying a wood log, destroy the entire tree including leaves connected to it.

    Disable it from dropping saplings and plant a sapling on the location where the tree was.

    The items that would normally be harvested by the tree (Amount of logs, odd chance of an apple or two) drop at the player's feet.

    This would only happen if the wood logs are NOT placed down by a player.

    Can anyone point me in the way of accomplishing this? As I have 0 idea how to get started on this.
  2. You would have to loop through all the blocks above/below the broken block and check if its a log. If it is,set it to air and drop a log item. Same with leaves, but this can get more complicated when dealing with irregular trees. Setting the leaves to air will not drop a sapling or an apple afaik.
  3. For the leaf problem ^, you can either instantly call the decay event on them, or just create your own chances for an apple / sapling. Differentiating an irregular tree from a player-placed oak log near by seems like a much harder problem though.
  4. You see the issue with it though? Imagine if someone made an entire mansion out of wooden logs and wants to remove 1 log, everything would vanish
  5. Then only make it destroy everything when they break it whilst shifting, or when they do a certain thing.
  6. I imagine calling the event for every single leaf block wouldn't be practical. Besides, just calling the event won't do anything by itself. OP would be better off managing the chances himself.
  7. Strahan


    Personally, I'd just download and decompile an existing tree cutting plugin and look at how they do it for inspiration.
  8. One could look at mcMMO Tree Fellar :)
  9. Thing is, I'm very new to coding and I'm always afraid if looking at other code that I'll have the tendency to copy it? Not like copy paste but do it like they do and I feel like that would be a bad way of learning.
  10. Strahan


    The idea is to learn how and why they do it, not just to lift code. Once you understand that, you should be able to implement it in your own project without referring back to the original.
    #10 Strahan, Jan 13, 2019 at 3:31 AM
    Last edited: Jan 13, 2019 at 3:37 AM
    • Agree Agree x 1
    • Useful Useful x 1
  11. Using existing code as a reference is essential, reinventing the wheel is just a waste of time.

    If you dont want to copy directly, look at it and try to understand it, then recreate it without using it as a reference. Compare results, then try to improve on it.
    • Agree Agree x 1
    • Useful Useful x 1
  12. Assuming there's an easy way to access this information (I haven't tried getting it in spigot before), you could just search for logs that have their corresponding leaf attached to them, and from there check the "persistent" tag on the leaf blocks. player-placed leaves have the persistent tag set to "true," while naturally spawning ones are tagged with "false."
    If all the leaves in the mass are persistent (or if the majority, depending on how aggressive / lenient you want it to be), delete the blocks.
  13. I'm doing something almost exactly the same! Also new to spigot.
    I have searched for "bukkit select whole tree", which really set me up in the right direction, and made me find amazing examples.
    If you want to do it more for yourself, I suggest searching for "bukkit select adjacent blocks".

    To point you in the right direction, check the block the player has mined, search and select adjacent logs for this block, you will need recursion for this. After you have selected all the logs, I ran over all the selected logs, for each log I searched in a 5x6x5 range for the leaves.

    Freel free to pm me if you have any questions!
    • Useful Useful x 1

Share This Page