Command Context
The command context (execution context, command source, command source stack) is the set of caller and environment parameters used for command execution and text component parsing.
Parameters
Eight parameters: permission level, executor (executor name + executor entity), environment (execution dimension, position, rotation, anchor), and output feedback.
Behavior
/function runs inherit the executor parameters, environment parameters, and permission level — but NOT the output feedback. In Java single-player/LAN, function commands are capped at permission level 2 (even when the /function call ran at a higher level); servers can raise the cap via config.
- Bedrock:
/schedule-planned functions also inherit executor/environment/permission.
Static vs Dynamic Parameters (Java)
In Java, the executor name and all environment parameters are static once set: modifying the executor entity mid-function (e.g. /tp on the sheep used by execute at @n[type=sheep] run function test) does not change later commands' position/rotation/dimension.
/execute freezes the dimension and rotation; align, in, positioned <coords>, facing, rotated <angles> freeze position/rotation; anchored freezes a dynamic position to the entity's feet/eyes (no effect on a static position).
- Example: chat-typed
/execute at @s run ... has dynamic position+rotation but static dimension; /execute positioned ~ ~ ~ run ... has everything static.
In Bedrock, several parameters stay dynamic (fetched live from an entity): chat/WebSocket commands (position, rotation, dimension from the player), command block minecarts (position/rotation), entity-event/script/animation-controller/NPC commands (name, position, rotation, dimension), /execute itself (name), at .../positioned as ... (position), at .../rotated as ... (rotation). Dynamic positions use the mount's Y when the entity rides (e.g. player on minecart → player X/Z, minecart Y). If the depended-on entity is gone, defaults apply: name = "", dimension = empty, position = (0,0,0), rotation = (0,0) (e.g. execute run say hi in a command block says nothing; a /schedule whose executor died before running fails because the dimension is empty).
Parameters in Detail
- Permission level — not modifiable by
/execute. Function commands run at most at level 2 (configurable on servers).
- Executor — may be empty (command blocks). Used by
/msg, /say (sender name), @s, default targets of /tp//kill, player-requiring commands (/clear, /gamemode, /playsound), Java-only /trigger//teammsg, and Java eye-height anchoring. Modified by as, on, and summon subcommands (Java sets name+entity together; Bedrock only the entity).
- Execution dimension — used for all coordinates, distance/box-restricted selectors (also
x/y/z in Java), /locate. Modified by at and in.
- Execution position — origin of relative coordinates; base for local coordinates (Java: plus the anchor's eye offset),
/facing starts, /locate, and default positions of /summon//spawnpoint//playsound. Modified by align, at, positioned, in.
- Execution rotation — coordinate system for local coordinates and
~ rotations in /tp//spawnpoint. Modified by at, facing, rotated.
- Execution anchor (Java only) — feet or eyes (feet = execution position; eyes = position + eye height of the executor entity). Used for local coordinate origin,
/execute facing start, /tp ... facing ... start, /rotate ... facing ... start. Modified by anchored. (Bedrock has no anchor parameter; anchored directly sets the position, freezing it if dynamic.)
- Output feedback — receives command success counts (command blocks, minecarts, scripts).
/execute store adds feedback while keeping existing feedback (existing cannot be cleared). Functions don't inherit feedback.
Contexts per Scenario
- Server console — level 4; name "Server"; no entity; dimension of world spawn (or Overworld); position = world-spawn block's NW-lower corner / (0,0,0); rotation (0,0); anchor feet; no feedback.
- Server-executed functions (
load/tick tags, tick.json, /schedule) — same as console but level 2/1.
- Player (chat / WebSocket / dev console) — player's level; name = player name ("External"/"DevConsole" for WebSocket/dev console); entity = the player; dimension/position/rotation dynamic; anchor feet; no feedback.
- Command block — level 2/1; name = custom name or
@/!; no entity; command block's dimension/center; its rotation / (0,0); receives success count.
- Command block minecart — like command block, but entity = the minecart, position/rotation dynamic.
- Sign (Java, clicking a sign command) — level 2; executor = the player; position = sign block center; rotation (0,0).
- Advancement reward function (Java) — level 2; executor = the rewarded player at their position/rotation.
- Enchantment
run_function effect (Java) — level 2; executor = the effect entity at the effect position/rotation.
- Bedrock entity-command contexts (entity events, scripts, animation controllers, NPCs) — level 1; name/position/rotation/dimension dynamic from the entity; scripts return success count.
- Bedrock dimension-command (scripts) — level 1; name "script engine"; position (0,0,0); rotation (0,0); returns success count.
- Test environment (Java) — level 2; name "Server"; world-spawn dimension/position; rotation (0,0).
Text Component Parsing
Text components resolve relative/local coordinates and selectors using the command context (output feedback is unused). score components with name: "*" show the reader's own score.
- Command-invoked components inherit the command's context:
/bossbar, /scoreboard, /team (reader: executor @s); /tellraw, /title (readers: each receiving player).
- Written book opened by a player (Java) — player's context; reader = the player.
- Written book placed on a lectern (Java) — level 2; name "Lectern"; no entity; lectern dimension/center; rotation (0,0); no reader.
- Sign text via NBT (Java) — level 2; name "Sign"; sign center; rotation (0,0).
- Text display entity (Java) — level 2; executor = the text display entity itself.
- Item modifiers
set_name/set_lore (Java) — when the entity field's entity exists, it is the executor (level 2) and reader.
1---2name: minecraft-command-context3description: Minecraft Command Context 命令上下文:Parameters 参数(permission level 权限等级、executor 执行者名称+实体、environment 环境 维度/位置/旋转/锚点、output feedback 输出反馈)、Behavior 行为(/function 继承执行者/环境/权限 不继承输出反馈、函数命令权限上限2)、Static vs Dynamic Parameters 静态vs动态参数(Java 执行者名称和环境参数静态、/execute 冻结维度和旋转、align/in/positioned/facing/rotated 冻结位置/旋转、anchored 锚定动态位置到脚/眼、Bedrock 多参数动态获取)、Parameters in Detail 参数详情(Permission level 不可修改、Executor 执行者 空/命令方块、Execution dimension 维度 用于坐标/距离选择器、Execution position 位置 相对坐标原点、Execution rotation 旋转 局部坐标系、Execution anchor 锚点 脚/眼 Java独有、Output feedback 输出反馈 成功计数)、Contexts per Scenario 各场景上下文(Server console 级别4、Server-executed functions 级别2/1、Player 玩家聊天/动态、Command block 级别2/1、Command block minecart 动态、Sign 标志 级别2、Advancement reward function 级别2、Enchantment run_function 级别2、Bedrock entity-command 级别1 动态、Test environment 级别2)、Text Component Parsing 文本组件解析(继承命令上下文、score name:* 显示读者分数、命令调用组件、Written book/Sign/Text display entity/Item modifiers)。4---56# Command Context78The command context (execution context, command source, command source stack) is the set of caller and environment parameters used for command execution and text component parsing.910## Parameters1112Eight parameters: **permission level**, **executor** (executor name + executor entity), **environment** (execution dimension, position, rotation, anchor), and **output feedback**.1314### Behavior1516- `/function` runs inherit the executor parameters, environment parameters, and permission level — but NOT the output feedback. In Java single-player/LAN, function commands are capped at permission level 2 (even when the `/function` call ran at a higher level); servers can raise the cap via config.17- Bedrock: `/schedule`-planned functions also inherit executor/environment/permission.1819### Static vs Dynamic Parameters (Java)2021In Java, the executor name and all environment parameters are **static** once set: modifying the executor entity mid-function (e.g. `/tp` on the sheep used by `execute at @n[type=sheep] run function test`) does not change later commands' position/rotation/dimension.2223- `/execute` freezes the dimension and rotation; `align`, `in`, `positioned <coords>`, `facing`, `rotated <angles>` freeze position/rotation; `anchored` freezes a dynamic position to the entity's feet/eyes (no effect on a static position).24- Example: chat-typed `/execute at @s run ...` has dynamic position+rotation but static dimension; `/execute positioned ~ ~ ~ run ...` has everything static.2526In Bedrock, several parameters stay **dynamic** (fetched live from an entity): chat/WebSocket commands (position, rotation, dimension from the player), command block minecarts (position/rotation), entity-event/script/animation-controller/NPC commands (name, position, rotation, dimension), `/execute` itself (name), `at ...`/`positioned as ...` (position), `at ...`/`rotated as ...` (rotation). Dynamic positions use the mount's Y when the entity rides (e.g. player on minecart → player X/Z, minecart Y). If the depended-on entity is gone, defaults apply: name = "", dimension = empty, position = (0,0,0), rotation = (0,0) (e.g. `execute run say hi` in a command block says nothing; a `/schedule` whose executor died before running fails because the dimension is empty).2728## Parameters in Detail2930- **Permission level** — not modifiable by `/execute`. Function commands run at most at level 2 (configurable on servers).31- **Executor** — may be empty (command blocks). Used by `/msg`, `/say` (sender name), `@s`, default targets of `/tp`/`/kill`, player-requiring commands (`/clear`, `/gamemode`, `/playsound`), Java-only `/trigger`/`/teammsg`, and Java eye-height anchoring. Modified by `as`, `on`, and `summon` subcommands (Java sets name+entity together; Bedrock only the entity).32- **Execution dimension** — used for all coordinates, distance/box-restricted selectors (also `x`/`y`/`z` in Java), `/locate`. Modified by `at` and `in`.33- **Execution position** — origin of relative coordinates; base for local coordinates (Java: plus the anchor's eye offset), `/facing` starts, `/locate`, and default positions of `/summon`/`/spawnpoint`/`/playsound`. Modified by `align`, `at`, `positioned`, `in`.34- **Execution rotation** — coordinate system for local coordinates and `~` rotations in `/tp`/`/spawnpoint`. Modified by `at`, `facing`, `rotated`.35- **Execution anchor** (Java only) — feet or eyes (feet = execution position; eyes = position + eye height of the executor entity). Used for local coordinate origin, `/execute facing` start, `/tp ... facing ...` start, `/rotate ... facing ...` start. Modified by `anchored`. (Bedrock has no anchor parameter; `anchored` directly sets the position, freezing it if dynamic.)36- **Output feedback** — receives command success counts (command blocks, minecarts, scripts). `/execute store` adds feedback while keeping existing feedback (existing cannot be cleared). Functions don't inherit feedback.3738## Contexts per Scenario3940- **Server console** — level 4; name "Server"; no entity; dimension of world spawn (or Overworld); position = world-spawn block's NW-lower corner / (0,0,0); rotation (0,0); anchor feet; no feedback.41- **Server-executed functions** (`load`/`tick` tags, `tick.json`, `/schedule`) — same as console but level 2/1.42- **Player (chat / WebSocket / dev console)** — player's level; name = player name ("External"/"DevConsole" for WebSocket/dev console); entity = the player; dimension/position/rotation dynamic; anchor feet; no feedback.43- **Command block** — level 2/1; name = custom name or `@`/`!`; no entity; command block's dimension/center; its rotation / (0,0); receives success count.44- **Command block minecart** — like command block, but entity = the minecart, position/rotation dynamic.45- **Sign (Java, clicking a sign command)** — level 2; executor = the player; position = sign block center; rotation (0,0).46- **Advancement reward function (Java)** — level 2; executor = the rewarded player at their position/rotation.47- **Enchantment `run_function` effect (Java)** — level 2; executor = the effect entity at the effect position/rotation.48- **Bedrock entity-command contexts (entity events, scripts, animation controllers, NPCs)** — level 1; name/position/rotation/dimension dynamic from the entity; scripts return success count.49- **Bedrock dimension-command (scripts)** — level 1; name "script engine"; position (0,0,0); rotation (0,0); returns success count.50- **Test environment (Java)** — level 2; name "Server"; world-spawn dimension/position; rotation (0,0).5152## Text Component Parsing5354Text components resolve relative/local coordinates and selectors using the command context (output feedback is unused). `score` components with `name: "*"` show the reader's own score.5556- **Command-invoked components** inherit the command's context: `/bossbar`, `/scoreboard`, `/team` (reader: executor `@s`); `/tellraw`, `/title` (readers: each receiving player).57- **Written book opened by a player (Java)** — player's context; reader = the player.58- **Written book placed on a lectern (Java)** — level 2; name "Lectern"; no entity; lectern dimension/center; rotation (0,0); no reader.59- **Sign text via NBT (Java)** — level 2; name "Sign"; sign center; rotation (0,0).60- **Text display entity (Java)** — level 2; executor = the text display entity itself.61- **Item modifiers `set_name`/`set_lore` (Java)** — when the `entity` field's entity exists, it is the executor (level 2) and reader.