Solved Instant Tree Breaking

Discussion in 'Plugin Development' started by Amgis, Feb 25, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Amgis

    I'd like to develop a plugin that allows players to instantly break a tree (leaves and all) if they destroy the root log of it, as seen in this video at (1:48):



    Generally speaking, how would I achieve this? Does bukkit offer a 'tree object' or would I have to manually iterate through each adjacent log/leaf of the tree to determine its volume?

    Thanks.
     
  2. Offline

    GaaTavares

    Check if the broken block is Material.LOG, then use a while loop adding y=+1, also checking if the block is log, then use breakNaturally();
     
  3. Offline

    Amgis

    GaaTavares What about logs that don't grow in a perfect column from the root, i.e. super trees?
     
  4. Offline

    MCForger

    Amgis
    Or consider that whatever block the break could be the middle of the tree and make a cuboid based around that point then iterate through each block checking for log, leaf, etc and break naturally.
     
  5. Offline

    NathanWolf

    You can do this recursively, like so:

    https://github.com/elBukkit/MagicPl...ne/bukkit/plugins/magic/spells/DropSpell.java

    I use this code both for a "chop" spell (instant tree/leaf chopping) and a "mine" spell (instant ore vein mining).

    Keep in mind you'll need a pretty high recursion depth to chop a whole jungle tree in one go, but it ought to be ok.

    Works great for me. You may need to add the 8 diagonal blocks as well to catch some of the screwier acacia trees, though (I haven't fully tested that).
     
    Amgis likes this.
  6. Offline

    Amgis

    NathanWolf

    Sounds great! Thanks for the code too, that really helps. I didn't consider using recursion to solve this problem.
     
    NathanWolf likes this.
  7. Offline

    NathanWolf

    No problem! Yeah, it's a perfect problem for recursion- though keep in mind it may go *crazy* in a roofed forest.... I haven't really dealt with that myself, it just takes a huge chunk out of the forest :) .. depending on the max recursion depth you use.

    You could probably also volume-limit it, sort of a combination of recursion and what other posters have suggested.
     
Thread Status:
Not open for further replies.

Share This Page