Skip to content

Commit

Permalink
Fix explosions calculation getting stuck (PaperMC#11061)
Browse files Browse the repository at this point in the history
Co-authored-by: Nassim Jahnke <[email protected]>
  • Loading branch information
electronicboy and kennytv authored Jul 12, 2024
1 parent 0e02aa5 commit c6e9579
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions patches/server/0991-Moonrise-optimisation-patches.patch
Original file line number Diff line number Diff line change
Expand Up @@ -30816,7 +30816,7 @@ index bd20bea7f76a7307f1698fb2dfef37125032d166..141b748abe80402731cdaf14a3d36aa7

// Paper start - Affects Spawning API
diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
index bff83fe413c7baef4ba56a3270ea4463a58c792f..3ca6e0a948194d1c4528472d4b96cb26bc0946d8 100644
index bff83fe413c7baef4ba56a3270ea4463a58c792f..a248d859cbce48f4a34c4771a7acffc17d7edc84 100644
--- a/src/main/java/net/minecraft/world/level/Explosion.java
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
@@ -75,6 +75,247 @@ public class Explosion {
Expand Down Expand Up @@ -31067,7 +31067,7 @@ index bff83fe413c7baef4ba56a3270ea4463a58c792f..3ca6e0a948194d1c4528472d4b96cb26
public static DamageSource getDefaultDamageSource(Level world, @Nullable Entity source) {
return world.damageSources().explosion(source, Explosion.getIndirectSourceEntityInternal(source));
}
@@ -167,68 +408,108 @@ public class Explosion {
@@ -167,68 +408,107 @@ public class Explosion {
}
// CraftBukkit end
this.level.gameEvent(this.source, (Holder) GameEvent.EXPLODE, new Vec3(this.x, this.y, this.z));
Expand Down Expand Up @@ -31176,13 +31176,12 @@ index bff83fe413c7baef4ba56a3270ea4463a58c792f..3ca6e0a948194d1c4528472d4b96cb26
- set.add(blockposition.relative(direction.getOpposite()));
+ // Paper end - collision optimisations
+ BlockState iblockdata = cachedBlock.blockState; // Paper - optimise collisions
+ if (!iblockdata.isDestroyable()) continue; // Paper - Protect Bedrock and End Portal/Frames from being destroyed
+ // Paper - collision optimisations
+
+ // Paper start - collision optimisations
+ power -= cachedBlock.resistance;
+
+ if (power > 0.0f && cachedBlock.shouldExplode == null) {
+ if (power > 0.0f && cachedBlock.shouldExplode == null && iblockdata.isDestroyable()) { // Paper - Protect Bedrock and End Portal/Frames from being destroyed
+ // note: we expect shouldBlockExplode to be pure with respect to power, as Vanilla currently is.
+ // basically, it is unused, which allows us to cache the result
+ final boolean shouldExplode = this.damageCalculator.shouldBlockExplode((Explosion)(Object)this, this.level, cachedBlock.immutablePos, cachedBlock.blockState, power);
Expand Down Expand Up @@ -31224,7 +31223,7 @@ index bff83fe413c7baef4ba56a3270ea4463a58c792f..3ca6e0a948194d1c4528472d4b96cb26
float f2 = this.radius * 2.0F;

i = Mth.floor(this.x - (double) f2 - 1.0D);
@@ -241,6 +522,10 @@ public class Explosion {
@@ -241,6 +521,10 @@ public class Explosion {
Vec3 vec3d = new Vec3(this.x, this.y, this.z);
Iterator iterator = list.iterator();

Expand All @@ -31235,15 +31234,15 @@ index bff83fe413c7baef4ba56a3270ea4463a58c792f..3ca6e0a948194d1c4528472d4b96cb26
while (iterator.hasNext()) {
Entity entity = (Entity) iterator.next();

@@ -257,6 +542,7 @@ public class Explosion {
@@ -257,6 +541,7 @@ public class Explosion {
d8 /= d11;
d9 /= d11;
d10 /= d11;
+ final double seenFraction; // Paper - optimise collisions
if (this.damageCalculator.shouldDamageEntity(this, entity)) {
// CraftBukkit start

@@ -272,6 +558,8 @@ public class Explosion {
@@ -272,6 +557,8 @@ public class Explosion {

entity.lastDamageCancelled = false;

Expand All @@ -31252,7 +31251,7 @@ index bff83fe413c7baef4ba56a3270ea4463a58c792f..3ca6e0a948194d1c4528472d4b96cb26
if (entity instanceof EnderDragon) {
for (EnderDragonPart entityComplexPart : ((EnderDragon) entity).subEntities) {
// Calculate damage separately for each EntityComplexPart
@@ -280,16 +568,21 @@ public class Explosion {
@@ -280,16 +567,21 @@ public class Explosion {
}
}
} else {
Expand All @@ -31277,7 +31276,7 @@ index bff83fe413c7baef4ba56a3270ea4463a58c792f..3ca6e0a948194d1c4528472d4b96cb26
double d13;

if (entity instanceof LivingEntity) {
@@ -327,7 +620,11 @@ public class Explosion {
@@ -327,7 +619,11 @@ public class Explosion {
}
}
}
Expand All @@ -31290,7 +31289,7 @@ index bff83fe413c7baef4ba56a3270ea4463a58c792f..3ca6e0a948194d1c4528472d4b96cb26
}

public void finalizeExplosion(boolean particles) {
@@ -547,14 +844,14 @@ public class Explosion {
@@ -547,14 +843,14 @@ public class Explosion {
private BlockInteraction() {}
}
// Paper start - Optimize explosions
Expand Down

0 comments on commit c6e9579

Please sign in to comment.