minecraft-commands-scripting について
minecraft-commands-scriptingは、Minecraftのコマンドチェーン、スコアボード、セレクター、RCONスクリプトの資料と例を提供し、コマンド処理や自動化に役立ちます。
主な機能
- 01コマンド構文とバージョン上の注意
- 02executeとセレクターの早見表
- 03スコアボードとプレイヤー検出の例
- 04BashとPythonのRCON例
- 05応用可能なコマンドスクリプト例
活用シーン
- 01バージョンに応じたコマンドチェーンの作成
- 02スコアボードで死亡数や初回参加処理を実装
- 03セレクターによる近接判定の作成
- 04RCON経由でサーバーコマンドを遠隔実行
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ jahrome907/ minecraft-agent-skills --skill minecraft-commands-scriptingインストール後、Claude Code で/minecraft-commands-scriptingを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
references/command-reference.mdexecute-cheat-sheet.mdselector-cheat-sheet.mdscripts/examples/arena-countdown.mcfunctionrcon-backup-warning.shstopwatch-podium.mcfunction詳細
Minecraft コマンドとスクリプトのスキル
編集する前に、Minecraft の正確なバージョンと実行コンテキスト(チャット、関数、コマンドブロック、RCON)を確認してください。依頼された範囲を守り、関連する例のみを使用してください。構文がバージョンに依存する場合は、最新のリリースノートを確認してください。
コマンド構文の規則
<required>— 必須の引数[optional]— 省略可能な引数(a|b|c)— いずれか1つを選択...— 繰り返し/複数- 座標:
~= 相対オフセット、^= ローカル座標(視線方向)
適用範囲
使用する場合:生のコマンドチェーン、スコアボード、セレクターのロジック、または RCON コマンドのスクリプト作成がタスクの場合に使用します。使用しない場合:データパック全体の構造やレジストリの作成・編集(minecraft-datapack)がタスクの場合は使用しません。使用しない場合:動作が Java プラグインまたは Mod のコードに依存する(minecraft-plugin-dev/minecraft-modding)場合は使用しません。
同梱のリファレンスと例
- Execute チートシート:
references/execute-cheat-sheet.md - セレクターのチートシート:
references/selector-cheat-sheet.md - スクリプト例:
scripts/examples/arena-countdown.mcfunction、scripts/examples/stopwatch-podium.mcfunction、scripts/examples/rcon-backup-warning.sh(必要な場合は、初回のみ実行するセットアップコマンドがコメントで示されています)
このスキルファイル全体を確認せずにコマンドをすばやく確認するには、チートシートを使用してください。必要に応じて、スクリプト例をコピーして調整してください。
コマンドリファレンス
該当するコマンドファミリーについては、references/command-reference.md を参照してください。アイテムコンポーネント、属性、テキストイベント、ゲームルール、26.x のワールドクロックに関するバージョンの境界が記載されています。例のブロックをまとめて実行しないでください。それぞれ別の操作を示しています。
RCON スクリプト
RCON を使用して Minecraft サーバーにリモート接続します(server.properties で有効にしてください)。
# server.properties
enable-rcon=true
rcon.password=your_password
rcon.port=25575
RCON は暗号化されません。ポートは信頼できるプライベートネットワーク、VPN、または localhost にバインドし、コマンドライン引数ではなく、保護されたシークレットを介してパスワードを渡してください。
Bash RCON スクリプト(mcrcon を使用)
#!/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 TERM
# Send command
mcrcon "say Server backup starting in 5 minutes"
sleep 300
mcrcon "save-off"
mcrcon "save-all flush"
# 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!"
Python RCON
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}")
よくあるスクリプトのパターン
初回参加時のセットアップ(ロード関数とティック関数)
# load.mcfunction: create the objective
scoreboard objectives add initialized dummy
# tick.mcfunction: detect players who have not been initialized
execute as @a unless score @s initialized matches 1 run function mypack:on_first_join
# 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"}
死亡カウンターとリスポーン
# tick.mcfunction — check deaths
execute as @a[scores={deaths=1..}] run function mypack:on_death
# on_death.mcfunction (separate file)
scoreboard players reset @s deaths
scoreboard players add @s total_deaths 1
近接検知
# 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
計算の工夫(スコアボードで分数を使わない)
# 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
# Set #two and #three on load:
# scoreboard players set #two constants 2
# scoreboard players set #three constants 3
参考資料
- Minecraft Wiki — コマンド:https://minecraft.wiki/w/Commands
- Minecraft Wiki — ターゲットセレクター: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 — スコアボード:https://minecraft.wiki/w/Scoreboard
- Execute コマンドの Wiki:https://minecraft.wiki/w/Commands/execute