マイクラJAVA1.21.10コマンドについての質問です左手に鉄インゴットを1つ持っているときにエメラルド1つ配布というコマンドを作りたいです。また、そのあと左手の鉄インゴットを手持ちから消したいです。ボタンを押したときに発動したいです。何度も試してもうまくいきません。教えていただきたいです。

Java

1件の回答

回答を書く

1086064

2026-02-14 02:55

+ フォロー

先の回答者さんのコマンドは1.20.4以前のものなので1.21.10では動作しません。



1.21.10ならこうです。

インパルス 無条件 動力が必要

/execute as @p if items entity @s weapon.offhand iron_ingot run give @s emerald



チェーン 無条件 常時実行

/execute as @p if items entity @s weapon.offhand iron_ingot run item modify entity @s weapon.offhand {function:set_count,count:-1,add:1b}



これは左手に持っている鉄インゴットの数に関わらず正しく動作します。ただし、@pを使っている関係上コマンドブロックの近くに他のプレイヤーがいると正しく動かない可能性があります。

これはボタンだとどうしようもないので、近くに他のプレイヤーがいても正しく動作するようにしたいならボタンではなく看板コマンドを使う必要があります。



以下は看板コマンドを使う場合の例です。

/give @p oak_sign[block_entity_data={id:sign,is_waxed:1b,front_text:{messages:[{text:\u0026quot;[看板ショップ]\u0026quot;,color:yellow,bold:1b,click_event:{action:run_command,command:\u0026quot;execute if items entity @s weapon.offhand iron_ingot run give @s emerald\u0026quot;}},[{sprite:\u0026quot;item/iron_ingot\u0026quot;,bold:1b,color:white,click_event:{action:run_command,command:\u0026quot;execute if items entity @s weapon.offhand iron_ingot run item modify entity @s weapon.offhand {function:set_count,count:-1,add:1b}\u0026quot;}},{text:\u0026quot; × 1 → \u0026quot;},{sprite:\u0026quot;item/emerald\u0026quot;},{text:\u0026quot; × 1\u0026quot;}],[{sprite:\u0026quot;item/iron_ingot\u0026quot;,color:white,bold:1b},{text:\u0026quot;を左手に持って\u0026quot;,color:green}],{text:\u0026quot;右クリック!\u0026quot;,color:green,bold:1b}]}}]

うったえる有益だ(0シェアするブックマークする

関連質問

Copyright © 2026 AQ188.com All Rights Reserved.

博識 著作権所有