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)
Place a structure block
On top of structure block place a barrel with
LootTable
(value does not matter)/setblock ~ ~ ~ barrel{LootTable:"test"}
Save the barrel as structure with name
test
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}
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)
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 blockPlace redstone lamps next to the blocks where the redstone block would be placed
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.
Please do not mark unreleased versions as affected.
You don't have access to them yet.