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

All structure blocks use same random value for structure integrity and LootTableSeed when powered at the same time


    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • Minecraft 1.10.2, Minecraft 16w40a, Minecraft 16w41a, Minecraft 16w42a, Minecraft 16w43a, Minecraft 16w44a, Minecraft 1.11 Pre-Release 1, Minecraft 1.11, Minecraft 16w50a, Minecraft 1.11.2, Minecraft 17w13a, Minecraft 17w15a, Minecraft 17w16a, Minecraft 17w16b, Minecraft 17w18a, Minecraft 1.12 Pre-Release 1, Minecraft 1.12 Pre-Release 4, Minecraft 1.12 Pre-Release 6, Minecraft 1.12 Pre-Release 7, Minecraft 1.12, Minecraft 1.12.2, Minecraft 17w47a, Minecraft 17w47b, Minecraft 17w49a, Minecraft 17w50a, Minecraft 18w08a, Minecraft 18w16a, Minecraft 1.13-pre1, Minecraft 1.13-pre2, Minecraft 1.13-pre6, Minecraft 1.13, 20w49a, 20w51a, 22w15a
    • Confirmed
    • Loot tables, Structures
    • Low
    • Platform

      The bug

      All structure blocks in a world with a random seed (value = 0) use same random value for whether the block in the structure should be placed for a given structure integrity when powered at the same time. Similarly for all containers placed by structure blocks the same sequence of LootTableSeed values will be assigned to them when loaded at the same time.

      Note: This report explicitly mentions "same time" because merely activating the structure blocks in the same tick might not be enough to reproduce this issue. See the "Code analysis" section below. Reproducing this is therefore slightly hardware dependent.

      How to reproduce (1)

      1. Place a structure block
      2. On top of structure block place a barrel with LootTable (value does not matter)
        /setblock ~ ~ ~ barrel{LootTable:"test"}
      3. Save the barrel as structure with name test
      4. Place multiple structure blocks in load mode with integrity lower than 1.0
        /fill ~1 ~1 ~1 ~10 ~1 ~10 structure_block[mode=load]{mode:"LOAD",posX:0,posY:1,posZ:0,sizeX:1,sizeY:1,sizeZ:1,name:"test",integrity:0.5f}
      5. Activate the structure blocks
        /fill ~1 ~ ~1 ~10 ~ ~10 redstone_block

        The barrels have not been placed randomly, but instead appear in contiguous lines. Additionally all or a lot of barrels in such a line have the same LootTableSeed (/data get block ~ ~-1 ~ LootTableSeed).

      How to reproduce (2)

      1. Save a single redstone block into a structure
      2. Place 8 structure blocks side by side that load the redstone block in front of them. (Leave one block gap so that the redstone block doesn't activate the structure block)
      3. Set the structure integrities to the values 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1.0 in order
      4. Place impulse command blocks with the command /setblock ~ ~1 ~ minecraft:air underneath the block where the redstone Block would be placed by the structure block
      5. Place redstone lamps next to the blocks where the redstone block would be placed
      6. Activate all structure blocks with a line of redstone.

      Expected result

      When activating the redstone the lamps light up with the probability set in the structure integrity independent from each other. There might be gaps between two lit lamps.

      Actual result

      A random amount from 1 to 8 of lamps light up when the redstone is activated, but the activated lamps are all in one line. There is never a gap between two lit redstone lamps.

      If all structure blocks had the same structure integrity, all lamps would either be lit or unlit, but never different.

      I guess this bug is caused by bad pseudo random number generation. Blocks not located at (0, 0, 0) show similar patterns since the generated r value is probably close to the one on the same block on other structures.

      This bug is relevant because it can lead to strange behaviors when using structure blocks for randomizers in map making.

      Code analysis

      20w49a, Mojang names

      When a random seed is used (value 0) the method net.minecraft.world.level.block.entity.StructureBlockEntity.createRandom(long) creates a new Random instance based on the current milliseconds. It is therefore not unlikely that when activating multiple structure blocks in the same tick, many of them will load the structure in the same millisecond and therefore create a Random instance which returns exactly the same sequence of random values.
      This also affects the creation of the LootTableSeed value for container blocks placed by the structure.

      Similar code also exists in net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings.getRandom(BlockPos).

      It would be best to not use the current milliseconds as seed value but instead create Random instances without a given seed, or to use a single static Random instance.

        1. activation.png
          1.55 MB
        2. F3.png
          1.28 MB
        3. setup.png
          1.22 MB

            Unassigned Unassigned
            quijx Quijx
            16 Vote for this issue
            8 Start watching this issue