Uploaded image for project: 'Minecraft (Bedrock codebase)'
  1. Minecraft (Bedrock codebase)
  2. MCPE-148128

Stronghold layout uses cloned random number generator

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.18.0.27 Beta, 1.17.41 Hotfix, 1.20.50.23 Preview, 1.20.41 Hotfix
    • None
    • Confirmed
    • Multiple
    • 957542

      When bedrock produces blueprints for strongholds it clones the rng which causes it to attempt to place the same room type on all exits of a room.

      Steps to Reproduce:
      Load up any of the seeds in the attached "StrongholdGen5wayAllOpen.txt", teleport to the bottom of the starting stairway, using the command provided.

      Observed Results:
      The room selected to be placed on the 'forward' exit of the starting 5 way room is consistently identical (if it fits) to room placed on other exits.

      Expected Results:
      Room selection should be random and no forking of the rng should occur when child rooms are placed.

      Notes:
      Basically what's happening is when there is a room with multiple exits the rng gets cloned before the room to be placed is chosen. This causes the same room to be chosen for every exit of a room that has multiple exits (ie 5 way, straight, large room, store house, pillar, fountain).

      There is logic that prevents the same room from being placed twice in a row. This causes an alternating pattern. If the starting 5 way has all exits open, normally 3 of those exits will have the same room, with the same door type (assuming it can fit).

      See the attached StrongholdGen5wayAllOpen.txt for examples where all exits of the starting 5 way are open (thats the only criteria, in order to make it easier to see the pattern). The first column is the seed, the second column is a teleport command that teleports you to the bottom of the starting staircase.

      Impacts:
      The cloning of the rng causes a significant increase in the number of stronghold layouts that fail to place a portal room. (Please note that is not the bug I'm reporting, just a side effect). After generating all 2^32 possible stronghold layouts available in bedrock, I've found that 5.8% of them fail to place a portal room. I reran the simulation as if the rng wasn't cloned and this dropped to 2.3%.

      I've attached a file (StrongholdGenFailures.txt) with examples of strongholds that almost completely failed generation due to this issue. All of these examples have strongholds that stopped generating after only 3 rooms. The starting staircase, the initial 5 way, and one other room. I'm hoping these more extreme examples will be helpful to identifying the cause of this issue.

      Code analysis:
      When simulating stronghold layouts for bedrock I need to clone the rng somewhere between the call to "generateAndAddPiece" and "generatePieceFromSmallDoor" in order for the stronghold layouts to be accurate. My best guess is that the "Random" object is being passed by value instead of by reference to one of these functions.

      If there is any more information that would be useful (eg 1.18 beta examples) let me know.

            crackedMagnet Matthew Ferguson
            Votes:
            3 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              CHK: