Custom Tree Generation with NMS

Discussion in 'Spigot Plugin Development' started by TheRedMelonYT, Oct 9, 2019.

  1. Part of a custom terrain generation plugin I'm making is custom trees of different blocks. While I could do this by placing the blocks block populators, I was wondering if there was a better way to implement this like how world.generateTree does it, perhaps by extending some classes related to net.minecraft.server.WorldGenerator. I've had a look at the bukkit source code but can't figure out how I could do this. How could I implement this?
  2. In MNS tree generators are just classes that get called to place their blocks into the world, not so different from Bukkit's block populators.
  3. drives_a_ford

    Junior Mod

    Have you tried using World#generateTree with the BlockChangeDelegate argument?
    You'd obviously need to create your own implementation, but that wouldn't be too difficult. It looks like you'd need to define the changes in BlockChangeDelegate#setBlockData.
    You can look here to see how CraftBukkit handles the method.
  4. Right, I was thinking there might be something more to it, just changing the blocks from block populators felt a bit like a cheat

    How is this any different from changing the blocks directly? It looks like all that method did was set the block data again and call notifyAndUpdatePhysics. I assume you're suggesting I pass generateTree a BlockChangeDelegate then change the block data to the custom tree block data, does this offer any advantage over setting the blocks without the generateTree method?
  5. drives_a_ford

    Junior Mod

    How would you know which list to change exactly without this method? You can't just get all connected blocks that are leaves (or logs), because if the tree was grown near another (naturally generated) tree, you'd also change blocks that shouldn't be changed.
    The advantage of this is that you don't have to actually worry what the tree looks like or how to generate it exactly. You just need to change the logs to something and the leaves to something.
  6. Oh right, I am going to do custom shapes and stuff too so I'd set the blocks directly without using Bukkit's method.
  7. drives_a_ford

    Junior Mod

    If you're setting them yourself, I don't really understand what you wanted the NMS WorldGenerator to take care of.