Mojira Archive
MC-125067

Command context/selectors in /execute are evaluated too early

The new /execute command gives detailed control over the command context given to a command that is to be executed. However, the way command contexts are computed doesn't account for the fact that command context may change in iterations of the outer loop and should then be different in subsequent iterations.

For many use-cases this is perfectly fine because the command context rarely (intentionally) changes. However, for some applications this is not sufficient. Consider the following command, ran when exactly one player and a couple of other entities are in the game:

/execute as @e at @p run tp @p ~ ~ ~1

Expected behavior: the player is teleported one block for each entity in the world. If there are 10 armor stands and the player, the player should be teleported 11 blocks. Actual behavior: the player is teleported one block. A reproduction case not involving teleportation can be found in this comment.


The following is a simplified, pseudo code interpretation of how /execute looping is understood to work with this command:

compute contexts for all loops
loop over @e
	loop over @p
		stitch together computed command context
		run "tp @p ~ ~ ~1" with computed command context

Instead, it should work somewhat like this:

calculate contexts for @e loop
loop over @e
	calculate contexts for @p loop
	loop over @p
		stitch together context for this iteration
		run tp @p ~ ~ ~1 with computed command context

Note that the implementation of /execute wasn't looked at in detail for this ticket, so it contains a healthy dose of speculation.

Won't Fix

komaramune

2018-02-11, 11:05 AM

2024-06-16, 11:31 PM

2022-03-16, 10:36 AM

11

9

Confirmed

(Unassigned)

/execute

Minecraft 18w06a - 1.17.1Minecraft 18w06a, Minecraft 18w07c, Minecraft 1.13-pre1, Minecraft 1.13, Minecraft 1.13.1, 1.15.1, 1.15.2 Pre-release 2, 1.16.3, 1.17.1

-