I managed to do it by overriding the "doHurtTarget" method.
@Override
public boolean doHurtTarget(Entity target) {
this.swing(InteractionHand.MAIN_HAND);
return super.doHurtTarget(target);
}
As of version 1.20.1, they wrote the entire network section, so networkEvent no longer exists. If you specify exactly what you wanted to do, I could help you better.