Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Minecraft:Command context

From SAS Gaming Wiki
Revision as of 14:07, 2 April 2026 by imported>Wplx23333
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Command context (also know as execution context, command origin, command source stack) is a set of parameters like the executor and execution environment. It is used to provide context for Minecraft:command execution or Minecraft:raw JSON text resolution.

Behaviors

There are mainly 8Template:Only/7Template:Only parameters in command context:

When Minecraft:commands are executed or Minecraft:raw JSON texts are resolved in different scenarios, corresponding contexts are provided, to allow them to work in different scenarios.

When running a function with the Template:Cmd command, the context for commands inside the function inherits the Executor Parameters, Execution Environment Parameters, and Execution Permission Level from the context of Template:Cmd command, while the Execution Output Callback is not inherited. Template:IN, the Execution Permission Level of commands in a function is limited to 2 or below, so, if the Template:Cmd command is executed with 2 or higher Execution Permission Level, the command inside the function is executed with Execution Permission Level being 2.

Template:IN, the context for commands in functions scheduled by Template:Cmd command also inherits the Executor Parameters, Execution Environment Parameters, and Execution Permission Level from the context of Template:Cmd command.

Static values and Dynamic values

Template:IN, the Executor Name and each Execution Environment Parameters in a context are static, and each of them exists independently. In other words, if these parameters are not modified with Template:Cmd, they do not change during the command execution, or during the execution of each command in a function. For example, even if the name of the Executor Entity is modified in a function, it does not change the Executor Name in the context of subsequent commands in the function; For another example, for Template:Cmd, even if a Template:Cmd command in a function Template:Cd changes the position, rotation, or dimension of the sheep entity, it does not affect the Execution Position, Execution Rotation, and Execution Dimension in the context of subsequent commands in the function, since the values of all these parameters are static after being modified by the Template:Cd subcommand and they are no longer related to the sheep entity itself.

Template:IN parameter values are static in some cases but dynamic in other cases. When dynamic, the value of a parameter does not exist independently, but rather it is a reference to an entity and fetches values from the entity in real time. For example, when an Execution Position is dynamic, it depends on an entity and obtains its position in real time, i.e., if the entity is moved in a function, the Execution Position in the context of subsequent commands in the function is the position of the entity after the move.<ref>Template:Bug</ref>

Specifically, dynamic values exist in the following cases:

  • When the player executes a command in the chat bar, or a command is requested through a WebSocket server connected with the client, the Execution Position, Execution Rotation, and Execution Dimension are dynamic and referring to the player entity.
  • When a command block minecart executes the command in it, the Execution Position and Execution Rotation are dynamic, referring to this minecart entity.
  • When an entity event response defined in a behavior pack executes a command, or a script executes a command with entity class, or an animation controller in a behavior pack executes a command, or an NPC executes a command, the Executor Name, Execution Position, Execution Rotation, and Execution Dimension are dynamic and referring to the entity.
  • Template:Cmd command converts the Executor Name to a dynamic value referring to the Executor Entity. That is, when a command is executed in a Template:Cmd command, the Executor Name of it is always dynamic, fetched from the Executor Entity in real time, regardless of whether there is a static Executor Name in the context of the Template:Cmd.
  • Template:Cd and Template:Cd subcommands in Template:Cmd set the Execution Position to a dynamic value, referring to the specified entity.
  • Template:Cd and Template:Cd subcommands in Template:Cmd set the Execution Rotation to a dynamic value, referring to the specified entity.

If the Execution Position is dynamic, it fetches the position from an entity in real time. But, if this entity is Minecraft:riding on another entity, there is a special treatment:

  • If the hitbox bottom of this entity is lower than the hitbox bottom of the mount, the mount's hitbox bottom is used as the Y coordinate of the Execution Position.
    • For example, if a player is riding on a minecart, the player's X and Z coordinates and the minecart's Y coordinate are used as the Execution Position.

If the entity which a dynamic value refers to has been removed from the world (e.g., an armor stand is killed, or a sheep finishes its death animation), the dynamic value cannot be fetched. In this case, default values of parameters are used:

  • Executor Name defaults to an empty string
  • Execution Dimension defaults to empty
  • Execution Position defaults to (0, 0, 0)
  • Execution Rotation defaults to (0, 0)

