指令:
⑴ /tag @s add 吸血
⑵ /scoreboard objectives add 耐久 dummy
⑶循环
effect @a[tag=吸血,hasitem={item=iron_sword,quantity=0,location=slot.hotbar,slot=8}] instant_health 1 0 truereplaceitem entity @a[tag=吸血,hasitem={item=iron_sword,quantity=0,location=slot.hotbar,slot=8}] slot.hotbar 8 keep iron_sword 1 250 {"minecraft:item_lock":{"mode":"lock_in_slot"}}
⑷ 循环
scoreboard players add @a[tag=吸血] 耐久 0
⑸ scoreboard players add @a[tag=吸血,scores={耐久=0}] 耐久 300
⑹ effect @a[tag=吸血,scores={耐久=1..},hasitem={item=iron_sword,quantity=0,location=slot.hotbar,slot=8}] instant_health 1 0 true
⑺ scoreboard players remove @a[tag=吸血,scores={耐久=1..},hasitem={item=iron_sword,quantity=0,location=slot.hotbar,slot=8}] 耐久 1
⑻ tag @a[tag=吸血,scores={耐久=0},hasitem={item=iron_sword,quantity=0,location=slot.hotbar,slot=8}] remove 吸血
⑼ replaceitem entity @a[tag=吸血,scores={耐久=1..},hasitem={item=iron_sword,quantity=0,location=slot.hotbar,slot=8}] slot.hotbar 8 keep iron_sword 1 250 {"minecraft:item_lock":{"mode":"lock_in_slot"}}
10.execute @a[tag=吸血,scores={耐久=1..},hasitem={item=iron_sword,quantity=1,location=slot.hotbar,slot=8}] ~ ~ ~ titleraw @s actionbar {"rawtext":[{"text":"§l§o§b吸血剑耐久§r:"},{"score":{"name":"@s","objective":"耐久"}}]}