Skip to content

Commit 1c257eb

Browse files
authored
Prevent NaN velocity and crash for 0 powered explosion (#13366)
Prevents a 0 explosion_power explosion at the exact location of an entity from producing a NaN delta due to dividing 0 by 0. Such velocities lead to faulty client state and server crashes.
1 parent 92ed3f0 commit 1c257eb

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

paper-server/patches/features/0001-Moonrise-optimisation-patches.patch

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30173,7 +30173,7 @@ index 93110c815abe7baef61b1eaacfe28ebb1fc821f7..564c5064ec105a4f59476f2d21d3664b
3017330173
ChunkAccess getChunk(int x, int z, ChunkStatus chunkStatus, boolean requireChunk);
3017430174

3017530175
diff --git a/net/minecraft/world/level/ServerExplosion.java b/net/minecraft/world/level/ServerExplosion.java
30176-
index c132a3bfff7cf020e7fe4be616daa763b83e4b25..1c521f9f32340cf75310686c90777e521ac3ae5c 100644
30176+
index d0286d25ea641ceb7642213067bc737175ea9d29..222ae660d2a74f708f13ba1e715bc810f433f48f 100644
3017730177
--- a/net/minecraft/world/level/ServerExplosion.java
3017830178
+++ b/net/minecraft/world/level/ServerExplosion.java
3017930179
@@ -62,6 +62,249 @@ public class ServerExplosion implements Explosion {
@@ -30576,7 +30576,7 @@ index c132a3bfff7cf020e7fe4be616daa763b83e4b25..1c521f9f32340cf75310686c90777e52
3057630576
}
3057730577

3057830578
private void hurtEntities() {
30579-
@@ -346,6 +628,14 @@ public class ServerExplosion implements Explosion {
30579+
@@ -347,6 +629,14 @@ public class ServerExplosion implements Explosion {
3058030580
}
3058130581

3058230582
public int explode() {
@@ -30591,7 +30591,7 @@ index c132a3bfff7cf020e7fe4be616daa763b83e4b25..1c521f9f32340cf75310686c90777e52
3059130591
this.level.gameEvent(this.source, GameEvent.EXPLODE, this.center);
3059230592
List<BlockPos> list = this.calculateExplodedPositions();
3059330593
this.hurtEntities();
30594-
@@ -360,6 +650,13 @@ public class ServerExplosion implements Explosion {
30594+
@@ -361,6 +651,13 @@ public class ServerExplosion implements Explosion {
3059530595
this.createFire(list);
3059630596
}
3059730597

@@ -30605,7 +30605,7 @@ index c132a3bfff7cf020e7fe4be616daa763b83e4b25..1c521f9f32340cf75310686c90777e52
3060530605
return list.size();
3060630606
}
3060730607

30608-
@@ -449,12 +746,12 @@ public class ServerExplosion implements Explosion {
30608+
@@ -450,12 +747,12 @@ public class ServerExplosion implements Explosion {
3060930609
// Paper start - Optimize explosions
3061030610
private float getBlockDensity(Vec3 vec3d, Entity entity) {
3061130611
if (!this.level.paperConfig().environment.optimizeExplosions) {

paper-server/patches/sources/net/minecraft/world/level/ServerExplosion.java.patch

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
}
6565

6666
d3 += d * 0.3F;
67-
@@ -176,8 +_,8 @@
67+
@@ -176,27 +_,64 @@
6868
int floor3 = Mth.floor(this.center.y + f + 1.0);
6969
int floor4 = Mth.floor(this.center.z - f - 1.0);
7070
int floor5 = Mth.floor(this.center.z + f + 1.0);
@@ -74,8 +74,9 @@
7474
+ for (Entity entity : list) { // Paper - used in loop
7575
if (!entity.ignoreExplosion(this)) {
7676
double d = Math.sqrt(entity.distanceToSqr(this.center)) / f;
77+
+ if (Double.isNaN(d)) d = Double.POSITIVE_INFINITY; // Paper - avoid infinite damage/velocity when distance and radius are 0 - +inf is chosen as 0+h / 0 is evaluated to +inf for all positive h, which distanceSqrt complies with
7778
if (!(d > 1.0)) {
78-
@@ -185,18 +_,54 @@
79+
Vec3 vec3 = entity instanceof PrimedTnt ? entity.position() : entity.getEyePosition();
7980
Vec3 vec31 = vec3.subtract(this.center).normalize();
8081
boolean shouldDamageEntity = this.damageCalculator.shouldDamageEntity(this, entity);
8182
float knockbackMultiplier = this.damageCalculator.getKnockbackMultiplier(entity);

0 commit comments

Comments
 (0)