minecraft-commands-scripting
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMinecraft Commands & Scripting Skill
Minecraft 命令与脚本 Skill
Before editing, inspect the exact Minecraft version and execution context
(chat, function, command block, or RCON). Keep the requested scope and use only
the relevant examples. Check current release notes for version-sensitive syntax.
In 26.3,
maps source slots to destinations once; use to
repeat items or to clear unmatched slots.
/item replace/item fill/item override在编辑前,检查确切的 Minecraft 版本和执行上下文
(聊天、function、command block 或 RCON)。保持请求范围,并仅使用
相关示例。查阅当前版本说明,以确认对版本敏感的语法。
在 26.3 中,
会将源槽位一次性映射到目标槽位;使用 重复放置物品,
或使用 清除未匹配的槽位。
/item replace/item fill/item overrideCommand Syntax Conventions
命令语法约定
- — required argument
<required> - — optional argument
[optional] - — choose one
(a|b|c) - — repeating / multiple
... - Coordinates: = relative offset,
~= local (look-direction)^
- — 必需参数
<required> - — 可选参数
[optional] - — 选择其中一个
(a|b|c) - — 重复或多个
... - 坐标:= 相对偏移,
~= 局部坐标(朝向方向)^
Routing Boundaries
使用边界
- : the task is raw command chains, scoreboards, selector logic, or RCON command scripting.
Use when - : creating or editing full datapack structures and registries (
Do not use when).minecraft-datapack - : behavior depends on Java plugin or mod code (
Do not use when/minecraft-plugin-dev).minecraft-modding
- :任务是原始命令链、scoreboard、target selector 逻辑或 RCON 命令脚本。
Use when - :创建或编辑完整的 datapack 结构和 registry(
Do not use when)。minecraft-datapack - :行为依赖 Java plugin 或 mod 代码(
Do not use when/minecraft-plugin-dev)。minecraft-modding
Bundled References And Examples
内置参考与示例
- Execute cheat sheet:
references/execute-cheat-sheet.md - Selector cheat sheet:
references/selector-cheat-sheet.md - Example scripts: ,
scripts/examples/arena-countdown.mcfunction,scripts/examples/stopwatch-podium.mcfunction(one-time setup commands are called out in comments when needed)scripts/examples/rcon-backup-warning.sh
Use the cheat sheets when you need fast command recall without scanning this whole
skill file. Copy and adapt the example scripts as needed.
- Execute 速查表:
references/execute-cheat-sheet.md - Target Selector 速查表:
references/selector-cheat-sheet.md - 示例脚本:、
scripts/examples/arena-countdown.mcfunction、scripts/examples/stopwatch-podium.mcfunction(需要时,一次性设置命令会在注释中标明)scripts/examples/rcon-backup-warning.sh
当你需要快速回忆命令而不想浏览整个
skill 文件时,请使用这些速查表。根据需要复制并调整示例脚本。
Command reference
命令参考
Use references/command-reference.md for the
relevant command family. It includes version boundaries for item components,
attributes, text events, gamerules, and 26.x world clocks. Do not run example
blocks as a batch; each demonstrates a separate operation.
针对相关的命令系列,请使用 references/command-reference.md。
其中包含物品组件、属性、文本事件、gamerule 和 26.x 世界时钟的版本边界。
不要将示例块作为批次运行;每个示例都演示一项独立操作。
RCON Scripting
RCON 脚本
Connect to a Minecraft server remotely using RCON (enable in ):
server.propertiesproperties
undefined使用 RCON 远程连接 Minecraft 服务器(在 中启用):
server.propertiesproperties
undefinedserver.properties
server.properties
enable-rcon=true
rcon.password=your_password
rcon.port=25575
RCON is unencrypted. Keep the port bound to a trusted private network, VPN, or
localhost, and inject the password through a protected secret rather than a
command-line argument.enable-rcon=true
rcon.password=your_password
rcon.port=25575
RCON 未加密。将端口绑定到受信任的私有网络、VPN 或 localhost,
并通过受保护的 secret 注入密码,而不要将其作为命令行参数传入。Bash RCON script (using mcrcon
)
mcrconBash RCON 脚本(使用 mcrcon
)
mcrconbash
#!/usr/bin/env bash
set -euo pipefail
: "${MCRCON_PASS:?inject MCRCON_PASS from a protected secret}"
export MCRCON_HOST="${MCRCON_HOST:-127.0.0.1}"
export MCRCON_PORT="${MCRCON_PORT:-25575}"
restore_saves() {
mcrcon "save-on" >/dev/null || true
}
trap restore_saves EXIT INT TERMbash
#!/usr/bin/env bash
set -euo pipefail
: "${MCRCON_PASS:?inject MCRCON_PASS from a protected secret}"
export MCRCON_HOST="${MCRCON_HOST:-127.0.0.1}"
export MCRCON_PORT="${MCRCON_PORT:-25575}"
restore_saves() {
mcrcon "save-on" >/dev/null || true
}
trap restore_saves EXIT INT TERMSend command
Send command
mcrcon "say Server backup starting in 5 minutes"
sleep 300
mcrcon "save-off"
mcrcon "save-all flush"
mcrcon "say Server backup starting in 5 minutes"
sleep 300
mcrcon "save-off"
mcrcon "save-all flush"
Backup world
Backup world
rsync -av /path/to/server/world/ /backups/world_$(date +%Y%m%d_%H%M%S)/
mcrcon "save-on"
trap - EXIT INT TERM
mcrcon "say Backup complete!"
undefinedrsync -av /path/to/server/world/ /backups/world_$(date +%Y%m%d_%H%M%S)/
mcrcon "save-on"
trap - EXIT INT TERM
mcrcon "say Backup complete!"
undefinedPython RCON
Python RCON
python
import os
from mcrcon import MCRcon
with MCRcon("localhost", os.environ["MCRCON_PASS"], port=25575) as mcr:
response = mcr.command("list")
print(response)
# "There are 3 of a max of 20 players online: Steve, Alex, Notch"
players = response.split(": ")[1].split(", ") if ": " in response else []
print(f"Online players: {players}")python
import os
from mcrcon import MCRcon
with MCRcon("localhost", os.environ["MCRCON_PASS"], port=25575) as mcr:
response = mcr.command("list")
print(response)
# "There are 3 of a max of 20 players online: Steve, Alex, Notch"
players = response.split(": ")[1].split(", ") if ": " in response else []
print(f"Online players: {players}")Common Scripting Patterns
常见脚本模式
First-join setup (load and tick functions)
首次加入初始化(load 和 tick function)
mcfunction
undefinedmcfunction
undefinedload.mcfunction: create the objective
load.mcfunction: create the objective
scoreboard objectives add initialized dummy
scoreboard objectives add initialized dummy
tick.mcfunction: detect players who have not been initialized
tick.mcfunction: detect players who have not been initialized
execute as @a unless score @s initialized matches 1 run function mypack:on_first_join
execute as @a unless score @s initialized matches 1 run function mypack:on_first_join
on_first_join.mcfunction
on_first_join.mcfunction
scoreboard players set @s initialized 1
give @s minecraft:stone_sword
give @s minecraft:bread 16
tellraw @s {"text":"Welcome! Here's a starter kit.","color":"green"}
undefinedscoreboard players set @s initialized 1
give @s minecraft:stone_sword
give @s minecraft:bread 16
tellraw @s {"text":"Welcome! Here's a starter kit.","color":"green"}
undefinedDeath counter + respawn
死亡计数器与重生
mcfunction
undefinedmcfunction
undefinedtick.mcfunction — check deaths
tick.mcfunction — check deaths
execute as @a[scores={deaths=1..}] run function mypack:on_death
execute as @a[scores={deaths=1..}] run function mypack:on_death
on_death.mcfunction (separate file)
on_death.mcfunction (separate file)
scoreboard players reset @s deaths
scoreboard players add @s total_deaths 1
undefinedscoreboard players reset @s deaths
scoreboard players add @s total_deaths 1
undefinedProximity detection
距离检测
mcfunction
undefinedmcfunction
undefinedCheck if any player is within 5 blocks of a location
Check if any player is within 5 blocks of a location
execute if entity @a[x=10,y=64,z=10,distance=..5] run function mypack:player_nearby
undefinedexecute if entity @a[x=10,y=64,z=10,distance=..5] run function mypack:player_nearby
undefinedMath tricks (no fractions in scoreboards)
数学技巧(scoreboard 中没有小数)
mcfunction
undefinedmcfunction
undefinedMultiply @s.value by 1.5 using integer math (×3 then /2)
Multiply @s.value by 1.5 using integer math (×3 then /2)
scoreboard players operation @s result = @s value
scoreboard players operation @s result *= #three constants
scoreboard players operation @s result /= #two constants
scoreboard players operation @s result = @s value
scoreboard players operation @s result *= #three constants
scoreboard players operation @s result /= #two constants
Set #two and #three on load:
Set #two and #three on load:
scoreboard players set #two constants 2
scoreboard players set #two constants 2
scoreboard players set #three constants 3
scoreboard players set #three constants 3
---
---References
参考资料
- Minecraft Wiki — Commands: https://minecraft.wiki/w/Commands
- Minecraft Wiki — Target selectors: https://minecraft.wiki/w/Target_selectors
- Minecraft Wiki — NBT format: https://minecraft.wiki/w/NBT_format
- Minecraft Wiki — Raw JSON text: https://minecraft.wiki/w/Raw_JSON_text_format
- Minecraft Wiki — Scoreboard: https://minecraft.wiki/w/Scoreboard
- Execute command wiki: https://minecraft.wiki/w/Commands/execute
- Minecraft Wiki — 命令:https://minecraft.wiki/w/Commands
- Minecraft Wiki — Target selector:https://minecraft.wiki/w/Target_selectors
- Minecraft Wiki — NBT 格式:https://minecraft.wiki/w/NBT_format
- Minecraft Wiki — Raw JSON 文本:https://minecraft.wiki/w/Raw_JSON_text_format
- Minecraft Wiki — Scoreboard:https://minecraft.wiki/w/Scoreboard
- Execute 命令 Wiki:https://minecraft.wiki/w/Commands/execute