Help with an idea

I wanted to know if I can make an item that is a sword in the mainhand, and when you put it in offhand, it becomes a shield? It’s for a 1.21.1 datapack

Continue to help post