Item exchange using a block

Basically when the player is inside a loom I want certain items to be transmuted into banners with otherwise the same data so that they can be designed with patterns and then turned back when the player exits the loom inventory. However I only know how to check when they open the inventory and originally I didn't mind and was just going to have it then create a raycast that checks if the player is still looking at a loom, and then when they weren't it would turn the stuff back into normal items. But if the player is out of the inventory and looking at the loom they can still place the items and I don't want that.
Continue to help post