You can:
On
Player Take Damage Event, place an
If Variable =, inside the chest, for the 1st slot, get a
Game Value from the
Values iron ingot (should be a name tag), hold it and type
Damage Event Cause and click on the Diamond Sword; and for the 2nd slot, get a
text, hold it and type
fall
. Now between the pistons, place a
Game Action: Cancel Event. Now the damage should be cancelled
.
Damage Event Cause is really useful for other stuff too, read its lore because it's helpful.