Block Populator only works 90% of the time ?

Discussion in 'Plugin Development' started by Ziden, Jul 25, 2012.

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

    Ziden

    Hi there. I have a silly question witch i havent found the answer. Ive found Dinnerbone's topic about Chunk Generators and Block Populators but i couldnt understand that.

    Ive made a populator, witch removes all coal ores from the generated chunk.

    It works, most of the time... but it seems some chunks are not affected by my populator, why is that ?

    Here is my populator:

    Code:
    public class BPop extends BlockPopulator {
     
            @Override
            public void populate(final World world, final Random random, final Chunk chunk) {
                if (world.getEnvironment() != Environment.NORMAL) {
                    return;
                }
                long tempo = System.nanoTime();
                for (int x = 0; x < 16; x++) {
                    for (int z = 0; z < 16; z++) {
                        for (int y = 1; y < 256; y++) {
                            if (chunk.getBlock(x, y, z).getType()==Material.COAL) {
                                chunk.getBlock(x, y, z).setType(Material.STONE);
                            }
                        }
                    }
                }
                plugin.log.info("Chunk repopulated, took " + (System.nanoTime() - tempo) + " nano seconds to do that");
            }
        }
    And here is how i call it !

    Code:
    @EventHandler
        public void init(WorldInitEvent ev) {
            boolean has= false;
            for (BlockPopulator bp : ev.getWorld().getPopulators()) {
                if (bp instanceof BPop) {
                    has= true;
                    break;
                }
            }
            if (!has&& ev.getWorld().getEnvironment() == Environment.NORMAL) {
                ev.getWorld().getPopulators().add(new BPop());
                log.info("added populator to world : " + ev.getWorld().getName());
            }
        }

    Thanks for the attention ! ^^
     
  2. Offline

    pzxc

    Dunno anything about block populators, but here's a couple things I'd fix on your code:

    loop y from 0 to world.getMaxHeight()
    dunno why you're looking for the highest Y block at the specific coords x,y,z but you're recalcing it EVERY block, just go 0 to 255 and be done with it (ok, getMaxHeight() at least in case they increase the ceiling again)

    You don't seem to be using the "target" variable that you are defining inside the triple-for loop. If it's unused get rid of it and save yourself 65k calls to getBlockAt and getLocation for each chunk
     
  3. Offline

    Ziden

    hehe thanks for the attention, fixed ! =]

    just throwing test code here , but thanks for the help!!

    I just noticed it seems to work 100% of the times, however it simply doesnt detect some coals... like if they were generated after my code runs...any idea why ?

    Please ? :/ I dont really know why this happens, i promise if i manage to do this ill make a plugin 99% of users will use , just need to know how to do that

    Ok so i just think its a bukkit bug, after reading this (and its old...and it keeps the same way)

    http://forums.bukkit.org/threads/blockpopulator-sometimes-fails-to-work.46148/

    ima report it to leaky
    if someone knows someway to 'bypass' this bug w/o havng to change blocks during a chunk load, plz let me know

    thanks

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
Thread Status:
Not open for further replies.

Share This Page