Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-6980

Regression: ChunkLoadEvent and World#isChunkLoaded are sometimes inconsistent on 1.18.2

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    •  This server is running CraftBukkit version dev-Spigot-ffceeae-9ed7e4f (MC: 1.18.2) (Implementing API version 1.18.2-R0.1-SNAPSHOT)
    • Yes

      In the past, World#isChunkLoaded would always already return true during the ChunkLoadEvent. On 1.18.2, when a player freshly joins the server, I now observe this call to return false for the just loaded chunk. In one of my plugins this broke some of the assumptions further down the line in code triggered during this event.

      The following simple event handler demonstrates the issue:

      @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
      void onChunkLoad(ChunkLoadEvent event) {
          Chunk chunk = event.getChunk();
          MyPlugin.getInstance().getLogger().info("Chunk load ("
              + chunk.getWorld().getName() + "," + chunk.getX() + "," + chunk.getZ()
              + "): Currently loaded=" + chunk.isLoaded());
      }

      Output:

      [23:12:18] [Server thread/INFO]: blablubbabc[/127.0.0.1:57632] logged in with entity id 2891 at ([world]-403.62336224751306, 72.0, -55.29084871721566)
      [23:12:18] [Server thread/INFO]: [MyPlugin] Chunk load (world,-25,-4): Currently loaded=false
      [23:12:18] [Server thread/INFO]: [MyPlugin] Chunk load (world,-26,-5): Currently loaded=false
      [23:12:18] [Server thread/INFO]: [MyPlugin] Chunk load (world,-23,-4): Currently loaded=false
      [23:12:18] [Server thread/INFO]: [MyPlugin] Chunk load (world,-23,-2): Currently loaded=false
      [23:12:18] [Server thread/INFO]: [MyPlugin] Chunk load (world,-23,-1): Currently loaded=false
      

      It appears to be arbitrary (can be 1+ ticks) how long after this event the chunk finally reports to actually be loaded (probably due to some kind of async loading involved before the chunk reports to be 'loaded').

      There have been some changes to the code used by the isChunkLoaded check in the update for 1.18.2: https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/commits/05a38da190704cb8df90401c45fc39d087cdc031#nms-patches/net/minecraft/server/level/PlayerChunk.patch
      Maybe these changes can explain this change in behavior. But I have not yet had the time to look into this in detail, or try if reverting these changes resolves this issue.

      Edit: Okay, I just verified: Reverting the changes in ChunkProviderServer and PlayerChunk related to the methods `getFullChunk` (needs to be renamed now) and `getFullChunkUnchecked` resolves this issue.

            blablubbabc blablubbabc
            blablubbabc blablubbabc
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: