Crash when importing 1.17 chunks with entities above the world, when a BlockPopulator is active

    • This server is running CraftBukkit version 3395-Spigot-f4ff00f-cc86ab1 (MC: 1.18.1) (Implementing API version 1.18.1-R0.1-SNAPSHOT)
    • Yes

      When the server attempts to import a chunk from Minecraft 1.17 (or maybe also earlier, not tested) and it encounters an entity above the world, the server will crash if a (plugin-provided) org.bukkit.generator.BlockPopulator instance is active for that world. It crashes with java.lang.IllegalStateException: Entity EntitySmallFireball['Small Fireball'/13, l='ServerLevel[world]', x=-8017.32, y=8783.24, z=2132.08] is not in the region (or similar).

      This seems quite specific, but it means that a server with a custom BlockPopulator cannot read parts of old worlds. I get similar crashes multiple times per day due to players visiting old chunks, with different projectile entities: arrows, fireballs, wither skulls, etc. For the past week, I've been trying to pinpoint the issue.

      The issue does not happen if the plugin providing the BlockPopulator instance is removed. The issue also does not happen if I manually edit the region files (using an external program, NBTExplorer) to remove the entity above the world.

      To help reproducing the issue, I've attached a world with the offending region file. The spawn of the world was moved so that the chunk is loaded on startup, making the server crash without requiring player movement.

      The server is not able to write the crash report to disk, nor to finish writing the log file, so I've attached the output of the console. I've also attached an example plugin that triggers the issue; it's just an empty block populator.

      Steps to reproduce

      • Download the attached world, use it as the main world.
      • Download the attached plugin, place it in the plugins folder.
      • Start the server, and watch it crash before it is finished loading the spawn area.

      Source code of the example plugin that triggers the issue (use with the provided world):

      import java.util.Random;

      import org.bukkit.event.EventHandler;
      import org.bukkit.event.Listener;
      import org.bukkit.event.world.WorldInitEvent;
      import org.bukkit.generator.BlockPopulator;
      import org.bukkit.generator.LimitedRegion;
      import org.bukkit.generator.WorldInfo;
      import org.bukkit.plugin.java.JavaPlugin;

      public class Startup extends JavaPlugin implements Listener {

          @Override
          public void onEnable() {
              getServer().getPluginManager().registerEvents(this, this);
      {{    }}}

          @EventHandler
          public void onWorldInitEvent(WorldInitEvent event) {
              event.getWorld().getPopulators().add(new BlockPopulator() {
                  @Override
                  public void populate(WorldInfo worldInfo, Random random, int chunkX, int chunkZ, LimitedRegion area) {
                      // Empty!
      {{            }}}
              });
      {{    }}}
      }

      Speculation of cause:

      Loading old chunks triggers Mojangs retrogen magic, which triggers the logic for custom block population, which triggers the entity-out-of-region check in org.bukkit.craftbukkit.v1_18_R1.generator.CraftLimitedRegion.saveEntities.

        1. console-output.txt
          271 kB
        2. EmptyBlockPopulator.jar
          4 kB
        3. world.zip
          6.61 MB

          [SPIGOT-6891] Crash when importing 1.17 chunks with entities above the world, when a BlockPopulator is active

          Nathan Wolf added a comment -

          I have a live server crashing constantly, I'd love to see this PR get pulled.

          Nathan Wolf added a comment - I have a live server crashing constantly, I'd love to see this PR get pulled.

          Rutger Kok added a comment -

          Thanks! For sure this will help custom terrain lovers with old worlds.

          Rutger Kok added a comment - Thanks! For sure this will help custom terrain lovers with old worlds.

          Made a PR for this: craftbukkit#995

          Marvin Rieple added a comment - Made a PR for this: craftbukkit#995

          Rutger Kok added a comment -

          It's an 8 year old world visited by many players, I have no idea how the projectile ended up there. Maybe some kind of farm? As far as I know only arrows experience gravity, so these fireball projectiles can go quite high before their time is up.

          Anyways, I just tested and the server also crashes for an entity edited to be at y=320. However, y=319 is fine and doesn't cause a crash.

          Rutger Kok added a comment - It's an 8 year old world visited by many players, I have no idea how the projectile ended up there. Maybe some kind of farm? As far as I know only arrows experience gravity, so these fireball projectiles can go quite high before their time is up. Anyways, I just tested and the server also crashes for an entity edited to be at y=320. However, y=319 is fine and doesn't cause a crash.

          Fireball was just infinity flying up ...
          Weird to have Entities saved at that high too ^^ 

          FreeSoccerHDX added a comment - Fireball was just infinity flying up ... Weird to have Entities saved at that high too ^^ 

          Why / how do you have entities at y level 8783?

          Marvin Rieple added a comment - Why / how do you have entities at y level 8783?

            Assignee:
            Marvin Rieple
            Reporter:
            Rutger Kok
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: