Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix explosion damage on players #869

Merged
merged 4 commits into from
Nov 17, 2024

Conversation

Flonja
Copy link
Contributor

@Flonja Flonja commented May 4, 2024

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)));

server/block/explosion.go Outdated Show resolved Hide resolved
@Flonja Flonja requested a review from T14Raptor May 5, 2024 22:22
dist := pos.Sub(pos).Len()
if dist >= d {
dist := pos.Sub(explosionPos).Len()
if dist > d || dist == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this logic with the dist == 0 doesn't make sense, but given that this is extremely unlikely to happen and matches mc code I'm okay with it.

@TwistedAsylumMC TwistedAsylumMC merged commit 77eb52b into df-mc:master Nov 17, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants