Chunk load/unload

Discussion in 'Spigot Discussion' started by Likaos, Sep 8, 2013.

  1. Hi,

    I'm developping a simple code to create a Meteorite Shower in a world, for some reasons I just want do it on the loaded chunks to improve performances.

    My code
    Code (Text):
        public static void meteorShower(World w, int nMeteor) {
            long start = System.currentTimeMillis();
            Chunk[] chunks = w.getLoadedChunks();
            Msa.debug("Nombre de chunks "+chunks.length);
            Random rand = new Random();
            int x,z;
            for (int count = 0 ; count < nMeteor; count++) {
                Chunk c = chunks[rand.nextInt(chunks.length)];
                x = rand.nextInt(16);
                z = rand.nextInt(16);
                Block b = c.getBlock(x, 255, z);
                Fireball f = (Fireball) w.spawn(b.getLocation(), Fireball.class);
                f.setYield(3F);
                int vx = new Random().nextInt(3) - 1;
                int vz = new Random().nextInt(3) - 1;
                f.setDirection(new Vector(vx, -1, vz));
            }
            Msa.perf(start, "Meteor");
     
        }
    My code spawn fireballs in chunks, but they are like "frozen" in the sky cause the chunks are not really loaded at this moment, how can I get the really loaded chunks ?
    Is it a Spigot or Bukkit feature ?

    Probleme ? When a player come and load the chunk, tons of Meteorites spawn at the same time and blast the area... :/

    Thanks.