9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-22 00:09:20 +00:00
Files
SakuraMC/patches/server/0018-Optimise-explosions-in-protected-regions.patch
2024-10-31 12:31:59 +00:00

46 lines
2.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
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/ServerExplosion.java b/src/main/java/net/minecraft/world/level/ServerExplosion.java
index 10432b31acd047ac2aa8581f2ee863254ec8d1eb..b07c2eb8cc3cc54e8ab72c5ed3d6d7623416e7fb 100644
--- a/src/main/java/net/minecraft/world/level/ServerExplosion.java
+++ b/src/main/java/net/minecraft/world/level/ServerExplosion.java
@@ -345,6 +345,22 @@ public class ServerExplosion implements 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.center.x, this.center.y, this.center.z);
+ List<org.bukkit.block.Block> 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 ServerExplosion(ServerLevel world, @Nullable Entity entity, @Nullable DamageSource damageSource, @Nullable ExplosionDamageCalculator behavior, Vec3 pos, float power, boolean createFire, Explosion.BlockInteraction destructionType) {
this.level = world;
@@ -441,6 +457,11 @@ public class ServerExplosion implements Explosion {
return ret;
}
// Sakura end - optimise paper explosions
+ // Sakura start - optimise protected explosions
+ if (!this.isRegionUnprotected()) {
+ return ret;
+ }
+ // Sakura end - optimise protected explosions
// only ~1/3rd of the loop iterations in vanilla will result in a ray, as it is iterating the perimeter of
// a 16x16x16 cube