Minecraft Wiki:Sandbox

How to calculate damage
 * 1) The actual damage
 * 2) The protection

If the damage source is a melee attack There are 5 effects F**k
 * 1) The weapon and it's strength
 * 2) For Swords, the calculation is that the sword does 3 damage itself + 1 dmg from fist. Then you add a damage amount for the quality of the sword
 * 3) Wood, Gold, 0
 * 4) Stone, 1
 * 5) Iron, 2
 * 6) Diamond, 3
 * 7) Netherite, 4
 * 8) The enchantment
 * 9) Sharpness does 0.5 dmg by itself and adds 0.5 dmg for each level (0.5xlvl+0.5)
 * 10) So sharpness 1 would do +1 dmg, 2 would do +1.5 dmg, 3 is +2, 5 is +3, 101 is +50
 * 11) Smite and BOA adds 2.5 attack dmg if it attacks the correct target (Undead for Smite and (Cave) Spider, Bee, Silverfish, and Endermite for BOA)
 * 12) These are incompatible with each other and Sharpness
 * 13) If used with commands, the effects stack
 * 14) Level 1 would do +2.5, 2 would do +5, 10 would do +25, etc
 * 15) Whether the player does a critical attack
 * 16) Simply, criticals add x1.5 damage to the attack
 * 17) The effect the player has (Stength/Weakness)
 * 18) Strength does +3 attack per level
 * 19) A sharpness 3 iron sword with strength 2 and critical would do ((6+6)x1.5)x1
 * 20) The cooldown effect
 * 21) An inportant note is that the order in which the attacks are calculated are this (((Original dmg+Effect)xCrit (if no crit, x1)+Enchantment)xcooldown effect (full charges)