Affects Version/s: 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
Fix Version/s: None
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.
- Place a structure block
- On top of structure block place a barrel with LootTable (value does not matter)
- Save the barrel as structure with name test
- Place multiple structure blocks in load mode with integrity lower than 1.0
- Activate the structure blocks
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).
- Save a single redstone block into a structure
- 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)
- 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
- 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
- Place redstone lamps next to the blocks where the redstone block would be placed
- Activate all structure blocks with a line of redstone.
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.
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.
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.