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

All structure blocks use same random value for structure integrity when powered in same tick

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Resolution: Unresolved
    • 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
    • Fix Version/s: None
    • Confirmation Status:
      Confirmed
    • Category:
      (Unassigned)

      Description

      The bug

      All structure blocks in a world use same random value for whether the block at (0, 0, 0) in the structure should be placed for a given structure integrity when powered in same tick.
      Of course this is only relevant when using a random seed (0).

      The code for whether a block in a structure should be placed for a given structure_integrity probably goes something like this:

      r = random value from 0.0 to 1.0
      if (r < structure_integrity)
          place block
      

      Now this value r appears to be the same for all blocks located at (x=0,y=0,z=0) in a structure when the structures are placed in the same tick.

      How to reproduce

      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

      Based on 1.11 decompiled using MCP 9.35 rc1

      This happens because the method net.minecraft.world.gen.structure.template.PlacementSettings.getRandom(BlockPos) uses the current time in milliseconds if the seed is 0 or the provided block position is null (which is never the case). It would return a block position based value if the seed, which is stored as a Long, would be null, but that is never the case either.

      However, creating a Random object without a given seed would probably return the best result.

        Attachments

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

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                quijx Quijx
              • Votes:
                10 Vote for this issue
                Watchers:
                9 Start watching this issue

                Dates

                • Created:
                  Updated:
                  CHK: