mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-24 01:09:16 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@7fbb827 Finish API patches PaperMC/Paper@8a37f93 62 PaperMC/Paper@2055809 117 PaperMC/Paper@0b75522 194 PaperMC/Paper@ec05cb8 279 PaperMC/Paper@0bc9aee 385 PaperMC/Paper@27e29cc 487/1053 PaperMC/Paper@083bd9e 531/1053 PaperMC/Paper@ed2ea45 538 PaperMC/Paper@ba163e1 585/1053 PaperMC/Paper@8731266 650/1053 PaperMC/Paper@52b49fb 788/1053 PaperMC/Paper@33b36cd update some patches PaperMC/Paper@14c0336 922 PaperMC/Paper@a399f23 956 PaperMC/Paper@4140de2 960 PaperMC/Paper@6d4e235 988 PaperMC/Paper@6a34750 Move unapplied patches to the back PaperMC/Paper@3c04f9f Fix a few compile errors PaperMC/Paper@0d3ce2d Fix more compile issues PaperMC/Paper@a308c7c Fix more compile issues PaperMC/Paper@69d1d0a Pretend to fix compile errors PaperMC/Paper@547f09d Some work on the ItemMend events PaperMC/Paper@184a943 Adopt previous commit changes in API PaperMC/Paper@5442bff Make it compile PaperMC/Paper@038f8d9 Fixup and deprecate player profiles in ping event PaperMC/Paper@66f7b67 Fix body equipmentslot and effect enum PaperMC/Paper@38b3182 Updated Upstream (Bukkit/CraftBukkit) PaperMC/Paper@df633e5 DataConverter 1.21 PaperMC/Paper@f569389 Update ConcurrentUtil PaperMC/Paper@5fca3ae update generated API PaperMC/Paper@188cff2 remove old vanilla goals PaperMC/Paper@ffe310a remove api that was scheduled for removal PaperMC/Paper@730882f Chunk System and Starlight WIP PaperMC/Paper@512fd08 Update Gradle Wrapper to v8.8 PaperMC/Paper@097284d Bump tiny-remapper to 0.10.3 PaperMC/Paper@ee9b820 Update more optimization patches PaperMC/Paper@5d834b1 rebuild patches PaperMC/Paper@4bc15f1 Updated Upstream (Bukkit/CraftBukkit) PaperMC/Paper@0b6701d Revert DamageSource#getCausingEntity to vanilla PaperMC/Paper@5bd7f4e Update AbstractArrow item method implementations for 1.20.6 (#10885) PaperMC/Paper@fb511c6 Fix Player#sendBlockState (#10855) PaperMC/Paper@b420038 Fix ItemMeta#removeEnchantments (#10886) PaperMC/Paper@a835ad1 Merge remote-tracking branch 'origin/dev/1.21' into dev/1.21 PaperMC/Paper@04dad71 Improve enchantWithLevels logic PaperMC/Paper@0008fa1 Add back more optimization patches PaperMC/Paper@56b5b7d Fix max chunk status checks PaperMC/Paper@c1aefee correctly change enchantment registry to a 'delayed' version PaperMC/Paper@d41636f Add back RecipeIterator fixes patch (#10887) PaperMC/Paper@7df4725 Configurable damage tick when blocking with shield (#10877) PaperMC/Paper@3555a77 Properly forward DispenseEvent #getItem to saddle PaperMC/Paper@e339ec2 Deprecate BlockData#getDestroySpeed for removal PaperMC/Paper@b090c65 Remove unnecessary changes from chunk status fix PaperMC/Paper@5e7cd07 add some generated typed/tag keys PaperMC/Paper@5a5412c Owen fixing stuff!!! PaperMC/Paper@7240d9d Restore functionality to sand dupe setting PaperMC/Paper@f873bce Fix NPE in V3808 PaperMC/Paper@1f8e7a7 address compile and test issue (#10890) PaperMC/Paper@60f3bd8 De-deprecate BlockData#getDestroySpeed PaperMC/Paper@752f957 Add back more patches PaperMC/Paper@dc684c6 Remove bad server.scheduleOnMain disconnect calls from old patches PaperMC/Paper@c84a3b5 Remove fully dropped patches PaperMC/Paper@d8c2980 Add Adventure API to ServerLinks (#10891) PaperMC/Paper@ec4c712 update 'improve mass craft perf' patch PaperMC/Paper@e1c0033 Updated Upstream (Bukkit/CraftBukkit) PaperMC/Paper@fbc2a55 Update Wither#canTravelThroughPortals PaperMC/Paper@167961e call EntityDamageItemEvent for thorns PaperMC/Paper@106dbae Fix getAddress connection check PaperMC/Paper@d9111cc Registry Modification API (#10893) PaperMC/Paper@f8ee0a0 Fix implementations of ChunkHolder#getChunkIfPresent PaperMC/Paper@61b85e4 Fix legacy cb version in remapper PaperMC/Paper@de8220c Update ChunkMap#distanceManager mapping patch PaperMC/Paper@8dfb85c Enchantment and GameEvent Registry builders (#10889) PaperMC/Paper@fb762cf remove remaining reference to 'pgive' PaperMC/Paper@a7f6633 make EntityPortalReadyEvent#setTargetWorld work again PaperMC/Paper@152f4fe Add back improved watchdog support patch PaperMC/Paper@13992b1 Make chunk system loggers calm down a bit PaperMC/Paper@bf8552f Delegate ItemStack (#10852) PaperMC/Paper@b3e072a Fix `hasFiredAsync` parameter when `AsyncPlayerSendCommandsEvent` is called (#10896) PaperMC/Paper@21c9a7c Rebuild patches PaperMC/Paper@b9f7098 [ci skip] Fix javadoc mistake in EnchantmentRegistryEntry.Builder (#10898) PaperMC/Paper@b4b8208 Fix NPE for Jukebox#setRecord PaperMC/Paper@4514f41 Correct duplicate attribute check (#10901) PaperMC/Paper@090775e Use ItemStack.empty() when air is passed into constructor PaperMC/Paper@7bbe682 Fix CraftWorld#isChunkGenerated PaperMC/Paper@126f6d7 Remove getUnloadingChunkHolder check PaperMC/Paper@d23825a Add missing null check to getFullChunkIfLoaded PaperMC/Paper@3b1c85b Execute chunk tasks while waiting for chunk load in isChunkGenerated PaperMC/Paper@4ea696f Add ticket for chunk load in isChunkGenerated PaperMC/Paper@250e78c Re-add fixlight command PaperMC/Paper@c0268ca Copy missing diff from old chunk system patch PaperMC/Paper@38428c0 Cleanup MCUtils patch for chunk system PaperMC/Paper@f4ddd4a Fix ChunkHolder#getFullChunkNow returning non-null when it should not PaperMC/Paper@e0d9d60 Add debug for chunk system unload crash PaperMC/Paper@2df432f Re-add chunk system debug commands PaperMC/Paper@cf60574 Fix jukebox playable component not being applied on item meta (#10922) PaperMC/Paper@666bc4d Experimental annotation changes (#10914) PaperMC/Paper@bab07e0 Validate speed for tool component rule (#10923) PaperMC/Paper@2118196 Fixes exception log messages getting dropped during bootstrap (#10935) PaperMC/Paper@8b1d26d Fix diff in sprint interruption option (Closes #10939) PaperMC/Paper@0a1b133 Revert "Fixes exception log messages getting dropped during bootstrap (#10935)" (Closes #10945) PaperMC/Paper@a0fad76 Fix base damage for trident (#10948) PaperMC/Paper@d64be7e Fix NPE of AbstractArrow#getWeapon (#10933) PaperMC/Paper@081146c Validate using_converts_to for food component (#10931) PaperMC/Paper@0409a68 deprecate and update some entity tags (#10932) PaperMC/Paper@9cd0201 Preserve velocity for fireball (#10934) PaperMC/Paper@19105a9 Fix unload queue storing chunks in wrong sections PaperMC/Paper@77c763b Fix PlayerShearBlockEvent drops ignored for Pumpkin (#10956) PaperMC/Paper@76c2f16 Fix wrong diff applying delta twice (#10959) PaperMC/Paper@812701d Do not crash when an exp orb attempts to mend an unrepairable item PaperMC/Paper@19eefe9 Fix SoundEffects only to players diff (#10966) PaperMC/Paper@95aa440 Add missing effect cause and deprecate PATROL_CAPTAIN cause (#10958) PaperMC/Paper@b2e5587 Expose LivingEntity#canUseSlot (#10930) PaperMC/Paper@97afc9a Fix StackOverflowError for new dispenser interaction (#10949) PaperMC/Paper@5ae4758 Fix speed for launched trident using api (#10936) PaperMC/Paper@897ece4 Call EntityPortalEnterEvent on endgateways and make cancellable (#10892) PaperMC/Paper@1d3fc0e Bump reflection-rewriter to 0.0.2 (#10927) PaperMC/Paper@b99d071 Swap some nullable annotations (#10960) PaperMC/Paper@dd31654 bump reflection-rewriter to 0.0.3 (#10969) PaperMC/Paper@dd49fba Fix NPE when retrieving an entity with a null UUID
206 lines
11 KiB
Diff
206 lines
11 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 3a35dcdfd639240363891f412beeef47b8b41e06..b6364b02142a71741bdeb5df3da58dcbd41d1ba5 100644
|
|
--- a/src/main/java/net/minecraft/world/level/Explosion.java
|
|
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
|
|
@@ -113,6 +113,41 @@ public class Explosion {
|
|
this.yield = this.blockInteraction == Explosion.BlockInteraction.DESTROY_WITH_DECAY ? 1.0F / this.radius : 1.0F; // CraftBukkit
|
|
}
|
|
|
|
+ // 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 final java.util.Comparator<double[]> SORT_EXPLOSION_RAYS = java.util.Comparator.comparingDouble(vec -> {
|
|
+ double sign = Math.signum(vec[0]);
|
|
+ double dir = (sign - 1) / 2;
|
|
+ return sign + 8 + vec[2] * dir;
|
|
+ });
|
|
+
|
|
+ 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(SORT_EXPLOSION_RAYS);
|
|
+
|
|
+ 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
|
|
// Paper start - optimise collisions
|
|
private static final double[] CACHED_RAYS;
|
|
static {
|
|
@@ -138,7 +173,7 @@ public class Explosion {
|
|
}
|
|
}
|
|
|
|
- CACHED_RAYS = rayCoords.toDoubleArray();
|
|
+ CACHED_RAYS = sortExplosionRays(rayCoords); // Sakura - optimise paper explosions
|
|
}
|
|
|
|
private static final int CHUNK_CACHE_SHIFT = 2;
|
|
@@ -432,7 +467,7 @@ public class Explosion {
|
|
}
|
|
// CraftBukkit end
|
|
this.level.gameEvent(this.source, (Holder) GameEvent.EXPLODE, new Vec3(this.x, this.y, this.z));
|
|
- Set<BlockPos> set = Sets.newHashSet();
|
|
+ // Sakura - moved into searchForBlocks
|
|
boolean flag = true;
|
|
|
|
int i;
|
|
@@ -458,6 +493,17 @@ public class Explosion {
|
|
|
|
initialCache = this.getOrCacheExplosionBlock(blockX, blockY, blockZ, key, true);
|
|
}
|
|
+ // 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(final ExplosionBlockCache[] blockCache, final ExplosionBlockCache initialCache) {
|
|
+ Set<BlockPos> set = Sets.newHashSet();
|
|
+ // Sakura end - optimise paper 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
|
|
// we can cache the rays and their normals as well, so that we eliminate the excess iterations / checks and
|
|
@@ -543,23 +589,62 @@ public class Explosion {
|
|
}
|
|
|
|
this.toBlow.addAll(set);
|
|
- 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(this.source, 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
|
|
- Vec3 vec3d = new Vec3(this.x, this.y, this.z);
|
|
- Iterator iterator = list.iterator();
|
|
+ return new AABB((double) i, (double) l, (double) j1, (double) j, (double) i1, (double) k1);
|
|
+ }
|
|
|
|
+ protected final void locateAndImpactEntities(final ExplosionBlockCache[] blockCache) {
|
|
+ float f2 = this.radius * 2.0F;
|
|
+
|
|
+ Vec3 vec3d = new Vec3(this.x, this.y, this.z);
|
|
final BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos(); // Paper - optimise explosions
|
|
|
|
- while (iterator.hasNext()) {
|
|
- Entity entity = (Entity) iterator.next();
|
|
+ int minSection = io.papermc.paper.util.WorldUtil.getMinSection(this.level);
|
|
+ int maxSection = io.papermc.paper.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(final ExplosionBlockCache[] blockCache, final 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(final ExplosionBlockCache[] blockCache, final BlockPos.MutableBlockPos blockPos, float f2, Vec3 vec3d, Entity entity) {
|
|
+ if (entity.isAlive() && !entity.isSpectator()) { // 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;
|
|
|
|
@@ -583,24 +668,27 @@ 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;
|
|
|
|
if (entity instanceof EnderDragon) {
|
|
+ // Sakura start - optimise paper explosions
|
|
+ AABB bounds = this.getExplosionBounds(f2);
|
|
for (EnderDragonPart entityComplexPart : ((EnderDragon) entity).subEntities) {
|
|
// Calculate damage separately for each EntityComplexPart
|
|
- if (list.contains(entityComplexPart)) {
|
|
- entityComplexPart.hurt(this.damageSource, this.damageCalculator.getEntityDamageAmount(this, entityComplexPart, getSeenFraction(vec3d, entityComplexPart, blockCache, blockPos))); // Paper - actually optimise explosions and use the right entity to calculate the damage
|
|
+ if (entityComplexPart.getBoundingBox().intersects(bounds)) {
|
|
+ entityComplexPart.hurt(this.damageSource, this.damageCalculator.getEntityDamageAmount(this, entityComplexPart, getBlockDensity(vec3d, entityComplexPart, blockCache, blockPos))); // Paper - actually optimise explosions and use the right entity to calculate the damage
|
|
}
|
|
}
|
|
} else {
|
|
- entity.hurt(this.damageSource, this.damageCalculator.getEntityDamageAmount(this, entity, getSeenFraction(vec3d, entity, blockCache, blockPos))); // Paper - actually optimise explosions
|
|
+ entity.hurt(this.damageSource, this.damageCalculator.getEntityDamageAmount(this, entity, getBlockDensity(vec3d, entity, blockCache, blockPos))); // Paper - actually optimise explosions
|
|
+ // Sakura end - optimise paper explosions
|
|
}
|
|
|
|
if (entity.lastDamageCancelled) { // SPIGOT-5339, SPIGOT-6252, SPIGOT-6777: Skip entity if damage event was cancelled
|
|
- continue;
|
|
+ return; // Sakura - optimise paper explosions
|
|
}
|
|
// CraftBukkit end
|
|
}
|
|
@@ -648,8 +736,12 @@ public class Explosion {
|
|
}
|
|
}
|
|
}
|
|
+ // Sakura start - optimise paper explosions
|
|
}
|
|
+ }
|
|
|
|
+ protected void clearBlockCache() {
|
|
+ // Sakura end - optimise paper explosions
|
|
this.blockCache = null; // Paper - optimise explosions
|
|
this.chunkPosCache = null; // Paper - optimise explosions
|
|
this.chunkCache = null; // Paper - optimise explosions
|