For example, when Template:Cmd is executed in the command block, as mentioned above, the Executor Name converts to a dynamic value by the Template:Cmd command, referring to the Executor Entity. Since there is no Executor Entity in the context, the Executor Name of Template:Cmd is an empty string.

For another example, if the Executor Entity is removed before a function schedule (scheduled by Template:Cmd) is executed, the schedule cannot be executed because the Execution Dimension is missing in the context.

A dynamic value is converted to a static value in the following cases:

For example:

  • When a player executes Template:Cmd in the chat bar, the Execution Position, Execution Rotation and Execution Dimension of commands in the function are dynamic, referring to the player.
  • When a player executes Template:Cmd in the chat bar, the Execution Position of the Template:Cd is dynamic, while the Execution Rotation and Execution Dimension are static.
  • When a player executes Template:Cmd in the chat bar, the Execution Position and Execution Rotation of the Template:Cd} are dynamic, while the Execution Dimension is static.
  • When a player executes Template:Cmd in the chat bar, the Execution Position of the Template:Cd is dynamic, while the Execution Rotation and Execution Dimension are static.
  • When a player executes Template:Cmd in the chat bar, the Execution Position, Execution Rotation and Execution Dimension of the Template:Cd are all static.
  • When a player executes Template:Cmd in the chat bar, the Execution Position, Execution Rotation and Execution Dimension of the Template:Cd are all static.
  • If there are at least three entities in a dimension, and a player in the dimension executes Template:Cmd in the chat bar, the player is teleported to 3 blocks above its original position.

Parameters

Execution Permission Level

Template:Main The Execution Permission Level cannot be modified by Template:Cmd command.

Template:IN, in the context of commands in a function called by a Template:Cmd command, the Execution Permission Level is limited to 2 or less. If the Execution Permission Level of the Template:Cmd command is greater than 2, the commands in the function is executed with Execution Permission Level of 2.

Executor Parameters

There are two Executor Parameters, Executor Name and Executor Entity, where the Executor Entity parameter may be empty (e.g. when a command is executed by a command block). Executor parameters are used in the following scenarios:

They can be modified using Template:Cd, Template:Cd, and Template:Cd subcommands in Template:Cmd command. Template:IN, the Executor Name and Executor Entity are always modified at the same time. Template:IN, only the Executor Entity is modified, and as mentioned above, the Executor Name remains a dynamic value referring to the Executor Entity.

Execution Dimension

Execution Dimension is the Minecraft:dimension in which the command takes effect. Execution Dimension is used in the following scenarios:

Execution Dimension can be modified using Template:Cd and Template:Cd subcommands in the Template:Cmd command. Template:IN, the Template:Cmd command itself converts the Execution Dimension to a static value.

Execution Position

Execution Position is the Minecraft:coordinates that the command takes effect from. Execution Position is used in the following scenarios:

Execution Position can be modified using Template:Cd, Template:Cd, Template:Cd subcommands in Template:Cmd command, and Template:Cd subcommand also affects the Execution Position. Template:IN, Template:Cd and Template:Cd subcommands set the Execution Position to a dynamic value referring to the specified entity. Template:IN, Template:Cd, Template:Cd, Template:Cd, and Template:Cd subcommands convert the Execution Position to a static value.

Execution Rotation

Execution Rotation is the rotation that the command is executed with. Execution Rotation is used in the following scenarios:

Execution Rotation can be modified using Template:Cd, Template:Cd, and Template:Cd subcommands in the Template:Cmd command. Template:IN, Template:Cd and Template:Cd subcommands set the Execution Rotation to a dynamic value referring to the specified entity. Template:IN, Template:Cmd command itself and its Template:Cd, Template:Cd subcommands converts the Execution Rotation to a static value.

Execute Anchor

Template:Exclusive Execute Anchor determines whether the position of eyes or feet of the Executor Entity is used as the origin of Minecraft:local coordinates, and the start point of Template:Cd in Template:Cmd and of Template:Cd subcommand in Template:Cmd.

  • If it is foot, uses the Execution Position directly.
  • If it is eyes, based on the Execution Position, the eye height of the Executor Entity is added into the Y coordinate.

Execution Anchor are used only in the following scenarios:

Execute Anchor can be modified using Template:Cd subcommand in Template:Cmd command.

