Do you mean,
if player holds a sword
then player can’t open villagers, chests, ...
Because if so, that is already the case when your hitting with your sword. And I think this is enough. You’re not supposed to be placing blocks with your sword either way :)