I'm wondering how to make an item give a potion buff or generic boost when held ONLY in the off-hand.
Thanks!
Arqade is a question and answer site for passionate videogamers on all platforms. It only takes a minute to sign up.
Sign up to join this communityI'm wondering how to make an item give a potion buff or generic boost when held ONLY in the off-hand.
Thanks!
Easiest way to accomplish a "generic boost" is through attributes, which can be set to only apply on a specific slot. This is a generator that allows adding attributes to items for specific slots. Here's an example command that gives you 10 extra health (5 hearts) when held only in the offhand:
/give @p minecraft:diamond_sword 1 0 {AttributeModifiers:[{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Slot:"offhand",Amount:10,Operation:0,UUIDMost:91328,UUIDLeast:135212}]}
There's this wiki page if you want to learn more about all the things attributes can do, and what do different operations are for.
Though there's a few things attributes do better than potions effects, they're a bit limited and may not be able to do what you want.
Alternatively, you could do this by detecting when the player is holding the item in their offhand slot (-106)
/scoreboard players tag @a[tag=OffhandHoldingItem] remove OffhandHoldingItem
/scoreboard players tag @a add OffhandHoldingItem {Inventory:[{Slot:-106b,id:"minecraft:diamond_sword",tag:{display:{Name:"Example Sword"}}}]}
You can then do anything you want to the player, such as:
/effect @a[tag=OffhandHoldingItem] jump_boost 1