Executor Anchor parameter does not exist Template:In. Instead, Template:In, the Template:Cd subcommand in Template:Cmd directly modifies the Execution Position. If the Execution Position is originally dynamic, the Template:Cd subcommand converts it to a static value, being the position of feet or eyes of the entity being referred by the dynamic value; If the Execution Position is static, Template:Cd subcommand does not have any effect at all.

Execution Output Callback

Execution Output Callbacks are used to receive output values of a command.

A command executed in a Minecraft:command block, a Minecraft:minecart with command block, or a scriptTemplate:Only has a callback that sends the success count to the command block or minecart.

Template:IN, Template:Cd subcommand in Template:Cmd command can be used to add a new callback while the existing callbacks are retained. Existing callbacks cannot be cleared by Template:Cmd command.

The context of commands in a function called by a Template:Cmd or Template:Cmd does not inherit the Execution Output Callbacks of the Template:Cmd or Template:Cmd command.

Contexts in various scenarios

Command execution

Server console

The context of commands entered in the server console is:

  • Execution Permission Level: 4
  • Executor Name: Server
  • Executor Entity: None
  • Execution Dimension: Overworld
  • Execution Position: Bottom northwest corner of the block at the Minecraft:world spawnTemplate:Only/(0, 0, 0)Template:Only
  • Execution Rotation: (0, 0)
  • Execution AnchorTemplate:Only: Feet
  • Execution Output Callback: None

Functions executed by the server-side

A Minecraft:function is executed by the server-side when:

The context of commands in a function executed by the server-side is:

Player

The context of commands that are entered in the chat bar, or requested via a WebSocket server connected with the client Template:In, is:

  • Execution Permission Level: The permission level of the player
  • Executor Name: The name of the player; or External for commands requested by a WebSocket Template:In
  • Executor Entity: The player
  • Execution Dimension: The dimension the player is in (Dynamic value Template:In)
  • Execution Position: The position of the player (Dynamic value Template:In)
  • Execution Rotation: The rotation of the player (Dynamic value Template:In)
  • Execution AnchorTemplate:Only: Feet
  • Execution Output Callback: None

Command block

The context of commands that are executed in a Minecraft:command block is:

  • Execution Permission Level: 2Template:Only/1Template:Only
  • Executor Name: The custom name of the command block. If it has no custom name, defaults to @Template:Only/!Template:Only.
  • Executor Entity: None
  • Execution Dimension: The dimension the command block is in
  • Execution Position: The center of the command block
  • Execution Rotation: The rotation of the command blockTemplate:Only/(0, 0)Template:Only
  • Execution AnchorTemplate:Only: Feet
  • Execution Output Callback: Sends the success count to the command block

Minecart with command block

The context of commands that are executed in a Minecraft:minecart with command block is:

  • Execution Permission Level: 2Template:Only/1Template:Only
  • Executor Name: The custom name of the minecart. If it has no custom name, defaults to @Template:Only/!Template:Only.
  • Executor Entity: The minecart with command block
  • Execution Dimension: The dimension the minecart is in
  • Execution Position: The position of the minecart (Dynamic value Template:In)
  • Execution Rotation: The rotation of the minecart (Dynamic value Template:In)
  • Execution AnchorTemplate:Only: Feet
  • Execution Output Callback: Sends the success count to the command block

Sign

Template:Exclusive The context of commands executed when a player clicks a Minecraft:sign block is:

  • Execution Permission Level: 2
  • Executor Name: The name of the player
  • Executor Entity: The player
  • Execution Dimension: The dimension the sign block is in
  • Execution Position: The center of the block the sign is in
  • Execution Rotation: (0, 0)
  • Execution Anchor: Feet
  • Execution Output Callback: None

Advancement reward

Template:Exclusive The context of commands in the function called by a Template:Nbt reward in a custom advancement is:

  • Execution Permission Level: 2
  • Executor Name: The name of the player that gets the advancement
  • Executor Entity: The player that gets the advancement
  • Execution Dimension: The dimension the player is in
  • Execution Position: The position of the player
  • Execution Rotation: The rotation of the player
  • Execution Anchor: Feet
  • Execution Output Callback: None

Enchantment effect

