dragonfly
dragonfly copied to clipboard
Fix explosion damage on players
Calculations taken from decompiled java edition, but it seems to match bedrock values (Edited slightly to make the original code easier to read)
float d = this.radius * 2.0F;
double dist = entity.distanceTo(vec3d); // Same as `entity.Sub(vec3d).Len()`
if (dist / d <= 1.0D) {
// double d8 = entity.getX() - this.x;
// double d9 = (entity instanceof EntityTNTPrimed ? entity.getY() : entity.getEyeY()) - this.y;
// double d10 = entity.getZ() - this.z;
// double d11 = Math.sqrt(d8 * d8 + d9 * d9 + d10 * d10); // Same as `dist`
if (dist != 0.0D) {
double exposure = (double) getSeenPercent(vec3d, entity); // Same as `exposure(vec3d, entity)`
double impact = (1.0D - dist) * exposure;
entity.hurt(this.getDamageSource(), (float) ((int) ((impact * impact + impact) / 2.0D * 7.0D * (double) d + 1.0D)));