How can i make my carrot on a stick switch my armour to something different when right clicked?

Solution 1:

You can set up a a scoreboard objective that keeps track of uses of carrots on a stick with this command:

/scoreboard objectives add carrots minecraft.used:minecraft.carrot_on_a_stick

You could then execute these commands in a function that executes every tick:

#tag players with strong armor who used a carrot on a stick
tag @a[scores={carrots=1..},nbt={Inventory:[{Slot:100b,id:"minecraft:iron_boots",<strong NBT>},{Slot:101b,id:"minecraft:iron_leggings",<strong NBT>},{Slot:102b,id:"minecraft:iron_chestplate",<strong NBT>},{Slot:103b,id:"minecraft:iron_helmet",<strong NBT>}]}] add strongArmor

#tag players with molten armor who used a carrot on a stick
tag @a[scores={carrots=1..},nbt={Inventory:[{Slot:100b,id:"minecraft:iron_boots",<molten NBT>},{Slot:101b,id:"minecraft:iron_leggings",<molten NBT>},{Slot:102b,id:"minecraft:iron_chestplate",<molten NBT>},{Slot:103b,id:"minecraft:iron_helmet",<molten NBT>}]}] add moltenArmor

#set the armor of any player who used a carrot on a stick and has the moltenArmor tag to strong armor
replaceitem entity @a[tag=moltenArmor] armor.head <strong helmet>
replaceitem entity @a[tag=moltenArmor] armor.chest <strong chestplate>
replaceitem entity @a[tag=moltenArmor] armor.legs <strong leggings>
replaceitem entity @a[tag=moltenArmor] armor.feet <strong boots>

#set the armor of any player who used a carrot on a stick and has the strongArmor tag to molten armor
replaceitem entity @a[tag=strongArmor] armor.head <molten helmet>
replaceitem entity @a[tag=strongArmor] armor.chest <molten chestplate>
replaceitem entity @a[tag=strongArmor] armor.legs <molten leggings>
replaceitem entity @a[tag=strongArmor] armor.feet <molten boots>

#remove the tags
tag remove @a strongArmor
tag remove @a moltenArmor

#set the scoreboard objective "carrots" back to 0 for all players
scoreboard players set @a carrots 0