Template:Exclusive The context of commands in the function called by a run_function enchantment effect is:

  • Execution Permission Level: 2
  • Executor Name: The name of the affected entity of the enchantment effect
  • Executor Entity: The affected entity of the enchantment effect
  • Execution Dimension: The dimension the enchantment takes effects in
  • Execution Position: The position the enchantment takes effects at
  • Execution Rotation: The rotation of the affected entity of the enchantment effect
  • Execution Anchor: Feet
  • Execution Output Callback: None

Entity in behavior packs

Template:Exclusive

The context of commands executed via an entity event response defined in a behavior pack, or via entity class in a script, or an animation controller in a behavior pack, or a dialogue of an Minecraft:NPC entity is:

  • Execution Permission Level: 1
  • Executor Name: The name of the entity (Dynamic value Template:In)
  • Executor Entity: The entity
  • Execution Dimension: The dimension the entity is in (Dynamic value Template:In)
  • Execution Position: The position of the entity (Dynamic value Template:In)
  • Execution Rotation: The rotation of the rotation (Dynamic value Template:In)
  • Execution Output Callback: If via entity class in a script, returns the success count

Dimension in scripts

Template:Exclusive The context of commands executed via Dimension class in a script:

  • Execution Permission Level: 1
  • Executor Name: Script Engine
  • Executor Entity: None
  • Execution Dimension: The dimension
  • Execution Position: (0, 0, 0)
  • Execution Rotation: (0, 0)
  • Execution Output Callback: Returns the success count

Raw JSON text resolution

When resolving a Minecraft:raw JSON text, relative coordinates, local coordinates, and target selectors in it are resolved based on a command context. The Execution Output Callback parameter in the command context is not used by raw JSON text.

Note that if the Template:Nbt field is * in a score type text, the reader's own score is displayed. In addition to the command context, the readers of the raw JSON text are also listed below.

Called by a command

A Minecraft:raw JSON text called by a command inherits the context of the command. Including:

Written book being opened by a player

Template:Exclusive The context when a Minecraft:written book is being opened by a player is:

  • Execution Permission Level: The permission level of the player
  • Executor Name: The name of the player
  • Executor Entity: The player
  • Execution Dimension: The dimension the player is in
  • Execution Position: The position of the player
  • Execution Rotation: The rotation of the player
  • Execution Anchor: Feet
  • Reader: The player

Written book being placed on a lectern

Template:Exclusive The context when a written book is being placed on a Minecraft:lectern is:

  • Execution Permission Level: 2
  • Executor Name: Lectern
  • Executor Entity: None
  • Execution Dimension: The dimension the lectern is in
  • Execution Position: The center of the block the lectern is in
  • Execution Rotation: (0, 0)
  • Execution Anchor: Feet
  • Reader: None

Sign

Template:Exclusive The context when the text in a Minecraft:sign block is being changed via NBT is:

  • Execution Permission Level: 2
  • Executor Name: Sign
  • Executor Entity: None
  • Execution Dimension: The dimension the sign is in
  • Execution Position: The center of the block the sign is in
  • Execution Rotation: (0, 0)
  • Execution Anchor: Feet
  • Reader: None

Text display entity

Template:Exclusive The context when the text in a Minecraft:text display entity is being changed

  • Execution Permission Level: 2
  • Executor Name: The name of the text display entity
  • Executor Entity: The text display entity
  • Execution Dimension: The dimension the text display entity is in
  • Execution Position: The position of the text display entity
  • Execution Rotation: The rotation of the text display entity
  • Execution Anchor: Feet
  • Reader: The text display entity

Item modifier

Template:Exclusive In Minecraft:item modifier, set_name and set_lore functions resolve the raw JSON text only if the entity specified with Template:Nbt does exist, with the following context:

  • Execution Permission Level: 2
  • Executor Name: The name of the entity specified with Template:Nbt
  • Executor Entity: The entity specified with Template:Nbt
  • Execution Dimension: The dimension that the entity specified with Template:Nbt is in
  • Execution Position: The position of the entity specified with Template:Nbt
  • Execution Rotation: The rotation of the entity specified with Template:Nbt
  • Execution Anchor: Feet
  • Reader: The entity specified with Template:Nbt

History

Template:HistoryTable

References

<references/>

Navigation

Template:Navbox Java Edition Template:Navbox Bedrock Edition

Minecraft:ja:コマンド文脈 Minecraft:zh:命令上下文