@@ -142,7 +142,7 @@ index 0000000000000000000000000000000000000000..5c6d4124189d98421e2d6f351840c5d6
142
142
+ }
143
143
diff --git a/src/main/java/me/samsuik/sakura/explosion/SakuraExplosion.java b/src/main/java/me/samsuik/sakura/explosion/SakuraExplosion.java
144
144
new file mode 100644
145
- index 0000000000000000000000000000000000000000..1819b24c90b4e58487cacce5eb0b3ee21c5a8f83
145
+ index 0000000000000000000000000000000000000000..cecc88aa129e201ebe85f7ca9cfd73bc25f2f902
146
146
--- /dev/null
147
147
+++ b/src/main/java/me/samsuik/sakura/explosion/SakuraExplosion.java
148
148
@@ -0,0 +1,405 @@
@@ -286,14 +286,14 @@ index 0000000000000000000000000000000000000000..1819b24c90b4e58487cacce5eb0b3ee2
286
286
+ }
287
287
+
288
288
+ // The purpose of this is to make sure papers blockCache doesn't become outdated
289
- + // by flushing the map and removing stale entries from the recent cache array.
290
- + if (!foundBlocks.isEmpty()) {
291
- + if (getToBlow().isEmpty()) {
292
- + cleanBlockCache(foundBlocks);
293
- + } else {
294
- + invalidateBlockCache(blockCache, foundBlocks);
295
- + }
289
+ + // by removing stale entries from the block cache map and the recent cache array.
290
+ + if (!foundBlocks.isEmpty() && getToBlow().isEmpty()) {
291
+ + markBlocksInCacheAsExplodable(foundBlocks);
292
+ + } else {
293
+ + this.blockCache.clear();
296
294
+ }
295
+ +
296
+ + java.util.Arrays.fill(blockCache, null);
297
297
+ }
298
298
+ }
299
299
+
@@ -680,7 +680,7 @@ index ed0234d6a2718d35af635c4b74243bb2afd40769..2800af98260ebdab107466c596d2ec8c
680
680
681
681
@Override
682
682
diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
683
- index 39c30a295df9dfbc3c861f1678a958ef2ed2ba93..e9d6c126b236cb0e29765e7febb52ba14f3b8c61 100644
683
+ index 39c30a295df9dfbc3c861f1678a958ef2ed2ba93..a30bc7ed6b0ea1787ef9bf320a834e6d407762a4 100644
684
684
--- a/src/main/java/net/minecraft/world/level/Explosion.java
685
685
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
686
686
@@ -55,14 +55,16 @@ public class Explosion {
@@ -769,7 +769,7 @@ index 39c30a295df9dfbc3c861f1678a958ef2ed2ba93..e9d6c126b236cb0e29765e7febb52ba1
769
769
++missedRays;
770
770
}
771
771
}
772
- @@ -375,12 +388,80 @@ public class Explosion {
772
+ @@ -375,12 +388,67 @@ public class Explosion {
773
773
return (float)missedRays / (float)totalRays;
774
774
}
775
775
// Paper end - optimise collisions
@@ -791,29 +791,16 @@ index 39c30a295df9dfbc3c861f1678a958ef2ed2ba93..e9d6c126b236cb0e29765e7febb52ba1
791
791
+ this.chunkCache = null; // Paper - optimise explosions
792
792
+ }
793
793
+
794
- + protected void cleanBlockCache (List<BlockPos> blocks) {
794
+ + protected void markBlocksInCacheAsExplodable (List<BlockPos> blocks) {
795
795
+ for (BlockPos blow : blocks) {
796
796
+ ExplosionBlockCache cache = blockCache.get(blow.asLong());
797
- + // May be null if the cache is invalidated then retrieved from the ExplosionBlockCache[]
797
+ + // May be null if the blockCache is cleared then retrieved from the recent cache
798
798
+ if (cache != null) {
799
799
+ cache.shouldExplode = null;
800
800
+ }
801
801
+ }
802
802
+ }
803
803
+
804
- + protected void invalidateBlockCache(ExplosionBlockCache[] blockCaches, List<BlockPos> blocks) {
805
- + for (BlockPos blow : blocks) {
806
- + final int cacheKey =
807
- + (blow.getX() & BLOCK_EXPLOSION_CACHE_MASK) |
808
- + (blow.getY() & BLOCK_EXPLOSION_CACHE_MASK) << (BLOCK_EXPLOSION_CACHE_SHIFT) |
809
- + (blow.getZ() & BLOCK_EXPLOSION_CACHE_MASK) << (BLOCK_EXPLOSION_CACHE_SHIFT + BLOCK_EXPLOSION_CACHE_SHIFT);
810
- +
811
- + blockCaches[cacheKey] = null;
812
- + }
813
- +
814
- + blockCache.clear();
815
- + }
816
- +
817
804
+ protected boolean isDestructibleBlock(@Nullable BlockState state) {
818
805
+ if (state == null) {
819
806
+ return false;
@@ -851,7 +838,7 @@ index 39c30a295df9dfbc3c861f1678a958ef2ed2ba93..e9d6c126b236cb0e29765e7febb52ba1
851
838
AABB axisalignedbb = entity.getBoundingBox();
852
839
double d0 = 1.0D / ((axisalignedbb.maxX - axisalignedbb.minX) * 2.0D + 1.0D);
853
840
double d1 = 1.0D / ((axisalignedbb.maxY - axisalignedbb.minY) * 2.0D + 1.0D);
854
- @@ -400,7 +481 ,11 @@ public class Explosion {
841
+ @@ -400,7 +468 ,11 @@ public class Explosion {
855
842
double d10 = Mth.lerp(d7, axisalignedbb.minZ, axisalignedbb.maxZ);
856
843
Vec3 vec3d1 = new Vec3(d8 + d3, d9, d10 + d4);
857
844
@@ -864,7 +851,7 @@ index 39c30a295df9dfbc3c861f1678a958ef2ed2ba93..e9d6c126b236cb0e29765e7febb52ba1
864
851
++i;
865
852
}
866
853
867
- @@ -429,7 +514 ,29 @@ public class Explosion {
854
+ @@ -429,7 +501 ,29 @@ public class Explosion {
868
855
return;
869
856
}
870
857
// CraftBukkit end
@@ -894,7 +881,7 @@ index 39c30a295df9dfbc3c861f1678a958ef2ed2ba93..e9d6c126b236cb0e29765e7febb52ba1
894
881
Set<BlockPos> set = Sets.newHashSet();
895
882
boolean flag = true;
896
883
897
- @@ -437,14 +544 ,7 @@ public class Explosion {
884
+ @@ -437,14 +531 ,7 @@ public class Explosion {
898
885
int j;
899
886
900
887
// Paper start - optimise explosions
@@ -910,7 +897,7 @@ index 39c30a295df9dfbc3c861f1678a958ef2ed2ba93..e9d6c126b236cb0e29765e7febb52ba1
910
897
// use initial cache value that is most likely to be used: the source position
911
898
final ExplosionBlockCache initialCache;
912
899
{
913
- @@ -541,10 +641 ,15 @@ public class Explosion {
900
+ @@ -541,10 +628 ,15 @@ public class Explosion {
914
901
}
915
902
916
903
this.toBlow.addAll(set);
@@ -928,7 +915,7 @@ index 39c30a295df9dfbc3c861f1678a958ef2ed2ba93..e9d6c126b236cb0e29765e7febb52ba1
928
915
int l = Mth.floor(this.y - (double) f2 - 1.0D);
929
916
int i1 = Mth.floor(this.y + (double) f2 + 1.0D);
930
917
int j1 = Mth.floor(this.z - (double) f2 - 1.0D);
931
- @@ -590,11 +695 ,11 @@ public class Explosion {
918
+ @@ -590,11 +682 ,11 @@ public class Explosion {
932
919
for (EnderDragonPart entityComplexPart : ((EnderDragon) entity).subEntities) {
933
920
// Calculate damage separately for each EntityComplexPart
934
921
if (list.contains(entityComplexPart)) {
@@ -942,7 +929,7 @@ index 39c30a295df9dfbc3c861f1678a958ef2ed2ba93..e9d6c126b236cb0e29765e7febb52ba1
942
929
}
943
930
944
931
if (entity.lastDamageCancelled) { // SPIGOT-5339, SPIGOT-6252, SPIGOT-6777: Skip entity if damage event was cancelled
945
- @@ -655,9 +760 ,7 @@ public class Explosion {
932
+ @@ -655,9 +747 ,7 @@ public class Explosion {
946
933
}
947
934
}
948
935
@@ -953,7 +940,7 @@ index 39c30a295df9dfbc3c861f1678a958ef2ed2ba93..e9d6c126b236cb0e29765e7febb52ba1
953
940
}
954
941
955
942
public void finalizeExplosion(boolean particles) {
956
- @@ -725,6 +828 ,12 @@ public class Explosion {
943
+ @@ -725,6 +815 ,12 @@ public class Explosion {
957
944
if (this.wasCanceled) {
958
945
return;
959
946
}
@@ -966,7 +953,7 @@ index 39c30a295df9dfbc3c861f1678a958ef2ed2ba93..e9d6c126b236cb0e29765e7febb52ba1
966
953
// CraftBukkit end
967
954
objectlistiterator = this.toBlow.iterator();
968
955
969
- @@ -871,15 +980 ,22 @@ public class Explosion {
956
+ @@ -871,15 +967 ,22 @@ public class Explosion {
970
957
private BlockInteraction() {}
971
958
}
972
959
// Paper start - Optimize explosions
0 commit comments