9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-30 12:19:08 +00:00
Files
SakuraMC/sakura-server/minecraft-patches/features/0010-Optimise-explosions-in-protected-regions.patch
2025-09-29 01:59:24 +01:00

46 lines
2.3 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/net/minecraft/world/level/ServerExplosion.java b/net/minecraft/world/level/ServerExplosion.java
index c3c90cc17c4f1ebcaddffea4087929e3708aa22f..000e1ffcebd6f529133af1edbed6da80b9848e75 100644
--- a/net/minecraft/world/level/ServerExplosion.java
+++ b/net/minecraft/world/level/ServerExplosion.java
@@ -309,6 +309,22 @@ public class ServerExplosion implements Explosion {
return (float)missedRays / (float)totalRays;
}
// Paper end - collisions optimisations
+ // 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) {
+ final Location location = new Location(this.level.getWorld(), this.center.x, this.center.y, this.center.z);
+ final List<org.bukkit.block.Block> blocks = new ObjectArrayList<>(1);
+ blocks.add(location.getBlock());
+ final org.bukkit.event.entity.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 level,
@@ -416,6 +432,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