From 7f6a0fb260c34beaf23d699933ae500176fca803 Mon Sep 17 00:00:00 2001 From: Samsuik Date: Mon, 3 Feb 2025 08:24:54 +0000 Subject: [PATCH] Fix avoid redundant block searches And move all ChunkEntitySlice changes into feature patches --- ...ice-Packet-obfuscation-and-reduction.patch | 6 +- .../0004-Optimise-paper-explosions.patch | 35 +++++++++ .../features/0006-Merge-Cannon-Entities.patch | 10 +-- .../0011-Add-maxSearch-to-getEntities.patch | 6 +- .../0015-Configure-cannon-physics.patch | 14 ++-- ...e-left-shooting-and-adjusting-limits.patch | 14 +--- ...t-implementation-to-BasicEntityList.patch} | 69 +++++------------ .../entity/item/FallingBlockEntity.java.patch | 18 ++++- .../special/SpecialisedExplosion.java | 2 +- .../explosion/special/TntExplosion.java | 76 ++++++++++--------- 10 files changed, 134 insertions(+), 116 deletions(-) rename sakura-server/minecraft-patches/{sources/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java.patch => features/0026-copy-EntityList-implementation-to-BasicEntityList.patch} (65%) diff --git a/sakura-server/minecraft-patches/features/0003-Slice-Packet-obfuscation-and-reduction.patch b/sakura-server/minecraft-patches/features/0003-Slice-Packet-obfuscation-and-reduction.patch index 6206a52..959fb10 100644 --- a/sakura-server/minecraft-patches/features/0003-Slice-Packet-obfuscation-and-reduction.patch +++ b/sakura-server/minecraft-patches/features/0003-Slice-Packet-obfuscation-and-reduction.patch @@ -166,10 +166,10 @@ index 00b3e16d5465547e7d4f8126664fb7eda3b3c568..7bbc4a982f442fdb9821221442737ae6 } diff --git a/net/minecraft/world/entity/item/FallingBlockEntity.java b/net/minecraft/world/entity/item/FallingBlockEntity.java -index 066884516b6c9120433864b043276836e087978d..17e810e201fab2e400ac3685e15fa98dcf4c1978 100644 +index fcb7b396db2605146be99f2b14da6806cdaa0f44..b9b8ed9c5e16a703e41997e1a781796363bcf5aa 100644 --- a/net/minecraft/world/entity/item/FallingBlockEntity.java +++ b/net/minecraft/world/entity/item/FallingBlockEntity.java -@@ -127,7 +127,7 @@ public class FallingBlockEntity extends Entity { +@@ -141,7 +141,7 @@ public class FallingBlockEntity extends Entity { } public void setStartPos(BlockPos startPos) { @@ -196,7 +196,7 @@ index 3c74cb8d4b71fcfa600742c21d6ad8e3942a2ab7..b6467f9ff64a76104076a01bfd56852c public int getFuse() { diff --git a/net/minecraft/world/entity/player/Player.java b/net/minecraft/world/entity/player/Player.java -index ee6d5d3ccd55cffdeb96eeb77f648fd82feceb80..09209e5a9b61244a0877818c0841d19aee72522b 100644 +index c1630a2ea3c89f9acc9f3f20faacae769e7449d1..6f3c0f5c68af30619fd46204f930c0da2f789670 100644 --- a/net/minecraft/world/entity/player/Player.java +++ b/net/minecraft/world/entity/player/Player.java @@ -673,7 +673,7 @@ public abstract class Player extends LivingEntity { diff --git a/sakura-server/minecraft-patches/features/0004-Optimise-paper-explosions.patch b/sakura-server/minecraft-patches/features/0004-Optimise-paper-explosions.patch index 2965781..461aee4 100644 --- a/sakura-server/minecraft-patches/features/0004-Optimise-paper-explosions.patch +++ b/sakura-server/minecraft-patches/features/0004-Optimise-paper-explosions.patch @@ -4,6 +4,41 @@ Date: Fri, 19 Apr 2024 22:20:03 +0100 Subject: [PATCH] Optimise paper explosions +diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java +index d21ce54ebb5724c04eadf56a2cde701d5eeb5db2..f214229185c9b54f54b146487232b432ef1314e6 100644 +--- a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java ++++ b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java +@@ -297,6 +297,12 @@ public final class ChunkEntitySlices { + return true; + } + ++ // Sakura start - optimise paper explosions; expose slice entity list ++ public Entity[] getSectionEntities(int sectionY) { ++ return this.allEntities.getSectionEntities(sectionY); ++ } ++ // Sakura end - optimise paper explosions; expose slice entity list ++ + public void getHardCollidingEntities(final Entity except, final AABB box, final List into, final Predicate predicate) { + this.hardCollidingEntities.getEntities(except, box, into, predicate); + } +@@ -495,6 +501,17 @@ public final class ChunkEntitySlices { + } + } + ++ // Sakura start - optimise paper explosions; expose slice entity list ++ public Entity[] getSectionEntities(int sectionY) { ++ final BasicEntityList list = this.entitiesBySection[sectionY - this.slices.minSection]; ++ if (list != null) { ++ return list.storage; ++ } else { ++ return new Entity[0]; ++ } ++ } ++ // Sakura end - optimise paper explosions; expose slice entity list ++ + public void getEntities(final Entity except, final AABB box, final List into, final Predicate predicate) { + if (this.count == 0) { + return; diff --git a/net/minecraft/world/level/ServerExplosion.java b/net/minecraft/world/level/ServerExplosion.java index df584256e133bfc0b7effd56961f1b91c264c7bd..9f06e32101f494d94d9210210255d5d72ca4ff36 100644 --- a/net/minecraft/world/level/ServerExplosion.java diff --git a/sakura-server/minecraft-patches/features/0006-Merge-Cannon-Entities.patch b/sakura-server/minecraft-patches/features/0006-Merge-Cannon-Entities.patch index 971fa7a..6f5da54 100644 --- a/sakura-server/minecraft-patches/features/0006-Merge-Cannon-Entities.patch +++ b/sakura-server/minecraft-patches/features/0006-Merge-Cannon-Entities.patch @@ -85,7 +85,7 @@ index 3671003b9fdf787fc5095d12df9ee2f15bd998f1..2a617bd6d5d14cd69b149d6c5f82f8b2 if (!(this instanceof ServerPlayer) && removalReason != RemovalReason.CHANGED_DIMENSION && !alreadyRemoved) { // Players need to be special cased, because they are regularly removed from the world diff --git a/net/minecraft/world/entity/item/FallingBlockEntity.java b/net/minecraft/world/entity/item/FallingBlockEntity.java -index 4836be29ff5e87e4f2b9beb0d4a9943281ab5262..1d9afcf995ee734f13803e26956439e5c3450f44 100644 +index b9b8ed9c5e16a703e41997e1a781796363bcf5aa..aa81292b862e22e276cabc9d7611362cbd91602d 100644 --- a/net/minecraft/world/entity/item/FallingBlockEntity.java +++ b/net/minecraft/world/entity/item/FallingBlockEntity.java @@ -54,7 +54,7 @@ import org.bukkit.craftbukkit.event.CraftEventFactory; @@ -160,7 +160,7 @@ index 4836be29ff5e87e4f2b9beb0d4a9943281ab5262..1d9afcf995ee734f13803e26956439e5 } public FallingBlockEntity(Level level, double x, double y, double z, BlockState state) { -@@ -222,6 +273,7 @@ public class FallingBlockEntity extends Entity { +@@ -236,6 +287,7 @@ public class FallingBlockEntity extends Entity { return; } // CraftBukkit end @@ -168,7 +168,7 @@ index 4836be29ff5e87e4f2b9beb0d4a9943281ab5262..1d9afcf995ee734f13803e26956439e5 if (this.level().setBlock(blockPos, this.blockState, 3)) { ((ServerLevel)this.level()) .getChunkSource() -@@ -328,6 +380,7 @@ public class FallingBlockEntity extends Entity { +@@ -342,6 +394,7 @@ public class FallingBlockEntity extends Entity { compound.putBoolean("CancelDrop", this.cancelDrop); if (!this.autoExpire) compound.putBoolean("Paper.AutoExpire", false); // Paper - Expand FallingBlock API @@ -176,7 +176,7 @@ index 4836be29ff5e87e4f2b9beb0d4a9943281ab5262..1d9afcf995ee734f13803e26956439e5 } @Override -@@ -360,6 +413,11 @@ public class FallingBlockEntity extends Entity { +@@ -374,6 +427,11 @@ public class FallingBlockEntity extends Entity { this.autoExpire = compound.getBoolean("Paper.AutoExpire"); } // Paper end - Expand FallingBlock API @@ -189,7 +189,7 @@ index 4836be29ff5e87e4f2b9beb0d4a9943281ab5262..1d9afcf995ee734f13803e26956439e5 public void setHurtsEntities(float fallDamagePerDistance, int fallDamageMax) { diff --git a/net/minecraft/world/entity/item/PrimedTnt.java b/net/minecraft/world/entity/item/PrimedTnt.java -index 9e9463d62aa1618a4a749bb7e2636c9b090991e9..b378b4c4930c4ebd55795591aca173fd1fee46c9 100644 +index b6467f9ff64a76104076a01bfd56852ce712d95b..e6aa1d1a5fc5cd2ffc156125c4eef2d0d1aeef4a 100644 --- a/net/minecraft/world/entity/item/PrimedTnt.java +++ b/net/minecraft/world/entity/item/PrimedTnt.java @@ -33,7 +33,7 @@ import org.bukkit.event.entity.EntityRemoveEvent; diff --git a/sakura-server/minecraft-patches/features/0011-Add-maxSearch-to-getEntities.patch b/sakura-server/minecraft-patches/features/0011-Add-maxSearch-to-getEntities.patch index f46c612..958f3b5 100644 --- a/sakura-server/minecraft-patches/features/0011-Add-maxSearch-to-getEntities.patch +++ b/sakura-server/minecraft-patches/features/0011-Add-maxSearch-to-getEntities.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Add maxSearch to getEntities diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java -index 39148fe540d616cdd4d63c4d1a02b422cab0f6eb..50a551d5bcac9b2b6644d7b43e625185090657a6 100644 +index f214229185c9b54f54b146487232b432ef1314e6..a242b68b6d603d3da46d9e0635a86a07a7149b3b 100644 --- a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java +++ b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java @@ -314,7 +314,14 @@ public final class ChunkEntitySlices { @@ -24,7 +24,7 @@ index 39148fe540d616cdd4d63c4d1a02b422cab0f6eb..50a551d5bcac9b2b6644d7b43e625185 } public void getEntities(final EntityType type, final AABB box, final List into, -@@ -570,6 +577,13 @@ public final class ChunkEntitySlices { +@@ -552,6 +559,13 @@ public final class ChunkEntitySlices { public boolean getEntitiesLimited(final Entity except, final AABB box, final List into, final Predicate predicate, final int maxCount) { @@ -38,7 +38,7 @@ index 39148fe540d616cdd4d63c4d1a02b422cab0f6eb..50a551d5bcac9b2b6644d7b43e625185 if (this.count == 0) { return false; } -@@ -591,8 +605,14 @@ public final class ChunkEntitySlices { +@@ -573,8 +587,14 @@ public final class ChunkEntitySlices { final Entity[] storage = list.storage; diff --git a/sakura-server/minecraft-patches/features/0015-Configure-cannon-physics.patch b/sakura-server/minecraft-patches/features/0015-Configure-cannon-physics.patch index caafed6..b8c3828 100644 --- a/sakura-server/minecraft-patches/features/0015-Configure-cannon-physics.patch +++ b/sakura-server/minecraft-patches/features/0015-Configure-cannon-physics.patch @@ -184,7 +184,7 @@ index d2f9708b9166a46adb5009bd6d927cd03f3f9820..a026047ed2ab4b9ab047c7d855914296 return; } diff --git a/net/minecraft/world/entity/item/FallingBlockEntity.java b/net/minecraft/world/entity/item/FallingBlockEntity.java -index af42bea9fb18bb0f6e576d4344cdee2cd0e9a4ef..10799fe7188f69c6eb56403ba0942a437139fb84 100644 +index bf6473756594f3296160d3b8c28a24ef0e458328..e4e708609799799ed2e7dd516ba8bf61e98bc022 100644 --- a/net/minecraft/world/entity/item/FallingBlockEntity.java +++ b/net/minecraft/world/entity/item/FallingBlockEntity.java @@ -125,6 +125,43 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti @@ -242,7 +242,7 @@ index af42bea9fb18bb0f6e576d4344cdee2cd0e9a4ef..10799fe7188f69c6eb56403ba0942a43 } // Sakura start - falling block height parity api -@@ -164,7 +205,11 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti +@@ -178,7 +219,11 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti : blockState ); if (!CraftEventFactory.callEntityChangeBlockEvent(fallingBlockEntity, pos, blockState.getFluidState().createLegacyBlock())) return fallingBlockEntity; // CraftBukkit @@ -255,7 +255,7 @@ index af42bea9fb18bb0f6e576d4344cdee2cd0e9a4ef..10799fe7188f69c6eb56403ba0942a43 level.addFreshEntity(fallingBlockEntity); return fallingBlockEntity; } -@@ -208,7 +253,7 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti +@@ -222,7 +267,7 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti @Override protected double getDefaultGravity() { @@ -264,7 +264,7 @@ index af42bea9fb18bb0f6e576d4344cdee2cd0e9a4ef..10799fe7188f69c6eb56403ba0942a43 } @Override -@@ -217,6 +262,12 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti +@@ -231,6 +276,12 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause } else { Block block = this.blockState.getBlock(); @@ -277,7 +277,7 @@ index af42bea9fb18bb0f6e576d4344cdee2cd0e9a4ef..10799fe7188f69c6eb56403ba0942a43 this.time++; this.applyGravity(); this.move(MoverType.SELF, this.getDeltaMovement()); -@@ -231,8 +282,15 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti +@@ -245,8 +296,15 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti } // Paper end - Configurable falling blocks height nerf this.handlePortal(); @@ -294,7 +294,7 @@ index af42bea9fb18bb0f6e576d4344cdee2cd0e9a4ef..10799fe7188f69c6eb56403ba0942a43 boolean flag = this.level().sakuraConfig().cannons.sand.concreteSolidifyInWater && this.blockState.getBlock() instanceof ConcretePowderBlock; // Sakura - configure concrete solidifying in water boolean flag1 = flag && this.level().getFluidState(blockPos).is(FluidTags.WATER); double d = this.getDeltaMovement().lengthSqr(); -@@ -259,8 +317,11 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti +@@ -273,8 +331,11 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti } } else { BlockState blockState = this.level().getBlockState(blockPos); @@ -308,7 +308,7 @@ index af42bea9fb18bb0f6e576d4344cdee2cd0e9a4ef..10799fe7188f69c6eb56403ba0942a43 if (!this.cancelDrop) { boolean canBeReplaced = blockState.canBeReplaced( new DirectionalPlaceContext(this.level(), blockPos, Direction.DOWN, ItemStack.EMPTY, Direction.UP) -@@ -332,7 +393,12 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti +@@ -346,7 +407,12 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti } } diff --git a/sakura-server/minecraft-patches/features/0022-Configurable-left-shooting-and-adjusting-limits.patch b/sakura-server/minecraft-patches/features/0022-Configurable-left-shooting-and-adjusting-limits.patch index 63fecec..2d43967 100644 --- a/sakura-server/minecraft-patches/features/0022-Configurable-left-shooting-and-adjusting-limits.patch +++ b/sakura-server/minecraft-patches/features/0022-Configurable-left-shooting-and-adjusting-limits.patch @@ -75,23 +75,13 @@ index 88a83d0b81fc65b4091c7f2c44820b4913356a2f..dd56f4e128793006c370514007755bdf x = this.scanX(currBoundingBox, x, voxelList, bbList); if (x != 0.0) { currBoundingBox = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.offsetX(currBoundingBox, x); -<<<<<<< HEAD:sakura-server/minecraft-patches/features/0022-Configurable-left-shooting-and-adjusting-limits.patch diff --git a/net/minecraft/world/entity/item/FallingBlockEntity.java b/net/minecraft/world/entity/item/FallingBlockEntity.java -index 10799fe7188f69c6eb56403ba0942a437139fb84..8ecc4a7b6f7bd997aecc85c5d0c12b0e8926a505 100644 +index e4e708609799799ed2e7dd516ba8bf61e98bc022..5b7fb6a1c39121bbfc7ef6631aea741f9bd0e244 100644 --- a/net/minecraft/world/entity/item/FallingBlockEntity.java +++ b/net/minecraft/world/entity/item/FallingBlockEntity.java -@@ -270,6 +270,7 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti +@@ -284,6 +284,7 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti // Sakura end - configure cannon physics this.time++; -======= -diff --git a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java -index eeca55d482787ff4f032db46a6934e98865f14aa..6d13b037a4e2c0d677c1cb4b39cf6d50c659c87e 100644 ---- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java -+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java -@@ -276,6 +276,7 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti - // Sakura end - physics version api - ++this.time; ->>>>>>> db70cd2 (Fix falling block stacking restrictions when using legacy physics):patches/server/0076-Configurable-left-shooting-and-adjusting-limits.patch this.applyGravity(); + this.limitLeftShooting(); // Sakura - configurable left shooting and adjusting limits this.move(MoverType.SELF, this.getDeltaMovement()); diff --git a/sakura-server/minecraft-patches/sources/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java.patch b/sakura-server/minecraft-patches/features/0026-copy-EntityList-implementation-to-BasicEntityList.patch similarity index 65% rename from sakura-server/minecraft-patches/sources/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java.patch rename to sakura-server/minecraft-patches/features/0026-copy-EntityList-implementation-to-BasicEntityList.patch index d8042ea..3d40c0d 100644 --- a/sakura-server/minecraft-patches/sources/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java.patch +++ b/sakura-server/minecraft-patches/features/0026-copy-EntityList-implementation-to-BasicEntityList.patch @@ -1,19 +1,14 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Samsuik +Date: Sun, 2 Feb 2025 17:05:05 +0000 +Subject: [PATCH] copy EntityList implementation to BasicEntityList + + +diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java +index a242b68b6d603d3da46d9e0635a86a07a7149b3b..2cf9c56d234b32a1ae95bdde73fd5f6aaa2ca82c 100644 --- a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java +++ b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java -@@ -297,6 +_,12 @@ - return true; - } - -+ // Sakura start - add utility methods to entity slices -+ public Entity[] getSectionEntities(int sectionY) { -+ return this.allEntities.getSectionEntities(sectionY); -+ } -+ // Sakura end - add utility methods to entity slices -+ - public void getHardCollidingEntities(final Entity except, final AABB box, final List into, final Predicate predicate) { - this.hardCollidingEntities.getEntities(except, box, into, predicate); - } -@@ -383,6 +_,13 @@ +@@ -396,6 +396,13 @@ public final class ChunkEntitySlices { private E[] storage; private int size; @@ -27,7 +22,7 @@ public BasicEntityList() { this(0); -@@ -403,6 +_,7 @@ +@@ -416,6 +423,7 @@ public final class ChunkEntitySlices { private void resize() { if (this.storage == EMPTY) { this.storage = (E[])new Entity[DEFAULT_CAPACITY]; @@ -35,7 +30,7 @@ } else { this.storage = Arrays.copyOf(this.storage, this.storage.length * 2); } -@@ -416,6 +_,7 @@ +@@ -429,6 +437,7 @@ public final class ChunkEntitySlices { } else { this.storage[idx] = entity; } @@ -43,32 +38,27 @@ } public int indexOf(final E entity) { -@@ -431,24 +_,32 @@ +@@ -444,24 +453,32 @@ public final class ChunkEntitySlices { } public boolean remove(final E entity) { - final int idx = this.indexOf(entity); - if (idx == -1) { -- return false; -- } -- ++ // Sakura start - use methods from EntityList ++ if (this.entityToIndex == null) { + return false; + } + - final int size = --this.size; - final E[] storage = this.storage; - if (idx != size) { - System.arraycopy(storage, idx + 1, storage, idx, size - idx); -- } -- -- storage[size] = null; -+ // Sakura start - use methods from EntityList -+ if (this.entityToIndex == null) { -+ return false; -+ } -+ + final int index = this.entityToIndex.remove(entity.getId()); + if (index == Integer.MIN_VALUE) { + return false; -+ } -+ + } + +- storage[size] = null; + // move the entity at the end to this index + final int endIndex = --this.size; + final E end = this.storage[endIndex]; @@ -89,22 +79,3 @@ } } -@@ -494,6 +_,18 @@ - this.entitiesBySection[sectionIndex] = null; - } - } -+ -+ // Sakura start - add utility methods to entity slices -+ public Entity[] getSectionEntities(int sectionY) { -+ BasicEntityList list = this.entitiesBySection[sectionY - this.slices.minSection]; -+ -+ if (list != null) { -+ return list.storage; -+ } -+ -+ return new Entity[0]; -+ } -+ // Sakura end - add utility methods to entity slices - - public void getEntities(final Entity except, final AABB box, final List into, final Predicate predicate) { - if (this.count == 0) { diff --git a/sakura-server/minecraft-patches/sources/net/minecraft/world/entity/item/FallingBlockEntity.java.patch b/sakura-server/minecraft-patches/sources/net/minecraft/world/entity/item/FallingBlockEntity.java.patch index db23bb9..c83c0d6 100644 --- a/sakura-server/minecraft-patches/sources/net/minecraft/world/entity/item/FallingBlockEntity.java.patch +++ b/sakura-server/minecraft-patches/sources/net/minecraft/world/entity/item/FallingBlockEntity.java.patch @@ -12,7 +12,7 @@ } public FallingBlockEntity(Level level, double x, double y, double z, BlockState state) { -@@ -85,6 +_,13 @@ +@@ -85,6 +_,27 @@ this.setStartPos(this.blockPosition()); } @@ -22,6 +22,20 @@ + return this.heightParity ? this.getY() : super.getEyeY(); + } + // Sakura end - falling block height parity api ++ // Sakura start - falling block stacking restrictions ++ private static boolean isFallingBlockInBounds(Level level, BlockPos blockPosition) { ++ if (level.sakuraConfig().cannons.sand.preventAtWorldHeight && blockPosition.getY() >= level.getMaxY() - 1) { ++ return false; ++ } ++ ++ Vec3 center = blockPosition.getBottomCenter(); ++ if (level.sakuraConfig().cannons.sand.preventAgainstBorder && !level.getWorldBorder().isWithinBounds(center.x(), center.z(), -1.0)) { ++ return false; ++ } ++ ++ return true; ++ } ++ // Sakura end - falling block stacking restrictions + public static FallingBlockEntity fall(Level level, BlockPos pos, BlockState blockState) { FallingBlockEntity fallingBlockEntity = new FallingBlockEntity( @@ -49,7 +63,7 @@ boolean flag2 = FallingBlock.isFree(this.level().getBlockState(blockPos.below())) && (!flag || !flag1); boolean flag3 = this.blockState.canSurvive(this.level(), blockPos) && !flag2; - if (canBeReplaced && flag3) { -+ if (canBeReplaced && flag3 && this.level().sakuraConfig().cannons.sand.isFallingBlockInBounds(this)) { // Sakura - falling block stacking restrictions ++ if (canBeReplaced && flag3 && isFallingBlockInBounds(this.level(), blockPos)) { // Sakura - falling block stacking restrictions if (this.blockState.hasProperty(BlockStateProperties.WATERLOGGED) && this.level().getFluidState(blockPos).getType() == Fluids.WATER) { this.blockState = this.blockState.setValue(BlockStateProperties.WATERLOGGED, Boolean.valueOf(true)); diff --git a/sakura-server/src/main/java/me/samsuik/sakura/explosion/special/SpecialisedExplosion.java b/sakura-server/src/main/java/me/samsuik/sakura/explosion/special/SpecialisedExplosion.java index f737a04..7bd879f 100644 --- a/sakura-server/src/main/java/me/samsuik/sakura/explosion/special/SpecialisedExplosion.java +++ b/sakura-server/src/main/java/me/samsuik/sakura/explosion/special/SpecialisedExplosion.java @@ -73,7 +73,7 @@ public abstract class SpecialisedExplosion extends ServerExplo this.getHitPlayers().clear(); } - return !explodedPositions.isEmpty(); + return !explodedPositions.isEmpty() && !this.wasCanceled; } protected void postExplosion(List foundBlocks, boolean destroyedBlocks) { diff --git a/sakura-server/src/main/java/me/samsuik/sakura/explosion/special/TntExplosion.java b/sakura-server/src/main/java/me/samsuik/sakura/explosion/special/TntExplosion.java index 320cdb1..a5635ea 100644 --- a/sakura-server/src/main/java/me/samsuik/sakura/explosion/special/TntExplosion.java +++ b/sakura-server/src/main/java/me/samsuik/sakura/explosion/special/TntExplosion.java @@ -28,7 +28,7 @@ public final class TntExplosion extends SpecialisedExplosion { private final Vec3 originalPosition; private final List explosions = new ObjectArrayList<>(); private AABB bounds; - private int wrapped = 0; + private int swinging = 0; private boolean moved = false; public TntExplosion(ServerLevel level, PrimedTnt tnt, @Nullable DamageSource damageSource, @Nullable ExplosionDamageCalculator behavior, Vec3 center, float power, boolean createFire, BlockInteraction destructionType, Consumer> applyEffects) { @@ -47,7 +47,7 @@ public final class TntExplosion extends SpecialisedExplosion { @Override protected int getExplosionCount() { if (this.cause.getMergeEntityData().getMergeLevel() == MergeLevel.NONE) { - this.mergeEntitiesBeforeExplosion(); + this.mergeEntitiesBeforeExploding(); } return this.cause.getMergeEntityData().getCount(); } @@ -55,44 +55,33 @@ public final class TntExplosion extends SpecialisedExplosion { @Override protected void startExplosion() { for (int i = this.getExplosionCount() - 1; i >= 0; --i) { - Vec3 previousMomentum = this.cause.entityState().momentum(); boolean lastCycle = i == 0; - List toBlow = this.midExplosion(previousMomentum, lastCycle); // search for blocks and impact entities - boolean destroyedBlocks = this.finalizeExplosionAndParticles(toBlow); + List toBlow = this.midExplosion(lastCycle); // search for blocks and impact entities + boolean destroyedBlocks = this.finalizeExplosionAndParticles(toBlow); // call events, break blocks and send particles if (!lastCycle) { EntityState entityState = this.nextSourceVelocity(); - this.postExplosion(toBlow, destroyedBlocks); // update wrapped, clear recent block cache + this.postExplosion(toBlow, destroyedBlocks); this.updateExplosionPosition(entityState, destroyedBlocks); } } } - private List midExplosion(Vec3 previousMomentum, boolean lastCycle) { + private List midExplosion(boolean lastCycle) { final List explodedPositions; - if (this.wrapped < FOUND_ALL_BLOCKS) { + if (this.swinging < FOUND_ALL_BLOCKS) { explodedPositions = this.calculateExplodedPositions(); } else { explodedPositions = List.of(); } - if (this.wrapped < ALL_DIRECTIONS) { - Vec3 momentum = this.cause.entityState().momentum(); - for (Direction.Axis axis : Direction.Axis.VALUES) { - double current = momentum.get(axis); - double previous = previousMomentum.get(axis); - if (current == previous || current * previous < 0) { - this.wrapped |= 1 << axis.ordinal(); - } - } - } + Vec3 center = this.center; + this.bounds = this.bounds.expand(center); + this.explosions.add(center); - this.bounds = this.bounds.expand(this.center); - this.explosions.add(this.center); - - if (lastCycle || this.requiresImpactEntities(explodedPositions, this.center)) { + if (lastCycle || this.requiresImpactEntities(explodedPositions, center)) { this.locateAndImpactEntitiesInBounds(); - this.bounds = new AABB(this.center, this.center); + this.bounds = new AABB(center, center); this.explosions.clear(); } @@ -102,12 +91,23 @@ public final class TntExplosion extends SpecialisedExplosion { @Override protected void postExplosion(List foundBlocks, boolean destroyedBlocks) { super.postExplosion(foundBlocks, destroyedBlocks); - // Update wrapped, this is for tracking swinging and if blocks are found - if (this.wrapped >= ALL_DIRECTIONS) { + if (this.swinging >= ALL_DIRECTIONS) { + // Increment "swinging" if no blocks have been found, and it has swung in every direction. + // This is used to skip expensive exploded block calculations. if (!destroyedBlocks && this.level().sakuraConfig().cannons.explosion.avoidRedundantBlockSearches) { - this.wrapped++; + this.swinging++; } else { - this.wrapped = ALL_DIRECTIONS; + this.swinging = ALL_DIRECTIONS; + } + } + } + + private void updateSwingingState(Vec3 momentum, Vec3 previousMomentum) { + for (Direction.Axis axis : Direction.Axis.VALUES) { + double current = momentum.get(axis); + double previous = previousMomentum.get(axis); + if (current == previous || current * previous <= 0.0) { + this.swinging |= 1 << axis.ordinal(); } } } @@ -127,6 +127,7 @@ public final class TntExplosion extends SpecialisedExplosion { private void updateExplosionPosition(EntityState entityState, boolean destroyedBlocks) { // Before setting entity state, otherwise we might cause issues. + Vec3 entityMomentum = this.cause.entityState().momentum(); final boolean hasMoved; if (this.moved) { hasMoved = true; @@ -134,7 +135,7 @@ public final class TntExplosion extends SpecialisedExplosion { hasMoved = false; } else { double newMomentum = entityState.momentum().lengthSqr(); - double oldMomentum = this.cause.entityState().momentum().lengthSqr(); + double oldMomentum = entityMomentum.lengthSqr(); hasMoved = oldMomentum <= Math.pow(this.radius() * 2.0 + 1.0, 2.0) || newMomentum <= oldMomentum; } @@ -146,12 +147,19 @@ public final class TntExplosion extends SpecialisedExplosion { if (destroyedBlocks || hasMoved) { this.cause.setFuse(100); this.cause.tick(); - this.moved |= !this.center.equals(this.originalPosition); this.recalculateExplosionPosition(); + this.moved |= !this.center.equals(this.originalPosition); + } + + // Update swinging state + if (this.moved) { + this.updateSwingingState(entityState.momentum(), entityMomentum); + } else { + this.swinging = ALL_DIRECTIONS; } } - private void mergeEntitiesBeforeExplosion() { + private void mergeEntitiesBeforeExploding() { IteratorSafeOrderedReferenceSet entities = this.level().entityTickList.entities; int index = entities.indexOf(this.cause); @@ -173,10 +181,10 @@ public final class TntExplosion extends SpecialisedExplosion { Vec3 center = bb.getCenter(); double change = Math.max(bb.getXsize(), Math.max(bb.getYsize(), bb.getZsize())); double maxDistanceSqr = Math.pow(radius + change, 2.0); - boolean moved = (change != 0.0); + boolean positionChanged = change != 0.0; this.forEachEntitySliceInBounds(bb.inflate(radius), entities -> { - if (moved) { + if (positionChanged) { this.impactEntitiesSwinging(entities, center, radius, maxDistanceSqr); } else { this.impactEntitiesFromPosition(entities, this.explosions.getFirst(), this.explosions.size(), radius); @@ -190,7 +198,7 @@ public final class TntExplosion extends SpecialisedExplosion { if (entity == null) break; if (entity != this.source && !entity.ignoreExplosion(this) && entity.distanceToSqr(center.x, center.y, center.z) <= maxDistanceSqr) { - this.impactEntity(entity, radius); + this.impactEntitySwinging(entity, radius); } if (entities[i] != entity) { @@ -199,7 +207,7 @@ public final class TntExplosion extends SpecialisedExplosion { } } - private void impactEntity(Entity entity, double radius) { + private void impactEntitySwinging(Entity entity, double radius) { //noinspection ForLoopReplaceableByForEach for (int i = 0; i < this.explosions.size(); i++) { this.impactEntity(entity, this.explosions.get(i), 1, radius);