Skip to main content
added 3 characters in body; edited title
Source Link
pinckerman
  • 43.9k
  • 23
  • 132
  • 197

How can iI swap between offhand and mainhand with commands?

Of course I know that if I press F key, offhand and mainhand's item swaps. But I want to do this with command. 
I tried:

execute as @a[nbt={Inventory:[{id:"minecraft:snowball",Slot:-106b}]}] at @s run tag @s add snowball
execute as @a[tag=snowball] at @s run item replace entity @s weapon.mainhand from entity @s weapon.offhand
execute as @a[tag=snowball] at @s run item replace entity @s weapon.offhand from entity @s weapon.mainhand

But I don't think this is possible.

How can i swap between offhand and mainhand?

Of course I know that if I press F key, offhand and mainhand's item swaps. But I want to do this with command. I tried

execute as @a[nbt={Inventory:[{id:"minecraft:snowball",Slot:-106b}]}] at @s run tag @s add snowball
execute as @a[tag=snowball] at @s run item replace entity @s weapon.mainhand from entity @s weapon.offhand
execute as @a[tag=snowball] at @s run item replace entity @s weapon.offhand from entity @s weapon.mainhand

But I don't think this is possible.

How can I swap between offhand and mainhand with commands?

Of course I know that if I press F key, offhand and mainhand's item swaps. But I want to do this with command. 
I tried:

execute as @a[nbt={Inventory:[{id:"minecraft:snowball",Slot:-106b}]}] at @s run tag @s add snowball
execute as @a[tag=snowball] at @s run item replace entity @s weapon.mainhand from entity @s weapon.offhand
execute as @a[tag=snowball] at @s run item replace entity @s weapon.offhand from entity @s weapon.mainhand

But I don't think this is possible.

Source Link

How can i swap between offhand and mainhand?

Of course I know that if I press F key, offhand and mainhand's item swaps. But I want to do this with command. I tried

execute as @a[nbt={Inventory:[{id:"minecraft:snowball",Slot:-106b}]}] at @s run tag @s add snowball
execute as @a[tag=snowball] at @s run item replace entity @s weapon.mainhand from entity @s weapon.offhand
execute as @a[tag=snowball] at @s run item replace entity @s weapon.offhand from entity @s weapon.mainhand

But I don't think this is possible.