Question About damage(double damage, Cause cause)


Excuse me if this is a nooby question, but why is the damage parameter for damage(double damage, Cause cause) a double? How would I specify how much damage to do to the entity in terms of health?


Because this will apply any and all DamageModifiers that may be applicable based on the Cause if it contains a DamageSource, when I do implement this method, it will be required that the provided cause contains a DamageSource as the root.

If you simply want the damage to be “absolute”, you set it in the DamageSource included in the Cause.

So what command would I use if I want to damage a player by 2 hearts and with the cause being another player hit him?

entity.damage(4.0D, Cause.of(EntityDamageSource.builder().source(otherPlayer).damageType(DamageTypes.ATTACK).build()));