Chunk Loading

Discussion in 'Plugin Development' started by Coopah, Mar 5, 2020.

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

    Coopah

    Is there an easy way to prevent chunks from unloading? I've tried cancelling the ChunkUnloadEvent but that does nothing.

    If there is no easy way to do this is there a working plugin for 1.8 that does it?

    Cheers.
     
  2. Offline

    Yeowza

    Here is what I do,

    Code:
            // force load all of our chunks
            for (int x = -68; x <= -56; x++) {
                for (int z = 55; z <= 68; z++)    {
                    Main.world.loadChunk(x, z, true);
                    Main.world.getChunkAt(x, z).setForceLoaded(true);
                }
            }
    Everyone says its dangerous though because it will lag the server quite a bit. My server is just a small minigame server though so it doesn't matter much for me.
     
  3. Offline

    KarimAKL

    @Coopah From reading the javadocs, it seems the ChunkUnloadEvent is called after the chunk is unloaded, so try this:
    Code:Java
    1. @EventHandler
    2. private void onUnload(ChunkUnloadEvent event) {
    3. Chunk chunk = event.getChunk();
    4.  
    5. chunk.setForceLoaded(true);
    6.  
    7. // I'm not sure if this is needed
    8. // First try without it, then if it doesn't work, try with it
    9. //chunk.load();
    10. }
     
  4. Offline

    Coopah

    @Yeowza @KarimAKL
    There is no method for setForceLoaded ? I am using 1.8.9 and all I get is chunk.load(); not chunk.setForceLoaded();
     
  5. Offline

    KarimAKL

    @Coopah Ah, my bad, i didn't check the docs for 1.8.

    Try the code i sent, but with "chunk.load()" instead of "chunk.setForceLoaded(true)".
     
    Coopah likes this.
  6. Offline

    Coopah

    @KarimAKL
    chunk.load() seems to have no effect. Guess it just unloads right away after.
     
  7. Offline

    KarimAKL

    @Coopah Ah, that's too bad.

    Try looking into some of the NMS source to see if you can find any way to do it in 1.8.

    I'd recommend first looking at some NMS where the setForceLoaded(boolean) method is there, see how it works, and then see if it's possible to do it in NMS 1.8.

    I checked a little for 1.14.4, it seems the setForceLoaded method is in the "WorldServer" class, and it seems to use the following classes to do it:
    - "ForcedChunk"
    - "WorldPersistentData"
    - "ChunkProviderServer"
     
Thread Status:
Not open for further replies.

Share This Page