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

Advancement trigger 'enter_block' with state conditions execute reward function when state changed


    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • Minecraft 1.13.2, Minecraft 18w43c, Minecraft 18w45a, 1.15.2, 20w08a
    • Confirmed
    • (Unassigned)

      Take a moment to consider blocks whose state changes when a player enters the block. It's usually blocks like tripwire and pressure plates. These have a blockstate property 'powered' that becomes true when a player enters it. As such, this property can be viewed by both commands and advancements alike.

       Similarly to how entering one of these blocks performs an action, so can advancements with "minecraft:enter_block" criteria and function rewards.

      The Setup

      Have an advancement with an enter_block criterion looking for a tripwire with state `powered=false`, and as a reward for such advancement, a function that looks at the blocks around the player, searching for the same block states as the advancement. If the function finds an unpowered tripwire, spawn happyVillager particles, meaning success. If it finds a powered tripwire, spawn a barrier particle, meaning failure.

      Since by the end of the tick this function runs, the tripwire will be set to powered=true, the function will only run once until the player steps off the tripwire and back on again.

      Note: since tripwire is set to powered even if it's a single block, unattached from a tripwire hook, a line of tripwire isn't necessary.



      Since the advancement looks for an unpowered tripwire, and it is set to run a function when it does so, the expected and intuitive result would be: the function would be able to detect the aforementioned unpowered tripwire before the blocks update to make it powered.


      The Bug

      As of the latest version, this isn't the case. If you run the experiment mentioned above with the data pack provided, you will notice that every time you walk into a tripwire, the barrier particle will play, meaning that the block's state updated between the time the advancement triggered and the reward function ran.

      This is unintuitive behavior, given that advancements trigger reward functions the moment the last required condition is met; so it wouldn't make sense for the condition to already be invalid by the time the function runs.



      The data pack containing the advancement and functions required for the demonstration of this bug is attached, and is set to detect tripwire. This does also occur with pressure plates, although the hitbox needed to trigger it is smaller, therefore it is possible to sneak up to it, on the ground and enter the block but not the pressure plate in the same tick.

      The game does yield the expected result when the player enters the block but not the hitbox of the block, such as the top half of the unattached tripwire, or the top 15/16 of a pressure plate; the bug occurs when the player enters both the block and the hitbox in the same tick.

            Unassigned Unassigned
            energyxxer Energyxxer
            3 Vote for this issue
            5 Start watching this issue