メインコンテンツまでスキップ

itemUse

説明

プレイヤーがアイテムを使用したときにトリガーされるイベントです。使用したアイテムの詳細情報を取得できます。


トリガータグ

イベントがトリガーされたとき、プレイヤーに自動付与されるタグです。

タグ名説明
capi:item_useこのイベントがトリガーされたとき、プレイヤーに自動付与されます。
item_use.id:{アイテムID}使用したアイテムのIDがタグとして付与されます。
item_use.name:{アイテム名}使用したアイテムの名前がタグとして付与されます。
item_use.amount:{個数}使用したアイテムの個数がタグとして付与されます。
item_use.lore:{説明文}使用したアイテムの説明文(Lore)がタグとして付与されます。

使用例

基本的な検出

特定のアイテムを使用したプレイヤーを検出する例:

/execute as @a[tag=capi:item_use] run say アイテムを使用しました!

特定アイテムの使用検出

特定のアイテムが使用されたときの処理:

# エンダーパールの使用
/execute as @a[tag=item_use.id:minecraft:ender_pearl] run tellraw @s "§5エンダーパールでテレポート!"

# ポーションの使用
/execute as @a[tag=item_use.id:minecraft:potion] run tellraw @s "§dポーションを飲みました"

# 盾の使用
/execute as @a[tag=item_use.id:minecraft:shield] run scoreboard players add @s shield_uses 1

カスタムアイテムの検出

名前付きアイテムの使用を検出する例:

# 「魔法の杖」という名前のアイテム
/execute as @a[tag=item_use.name:魔法の杖] run summon lightning_bolt ~ ~ ~
/execute as @a[tag=item_use.name:魔法の杖] run tellraw @s "§6§l魔法の杖の力を解放した!"

# 「回復の薬」という名前のアイテム
/execute as @a[tag=item_use.name:回復の薬] run effect give @s instant_health 1 2
/execute as @a[tag=item_use.name:回復の薬] run effect give @s regeneration 10 1

アイテム使用回数の記録

特定のアイテムの使用回数をカウントする例:

# エンダーパール使用回数
/execute as @a[tag=item_use.id:minecraft:ender_pearl] run scoreboard players add @s ender_pearl_uses 1
/execute as @a[tag=item_use.id:minecraft:ender_pearl,scores={ender_pearl_uses=100}] run tellraw @s "§5エンダーパール使用100回達成!"

# トーテム使用回数
/execute as @a[tag=item_use.id:minecraft:totem_of_undying] run scoreboard players add @s totem_uses 1
/execute as @a[tag=item_use.id:minecraft:totem_of_undying] run tellraw @a [{"selector":"@s"},"§6 がトーテムを使用しました!"]

クールダウンシステム

アイテムの使用にクールダウンを設定する例:

# エンダーパールのクールダウン(10秒)
/execute as @a[tag=item_use.id:minecraft:ender_pearl,scores={pearl_cooldown=0}] run scoreboard players set @s pearl_cooldown 200
/execute as @a[tag=item_use.id:minecraft:ender_pearl,scores={pearl_cooldown=1..}] run tellraw @s "§cエンダーパールはクールダウン中です"
/execute as @a[tag=item_use.id:minecraft:ender_pearl,scores={pearl_cooldown=1..}] run give @s ender_pearl 1

# クールダウンを減らす(毎ティック実行)
scoreboard players remove @a[scores={pearl_cooldown=1..}] pearl_cooldown 1

スキルシステム

アイテム使用でスキルを発動する例:

# ファイアボール(火薬使用)
/execute as @a[tag=item_use.id:minecraft:gunpowder] run summon fireball ^ ^1 ^3 {direction:[0.0,-0.1,0.0],power:[0.0,0.0,0.1]}
/execute as @a[tag=item_use.id:minecraft:gunpowder] run playsound entity.blaze.shoot @s
/execute as @a[tag=item_use.id:minecraft:gunpowder] run tellraw @s "§c§lファイアボール!"

# テレポート(エンダーアイ使用)
/execute as @a[tag=item_use.id:minecraft:ender_eye] run tp @s ^ ^ ^10
/execute as @a[tag=item_use.id:minecraft:ender_eye] run particle portal ~ ~ ~ 1 1 1 1 100
/execute as @a[tag=item_use.id:minecraft:ender_eye] run playsound entity.enderman.teleport @s

Lore(説明文)を使った特殊効果

特定の説明文を持つアイテムの使用を検出する例:

# 「レジェンダリー」と説明に書かれたアイテム
/execute as @a[tag=item_use.lore:レジェンダリー] run effect give @s strength 60 1
/execute as @a[tag=item_use.lore:レジェンダリー] run effect give @s speed 60 1
/execute as @a[tag=item_use.lore:レジェンダリー] run tellraw @s "§6§lレジェンダリーアイテムの力を得た!"

# 「呪われた」と説明に書かれたアイテム
/execute as @a[tag=item_use.lore:呪われた] run effect give @s wither 10 1
/execute as @a[tag=item_use.lore:呪われた] run tellraw @s "§8呪いを受けた..."

アイテム個数の検出

使用したアイテムの個数に応じた処理:

# 64個スタックのアイテムを使用
/execute as @a[tag=item_use.amount:64] run tellraw @s "§eフルスタックのアイテムを使用しました"

# 1個のアイテムを使用
/execute as @a[tag=item_use.amount:1] run tellraw @s "§c最後のアイテムを使用しました"

食べ物の消費統計

食べ物の消費を記録する例:

# りんごを食べた
/execute as @a[tag=item_use.id:minecraft:apple] run scoreboard players add @s food_eaten 1
/execute as @a[tag=item_use.id:minecraft:apple] run tellraw @s "§e食べ物を食べました"

# 金のりんごを食べた
/execute as @a[tag=item_use.id:minecraft:golden_apple] run scoreboard players add @s golden_apples 1
/execute as @a[tag=item_use.id:minecraft:golden_apple] run tellraw @s "§6金のりんごを消費!"

使い捨てアイテムシステム

アイテムを使用すると消える特殊アイテム:

# 「瞬間移動の巻物」
/execute as @a[tag=item_use.name:瞬間移動の巻物] run tp @s 0 100 0
/execute as @a[tag=item_use.name:瞬間移動の巻物] run particle portal ~ ~ ~ 1 2 1 1 200
/execute as @a[tag=item_use.name:瞬間移動の巻物] run playsound entity.enderman.teleport @s
/execute as @a[tag=item_use.name:瞬間移動の巻物] run tellraw @s "§dスポーンにテレポートしました!"

アイテム使用制限

特定の条件下でのみアイテムを使用できるようにする例:

# VIP専用アイテム
/execute as @a[tag=item_use.name:VIP特典,tag=!vip] run tellraw @s "§cこのアイテムはVIP専用です"
/execute as @a[tag=item_use.name:VIP特典,tag=!vip] run give @s paper{display:{Name:'"VIP特典"'}} 1

# 特定エリアでのみ使用可能
/execute as @a[tag=item_use.name:エリア限定アイテム,scores={capi:location_x=100..200}] run tellraw @s "§aアイテムを使用しました"
/execute as @a[tag=item_use.name:エリア限定アイテム,scores={capi:location_x=..99}] run tellraw @s "§cこのエリアでは使用できません"
/execute as @a[tag=item_use.name:エリア限定アイテム,scores={capi:location_x=..99}] run give @s paper{display:{Name:'"エリア限定アイテム"'}} 1