Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-253542

Spawner blocks with SpawnPotential and no SpawnData will crash during worldgen

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • 22w43a
    • 1.19, 1.19.1
    • None
    • Confirmed
    • Crash
    • Important

    Description

      If a spawner block is saved into an nbt file for structures and then is edited to delete its SpawnData field but keep its SpawnPotential field, loading that nbt file by worldgen structure or worldgen feature will crash the game.

      The expected behavior is that the SpawnPotential would pick on entry from itself and create the SpawnData info automatically. This expected already happens when doing this command in a world: 

      /setblock ~ ~ ~ spawner
      {"SpawnPotentials":[{"data":{"custom_spawn_rules":{"block_light_limit":{"max_inclusive":15,"min_inclusive":0}},"entity":{"id":"minecraft:drowned"}},"weight":1}]}

      The issue is caused by the BlockEntity's load method being called right away during worldgen block placing where it's level field is currently null. In order for the SpawnPotentials to pick which entry to use for SpawnData, it needs a random. Before 22w15a, the spawner block entity used this.random to do the picking. Now it is trying to do this.level.getRandom() which will crash because level is null.

      Attached is a datapack to reproduce the issue. Locate and teleport to any plains village and the crash will happen because the datapack replaces the town center of the village to have a spawner block with SpawnPotential but no SpawnData.

      Attachments

        1. spawner_nbt_crash.zip
          11 kB
        2. latest.log
          23 kB
        3. crash-2022-07-30_12.20.35-server.txt
          8 kB
        4. deobf_crash-2022-07-30_12.20.35-server.txt
          35 kB
        5. MC-253542.png
          MC-253542.png
          161 kB

        Activity

          People

            panda4994 [Mojang] Panda
            TelepathicGrunt TelepathicGrunt
            Votes:
            5 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              CHK: