Fix explosions calculation getting stuck (#11061)

Co-authored-by: Nassim Jahnke <nassim@njahnke.dev>
This commit is contained in:
Shane Freeder 2024-07-12 08:16:03 +01:00 committed by GitHub
parent 0e02aa5b8e
commit c6e9579688
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -30816,7 +30816,7 @@ index bd20bea7f76a7307f1698fb2dfef37125032d166..141b748abe80402731cdaf14a3d36aa7
// Paper start - Affects Spawning API // 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 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 --- a/src/main/java/net/minecraft/world/level/Explosion.java
+++ b/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 { @@ -75,6 +75,247 @@ public class Explosion {
@ -31067,7 +31067,7 @@ index bff83fe413c7baef4ba56a3270ea4463a58c792f..3ca6e0a948194d1c4528472d4b96cb26
public static DamageSource getDefaultDamageSource(Level world, @Nullable Entity source) { public static DamageSource getDefaultDamageSource(Level world, @Nullable Entity source) {
return world.damageSources().explosion(source, Explosion.getIndirectSourceEntityInternal(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 // CraftBukkit end
this.level.gameEvent(this.source, (Holder) GameEvent.EXPLODE, new Vec3(this.x, this.y, this.z)); this.level.gameEvent(this.source, (Holder) GameEvent.EXPLODE, new Vec3(this.x, this.y, this.z));
@ -31176,13 +31176,12 @@ index bff83fe413c7baef4ba56a3270ea4463a58c792f..3ca6e0a948194d1c4528472d4b96cb26
- set.add(blockposition.relative(direction.getOpposite())); - set.add(blockposition.relative(direction.getOpposite()));
+ // Paper end - collision optimisations + // Paper end - collision optimisations
+ BlockState iblockdata = cachedBlock.blockState; // Paper - optimise collisions + 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 - collision optimisations
+ +
+ // Paper start - collision optimisations + // Paper start - collision optimisations
+ power -= cachedBlock.resistance; + 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. + // 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 + // 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); + final boolean shouldExplode = this.damageCalculator.shouldBlockExplode((Explosion)(Object)this, this.level, cachedBlock.immutablePos, cachedBlock.blockState, power);
@ -31224,7 +31223,7 @@ index bff83fe413c7baef4ba56a3270ea4463a58c792f..3ca6e0a948194d1c4528472d4b96cb26
float f2 = this.radius * 2.0F; float f2 = this.radius * 2.0F;
i = Mth.floor(this.x - (double) f2 - 1.0D); 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); Vec3 vec3d = new Vec3(this.x, this.y, this.z);
Iterator iterator = list.iterator(); Iterator iterator = list.iterator();
@ -31235,7 +31234,7 @@ index bff83fe413c7baef4ba56a3270ea4463a58c792f..3ca6e0a948194d1c4528472d4b96cb26
while (iterator.hasNext()) { while (iterator.hasNext()) {
Entity entity = (Entity) iterator.next(); Entity entity = (Entity) iterator.next();
@@ -257,6 +542,7 @@ public class Explosion { @@ -257,6 +541,7 @@ public class Explosion {
d8 /= d11; d8 /= d11;
d9 /= d11; d9 /= d11;
d10 /= d11; d10 /= d11;
@ -31243,7 +31242,7 @@ index bff83fe413c7baef4ba56a3270ea4463a58c792f..3ca6e0a948194d1c4528472d4b96cb26
if (this.damageCalculator.shouldDamageEntity(this, entity)) { if (this.damageCalculator.shouldDamageEntity(this, entity)) {
// CraftBukkit start // CraftBukkit start
@@ -272,6 +558,8 @@ public class Explosion { @@ -272,6 +557,8 @@ public class Explosion {
entity.lastDamageCancelled = false; entity.lastDamageCancelled = false;
@ -31252,7 +31251,7 @@ index bff83fe413c7baef4ba56a3270ea4463a58c792f..3ca6e0a948194d1c4528472d4b96cb26
if (entity instanceof EnderDragon) { if (entity instanceof EnderDragon) {
for (EnderDragonPart entityComplexPart : ((EnderDragon) entity).subEntities) { for (EnderDragonPart entityComplexPart : ((EnderDragon) entity).subEntities) {
// Calculate damage separately for each EntityComplexPart // Calculate damage separately for each EntityComplexPart
@@ -280,16 +568,21 @@ public class Explosion { @@ -280,16 +567,21 @@ public class Explosion {
} }
} }
} else { } else {
@ -31277,7 +31276,7 @@ index bff83fe413c7baef4ba56a3270ea4463a58c792f..3ca6e0a948194d1c4528472d4b96cb26
double d13; double d13;
if (entity instanceof LivingEntity) { if (entity instanceof LivingEntity) {
@@ -327,7 +620,11 @@ public class Explosion { @@ -327,7 +619,11 @@ public class Explosion {
} }
} }
} }
@ -31290,7 +31289,7 @@ index bff83fe413c7baef4ba56a3270ea4463a58c792f..3ca6e0a948194d1c4528472d4b96cb26
} }
public void finalizeExplosion(boolean particles) { public void finalizeExplosion(boolean particles) {
@@ -547,14 +844,14 @@ public class Explosion { @@ -547,14 +843,14 @@ public class Explosion {
private BlockInteraction() {} private BlockInteraction() {}
} }
// Paper start - Optimize explosions // Paper start - Optimize explosions