Check if chunk isn't loaded

Discussion in 'Plugin Development' started by xDeeKay, Jun 12, 2015.

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

    xDeeKay

    I need to spawn an entity in a location, which I believe requires the chunk to be loaded.
    The code below always seems to always return true, saying the chunk is already loaded, even when I change worlds to unload the chunk.

    Code:
                    Chunk chunk = location.getChunk();
    
                    if (!chunk.isLoaded()) {
                        Bukkit.broadcastMessage("chunk wasn't loaded, loading chunk");
                        chunk.load(true);
                    } else {
                        Bukkit.broadcastMessage("chunk was already loaded");
                    }
    Any ideas? Thanks.
     
    Last edited: Jun 13, 2015
  2. Offline

    LeePMC

    remember spawn chunks are always loaded so if your testing on a new server, and your spawning the entity within the spawn chunks, it will always return true, try moving atleast 15 chunks away from the world spawn (NOT 0,0) and see if that works.
     
  3. Offline

    xDeeKay

    @LeePMC Yeah, I've tried locations far away from spawn as well as the nether world, still returns the chunks as being loaded.
     
  4. Offline

    LeePMC

    when are you checking this? @xDeeKay
     
  5. Offline

    xDeeKay

  6. Offline

    LeePMC

    If your spawning your entity before this, then it's probably already loading the chunk to spawn the entity, I can't figure anything out with this snippet of code @xDeeKay
     
  7. Offline

    xDeeKay

    @LeePMC I don't think that's the case, as I wasn't able to spawn the entity before using this check, and even so, spawning of the entity comes after the chunk load check. I just find it strange that it returns the else statement, yet it still loads the chunk at the same time.
     
  8. Offline

    LeePMC

    Again... I can't see anything wrong with this snippet of code, the only thing I can think of now is what if you just loaded the chunk you were spawning the entity in even if it's already loaded so you never have to worrie about the problem again
     
Thread Status:
Not open for further replies.

Share This Page