Are BlockPopulator busted, or am I insane?

Discussion in 'Plugin Development' started by phrstbrn, Jun 30, 2013.

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

    phrstbrn

    Simple one file plugin to remove all the ores from chunk generation. This *should* work, yet it doesn't. Chunks loaded on world gen seem to have all their ores remove, but as I explore, I'm finding all the chunks contain their ores. Not what I want.

    Yes, I have deleted my world folders before testing, they are brand new chunks.

    plugin.yml
    Code:
    name: NoOres
    main: com.gamingmesh.noores.NoOres
    version: 1.0
    load: startup
    Code:java
    1. package com.gamingmesh.noores;
    2.  
    3. import java.util.EnumSet;
    4. import java.util.Random;
    5.  
    6. import org.bukkit.Chunk;
    7. import org.bukkit.Material;
    8. import org.bukkit.World;
    9. import org.bukkit.block.Block;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.world.WorldInitEvent;
    13. import org.bukkit.generator.BlockPopulator;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15.  
    16. public class NoOres extends JavaPlugin implements Listener {
    17. @Override
    18. public void onEnable() {
    19. getServer().getPluginManager().registerEvents(this, this);
    20. }
    21.  
    22. @EventHandler
    23. public void onWorldInit (WorldInitEvent event) {
    24. for (BlockPopulator pop : event.getWorld().getPopulators()) {
    25. if (pop instanceof NoOrePopulator)
    26. return;
    27. }
    28.  
    29. World world = event.getWorld();
    30. if (world.getEnvironment() == World.Environment.NORMAL) {
    31. world.getPopulators().add(new NoOrePopulator());
    32. }
    33. }
    34.  
    35. public class NoOrePopulator extends BlockPopulator {
    36. private EnumSet<Material> ores = EnumSet.of(
    37. Material.COAL_ORE,
    38. Material.IRON_ORE,
    39. Material.LAPIS_ORE,
    40. Material.GOLD_ORE,
    41. Material.EMERALD_ORE,
    42. Material.REDSTONE_ORE,
    43. Material.DIAMOND_ORE
    44. );
    45.  
    46. @Override
    47. public void populate(World world, Random rand, Chunk chunk) {
    48. for (int x=0;x<16;x++) {
    49. for (int z=0;z<16;z++) {
    50. for (int y=0;y<world.getMaxHeight();y++) {
    51. Block block = chunk.getBlock(x, y, z);
    52. if (ores.contains(block.getType())) {
    53. block.setTypeIdAndData(1, (byte) 0, false);
    54. }
    55. }
    56. }
    57. }
    58. }
    59. }
    60. }
    61.  


    I just tried downgrading to 1.4.7 to test, nope, same deal. Is it even possible to do this?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  2. Offline

    Jogy34

    They definitely still work, I use them multiple times in one of my plugins. I would suggest storing the NoOrePopulator object into a variable before you add it then check if the list contains it after. This would also check to make sure that your onWorldInit() method is actually being called correctly
     
  3. Offline

    phrstbrn


    It's definately being called. If I add a getLogger().info(..) line to my populate(..) method I can see the populate method being called. I also added another logger command to before I call setTypeIdAndData(...) and it's definately *trying* to change the blocks. However, I can also see the chunks that were populated still have all the ores in them.
     
  4. Offline

    MUG806

    I have been noticing the populator does not reliably populate every chunk. In my own generator I have been noticing that certain chunks get skipped seemingly at random, and no population happens in them.
     
  5. Offline

    phrstbrn

  6. Offline

    saturnine_nl

    maybe a stupid mark, but i had some problems with it. Does it saves the chunk after its getting processed ?
    you can get a list of loaded chunks with world.getLoadedChunks() iterate over the list and perfom a chunk.unload(true) on each chunk. that will save all changes made. It shouldnt matter, but it did in my case.

    greets sat
     
Thread Status:
Not open for further replies.

Share This Page