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

/return executed within an advancement reward function globally discards all subsequent commands

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • 1.20.3 Pre-Release 4
    • 1.20.3 Pre-Release 2
    • None
    • Confirmed
    • Advancements, Commands, Data Packs
    • Important
    • Platform

      The bug

      When /return is executed within an advancement reward function, it will discard all subsequent commands globally, not just the local commands that the function has.

      How to reproduce

      1. Install the data pack in Attachments
      2. Run
        /function mc-266968:a

      Results

      The following table shows whether each message was expected to be printed or not, and whether it was actually printed or not.

      Message Expected Actual  
      a-1 Yes Yes
      a-2 Yes No
      b-1 Yes Yes
      b-2 No No

      As the table suggests, say a-2 in mc-266968:a was not executed because it was discarded by return 0 in mc-266968:b.

      Resources

      data/mc-266968/functions/a.mcfunction
      say a-1
      advancement grant @s only mc-266968:b
      say a-2
      
      data/mc-266968/functions/b.mcfunction
      advancement revoke @s only mc-266968:b
      say b-1
      return 0
      say b-2
      
      data/mc-266968/advancements/b.json
      {
        "criteria": {
          "": {
            "trigger": "impossible"
          }
        },
        "rewards": {
          "function": "mc-266968:b"
        }
      }
      

      Code analysis

      An advancement reward function is executed as an initial function, which has a frame with depth 0, regardless of the current depth. Because /return discards all command queue entries above the depth of the currently executed function, /return executed in an advancement reward function discards all entries, which have a depth >= 0.

            boq [Mojang] Bartosz Bok
            intsuc intsuc
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: