mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-22 16:29:16 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@20ec622 use correct types for preloading CraftRegistry PaperMC/Paper@627cc64 Adjust HAProxy's existance to log for console masters (#11433) PaperMC/Paper@01c4820 Call EntityDropItemEvent when a container item drops its contents (#11441) PaperMC/Paper@9c76642 Deprecate for removal Block#isValidTool (#11439) PaperMC/Paper@dd6d184 Remove redundant fillUsableCommands call (#11425) PaperMC/Paper@f33611c fix ItemStack#removeEnchantments creating non-stackable items (#11442) PaperMC/Paper@8f56db8 Add enchantWithLevels with tag specification (#11438) PaperMC/Paper@b7ab22d Fix console completions on invalid commands (#7603) PaperMC/Paper@41bc31b Update paperweight to 1.7.3 (#11445) PaperMC/Paper@e17eb6b Improve entity effect API (#11444) PaperMC/Paper@7b03141 Add startingBrewTime (#11406) PaperMC/Paper@355b1cb Add API for explosions to damage the explosion cause (#11180) PaperMC/Paper@6d7a438 Call bucket events for cauldrons (#7486) PaperMC/Paper@f9c7f2a Begin switching to JSpecify annotations (#11448) PaperMC/Paper@e3c8a8e Add PlayerInsertLecternBookEvent [1.20 port] (#7305) PaperMC/Paper@b410fe8 Configurable per-world void damage offset/damage(#11436) PaperMC/Paper@ea00be3 Do not NPE on uuid resolution in player profile (#11449) PaperMC/Paper@ba3c29b Finish converting all events to jspecify annotations PaperMC/Paper@e7e1ab5 Finish converting most of the undeprecated api to jspecify PaperMC/Paper@69ffbec Fix hex color check PaperMC/Paper@709f0f2 Use components properly in ProfileWhitelistVerifyEvent (#11456) PaperMC/Paper@fb76840 [ci skip] Add section on nullability annotations (#11461)
191 lines
9.7 KiB
Diff
191 lines
9.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Samsuik <kfian294ma4@gmail.com>
|
|
Date: Fri, 19 Apr 2024 22:20:03 +0100
|
|
Subject: [PATCH] Optimise paper explosions
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
|
|
index f696afd7e241bf1966a2d505b5d59bff824b43e4..611fc40fd7461f6d9cd9e737de71e702bf1f36c5 100644
|
|
--- a/src/main/java/net/minecraft/world/level/Explosion.java
|
|
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
|
|
@@ -101,7 +101,7 @@ public class Explosion {
|
|
}
|
|
}
|
|
|
|
- CACHED_RAYS = rayCoords.toDoubleArray();
|
|
+ CACHED_RAYS = sortExplosionRays(rayCoords); // Sakura - optimise paper explosions
|
|
}
|
|
|
|
private static final int CHUNK_CACHE_SHIFT = 2;
|
|
@@ -316,6 +316,39 @@ public class Explosion {
|
|
return (float)missedRays / (float)totalRays;
|
|
}
|
|
// Paper end - optimise collisions
|
|
+ // Sakura start - optimise paper explosions
|
|
+ /*
|
|
+ * Sort the explosion rays to better utilise the chunk and block cache.
|
|
+ * x + Vanilla Sorted
|
|
+ * z @ z 8 5
|
|
+ * - x 6 7 6 4
|
|
+ * 4 @ 5 7 @ 3
|
|
+ * 2 3 8 2
|
|
+ * 1 1
|
|
+ */
|
|
+ private static double[] sortExplosionRays(final it.unimi.dsi.fastutil.doubles.DoubleArrayList rayCoords) {
|
|
+ List<double[]> explosionRays = new ArrayList<>();
|
|
+
|
|
+ for (int i = 0; i < rayCoords.size(); i += 3) {
|
|
+ double[] ray = new double[3];
|
|
+ rayCoords.getElements(i, ray, 0, 3);
|
|
+ explosionRays.add(ray);
|
|
+ }
|
|
+
|
|
+ rayCoords.clear();
|
|
+ explosionRays.sort(java.util.Comparator.comparingDouble(vec -> {
|
|
+ double sign = Math.signum(vec[0]);
|
|
+ double dir = (sign - 1) / 2;
|
|
+ return sign + 8 + vec[2] * dir;
|
|
+ }));
|
|
+
|
|
+ double[] rays = new double[explosionRays.size() * 3];
|
|
+ for (int i = 0; i < explosionRays.size() * 3; i++) {
|
|
+ rays[i] = explosionRays.get(i / 3)[i % 3];
|
|
+ }
|
|
+ return rays;
|
|
+ }
|
|
+ // Sakura end - optimise paper explosions
|
|
|
|
public static DamageSource getDefaultDamageSource(Level world, @Nullable Entity source) {
|
|
return world.damageSources().explosion(source, Explosion.getIndirectSourceEntityInternal(source));
|
|
@@ -439,6 +472,16 @@ public class Explosion {
|
|
int j;
|
|
|
|
// Paper start - collision optimisations
|
|
+ // Sakura start - optimise paper explosions
|
|
+ if (initialCache.resistance <= (this.radius * 1.3f) && this.interactsWithBlocks()) {
|
|
+ this.searchForBlocks(blockCache, initialCache);
|
|
+ }
|
|
+ this.locateAndImpactEntities(blockCache);
|
|
+ this.clearBlockCache();
|
|
+ }
|
|
+
|
|
+ protected final void searchForBlocks(ca.spottedleaf.moonrise.patches.collisions.ExplosionBlockCache[] blockCache, final ca.spottedleaf.moonrise.patches.collisions.ExplosionBlockCache initialCache) {
|
|
+ // Sakura end - optimise paper explosions
|
|
for (int ray = 0, len = CACHED_RAYS.length; ray < len;) {
|
|
ca.spottedleaf.moonrise.patches.collisions.ExplosionBlockCache cachedBlock = initialCache;
|
|
|
|
@@ -510,25 +553,64 @@ public class Explosion {
|
|
}
|
|
|
|
// Paper - optimise collisions
|
|
- float f2 = this.radius * 2.0F;
|
|
+ // Sakura start - optimise paper explosions
|
|
+ }
|
|
|
|
- i = Mth.floor(this.x - (double) f2 - 1.0D);
|
|
- j = Mth.floor(this.x + (double) f2 + 1.0D);
|
|
+ protected final AABB getExplosionBounds(float f2) {
|
|
+ // Sakura - moved into locateAndImpactEntities
|
|
+
|
|
+ int i = Mth.floor(this.x - (double) f2 - 1.0D);
|
|
+ int j = Mth.floor(this.x + (double) f2 + 1.0D);
|
|
int l = Mth.floor(this.y - (double) f2 - 1.0D);
|
|
int i1 = Mth.floor(this.y + (double) f2 + 1.0D);
|
|
int j1 = Mth.floor(this.z - (double) f2 - 1.0D);
|
|
int k1 = Mth.floor(this.z + (double) f2 + 1.0D);
|
|
- List<Entity> list = this.level.getEntities(excludeSourceFromDamage ? this.source : null, new AABB((double) i, (double) l, (double) j1, (double) j, (double) i1, (double) k1), (com.google.common.base.Predicate<Entity>) entity -> entity.isAlive() && !entity.isSpectator()); // Paper - Fix lag from explosions processing dead entities, Allow explosions to damage source
|
|
+ return new AABB((double) i, (double) l, (double) j1, (double) j, (double) i1, (double) k1);
|
|
+ }
|
|
+
|
|
+ protected final void locateAndImpactEntities(ca.spottedleaf.moonrise.patches.collisions.ExplosionBlockCache[] blockCache) {
|
|
+ float f2 = this.radius * 2.0F;
|
|
Vec3 vec3d = new Vec3(this.x, this.y, this.z);
|
|
- Iterator iterator = list.iterator();
|
|
|
|
// Paper start - optimise collisions
|
|
final BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos();
|
|
// Paper end - optimise collisions
|
|
|
|
- while (iterator.hasNext()) {
|
|
- Entity entity = (Entity) iterator.next();
|
|
+ int minSection = ca.spottedleaf.moonrise.common.util.WorldUtil.getMinSection(this.level);
|
|
+ int maxSection = ca.spottedleaf.moonrise.common.util.WorldUtil.getMaxSection(this.level);
|
|
+
|
|
+ int minChunkX = Mth.floor(this.x - f2) >> 4;
|
|
+ int maxChunkX = Mth.floor(this.x + f2) >> 4;
|
|
+ int minChunkY = Mth.clamp(Mth.floor(this.y - f2) >> 4, minSection, maxSection);
|
|
+ int maxChunkY = Mth.clamp(Mth.floor(this.y + f2) >> 4, minSection, maxSection);
|
|
+ int minChunkZ = Mth.floor(this.z - f2) >> 4;
|
|
+ int maxChunkZ = Mth.floor(this.z + f2) >> 4;
|
|
|
|
+ ca.spottedleaf.moonrise.patches.chunk_system.level.entity.EntityLookup entityLookup = this.level.moonrise$getEntityLookup();
|
|
+ for (int chunkX = minChunkX; chunkX <= maxChunkX; ++chunkX) {
|
|
+ for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; ++chunkZ) {
|
|
+ ca.spottedleaf.moonrise.patches.chunk_system.level.entity.ChunkEntitySlices chunk = entityLookup.getChunk(chunkX, chunkZ);
|
|
+ if (chunk == null) continue; // empty slice
|
|
+
|
|
+ for (int chunkY = minChunkY; chunkY <= maxChunkY; ++chunkY) {
|
|
+ this.impactEntities(blockCache, blockPos, f2, vec3d, chunk.getSectionEntities(chunkY));
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ protected final void impactEntities(ca.spottedleaf.moonrise.patches.collisions.ExplosionBlockCache[] blockCache, BlockPos.MutableBlockPos blockPos, float f2, Vec3 vec3d, Entity[] entities) {
|
|
+ for (int i = 0; i < entities.length; i++) {
|
|
+ Entity entity = entities[i];
|
|
+ if (entity == null) break; // end of entity section
|
|
+ this.impactEntity(blockCache, blockPos, f2, vec3d, entity);
|
|
+ if (entity != entities[i]) i--; // entities can be removed mid-explosion
|
|
+ }
|
|
+ }
|
|
+
|
|
+ protected final void impactEntity(ca.spottedleaf.moonrise.patches.collisions.ExplosionBlockCache[] blockCache, BlockPos.MutableBlockPos blockPos, float f2, Vec3 vec3d, Entity entity) {
|
|
+ if (entity.isAlive() && !entity.isSpectator() && (!this.excludeSourceFromDamage || entity != this.source)) { // Paper - Fix lag from explosions processing dead entities
|
|
+ // Sakura end - optimise paper explosions
|
|
if (!entity.ignoreExplosion(this)) {
|
|
double d7 = Math.sqrt(entity.distanceToSqr(vec3d)) / (double) f2;
|
|
|
|
@@ -553,7 +635,7 @@ public class Explosion {
|
|
// - Damaging EntityEnderDragon does nothing
|
|
// - EntityEnderDragon hitbock always covers the other parts and is therefore always present
|
|
if (entity instanceof EnderDragonPart) {
|
|
- continue;
|
|
+ return; // Sakura - optimise paper explosions
|
|
}
|
|
|
|
entity.lastDamageCancelled = false;
|
|
@@ -561,9 +643,10 @@ public class Explosion {
|
|
seenFraction = (double)this.getBlockDensity(vec3d, entity, blockCache, blockPos); // Paper - optimise collisions
|
|
|
|
if (entity instanceof EnderDragon) {
|
|
+ AABB bounds = this.getExplosionBounds(f2); // Sakura - optimise paper explosions
|
|
for (EnderDragonPart entityComplexPart : ((EnderDragon) entity).subEntities) {
|
|
// Calculate damage separately for each EntityComplexPart
|
|
- if (list.contains(entityComplexPart)) {
|
|
+ if (entityComplexPart.getBoundingBox().intersects(bounds)) { // Sakura - optimise paper explosions
|
|
entityComplexPart.hurt(this.damageSource, this.damageCalculator.getEntityDamageAmount(this, entity));
|
|
}
|
|
}
|
|
@@ -577,7 +660,7 @@ public class Explosion {
|
|
}
|
|
|
|
if (entity.lastDamageCancelled) { // SPIGOT-5339, SPIGOT-6252, SPIGOT-6777: Skip entity if damage event was cancelled
|
|
- continue;
|
|
+ return; // Sakura - optimise paper explosions
|
|
}
|
|
// CraftBukkit end
|
|
} else { seenFraction = (double)this.getBlockDensity(vec3d, entity, blockCache, blockPos); } // Paper - optimise collisions
|
|
@@ -620,6 +703,11 @@ public class Explosion {
|
|
}
|
|
}
|
|
}
|
|
+ // Sakura start - optimise paper explosions
|
|
+ }
|
|
+
|
|
+ protected void clearBlockCache() {
|
|
+ // Sakura end - optimise paper explosions
|
|
// Paper start - optimise collisions
|
|
this.blockCache = null;
|
|
this.chunkPosCache = null;
|