From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Samsuik Date: Fri, 3 May 2024 15:18:58 +0100 Subject: [PATCH] Optimise explosions in protected regions diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java index 3ad6f5f19c9fae2f00c662971eaa613c1a0ddbcf..da423a9211dd72bc531d7f0f65aab08b5c44f39c 100644 --- a/src/main/java/net/minecraft/world/level/Explosion.java +++ b/src/main/java/net/minecraft/world/level/Explosion.java @@ -353,6 +353,22 @@ public class Explosion { return rays; } // Sakura end - optimise paper explosions + // Sakura start - optimise explosion protected regions + protected final boolean isRegionUnprotected() { + // optimisation: We check if a plugin has cancelled the event or cleared the blockList. + // It tells us if the result was thrown away, so we can avoid the block searching logic. + // As a side effect the event is called twice which may interfere with some plugins. + if (this.source != null && this.level.sakuraConfig().cannons.explosion.optimiseProtectedRegions) { + Location location = new Location(this.level.getWorld(), this.x, this.y, this.z); + List blocks = new ObjectArrayList<>(1); + blocks.add(location.getBlock()); + EntityExplodeEvent event = CraftEventFactory.callEntityExplodeEvent(this.source, blocks, 0.0f, this.blockInteraction); + return !event.isCancelled() && !event.blockList().isEmpty(); + } + + return true; + } + // Sakura end - optimise explosion protected regions public static DamageSource getDefaultDamageSource(Level world, @Nullable Entity source) { return world.damageSources().explosion(source, Explosion.getIndirectSourceEntityInternal(source)); @@ -486,7 +502,7 @@ public class Explosion { // Paper start - collision optimisations // Sakura start - optimise paper explosions - if (initialCache.resistance <= (this.radius * 1.3f) && this.interactsWithBlocks()) { + if (initialCache.resistance <= (this.radius * 1.3f) && this.interactsWithBlocks() && this.isRegionUnprotected()) { // Sakura - optimise protected explosions this.searchForBlocks(blockCache, initialCache); } this.locateAndImpactEntities(blockCache);