From 2e58a562ebcf97fdd46e6d9460dada38defbd825 Mon Sep 17 00:00:00 2001 From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com> Date: Sat, 26 Oct 2024 14:06:27 +0800 Subject: [PATCH 1/4] Remove stream in YieldJobSite --- .../0121-Remove-stream-in-YieldJobSite.patch | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 patches/server/0121-Remove-stream-in-YieldJobSite.patch diff --git a/patches/server/0121-Remove-stream-in-YieldJobSite.patch b/patches/server/0121-Remove-stream-in-YieldJobSite.patch new file mode 100644 index 000000000..4704a8687 --- /dev/null +++ b/patches/server/0121-Remove-stream-in-YieldJobSite.patch @@ -0,0 +1,53 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com> +Date: Sat, 26 Oct 2024 14:04:54 +0800 +Subject: [PATCH] Remove stream in YieldJobSite + + +diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/YieldJobSite.java b/src/main/java/net/minecraft/world/entity/ai/behavior/YieldJobSite.java +index d1a9b62d3304916275dd6b4c4e783cf1563b5e21..572d266c3af268a5dbbc31272b5aa15d46442408 100644 +--- a/src/main/java/net/minecraft/world/entity/ai/behavior/YieldJobSite.java ++++ b/src/main/java/net/minecraft/world/entity/ai/behavior/YieldJobSite.java +@@ -38,24 +38,25 @@ public class YieldJobSite { + if (optional.isEmpty()) { + return true; + } else { +- context.>get(mobs) +- .stream() +- .filter(mob -> mob instanceof Villager && mob != entity) +- .map(villager -> (Villager)villager) +- .filter(LivingEntity::isAlive) +- .filter(villager -> nearbyWantsJobsite(optional.get(), villager, blockPos)) +- .findFirst() +- .ifPresent(villager -> { +- walkTarget.erase(); +- lookTarget.erase(); +- potentialJobSite.erase(); +- if (villager.getBrain().getMemory(MemoryModuleType.JOB_SITE).isEmpty()) { +- BehaviorUtils.setWalkAndLookTargetMemories(villager, blockPos, speed, 1); +- villager.getBrain() +- .setMemory(MemoryModuleType.POTENTIAL_JOB_SITE, GlobalPos.of(world.dimension(), blockPos)); +- DebugPackets.sendPoiTicketCountPacket(world, blockPos); ++ // Leaf start - Remove stream in YieldJobSite ++ List mobsList = context.get(mobs); ++ for (LivingEntity mob : mobsList) { ++ if (mob instanceof Villager villager && mob != entity && villager.isAlive()) { ++ if (nearbyWantsJobsite(optional.get(), villager, blockPos)) { ++ walkTarget.erase(); ++ lookTarget.erase(); ++ potentialJobSite.erase(); ++ ++ if (villager.getBrain().getMemory(MemoryModuleType.JOB_SITE).isEmpty()) { ++ BehaviorUtils.setWalkAndLookTargetMemories(villager, blockPos, speed, 1); ++ villager.getBrain().setMemory(MemoryModuleType.POTENTIAL_JOB_SITE, GlobalPos.of(world.dimension(), blockPos)); ++ DebugPackets.sendPoiTicketCountPacket(world, blockPos); ++ } ++ break; + } +- }); ++ } ++ } ++ // Leaf end - Remove stream in YieldJobSite + return true; + } + } From 39cfe4ce102019b677e195d560b02cf013fb1373 Mon Sep 17 00:00:00 2001 From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com> Date: Sat, 26 Oct 2024 16:22:46 +0800 Subject: [PATCH 2/4] Use parallelQuickSort in NearestLivingEntitySensor --- ...ickSort-in-NearestLivingEntitySensor.patch | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 patches/server/0122-Use-parallelQuickSort-in-NearestLivingEntitySensor.patch diff --git a/patches/server/0122-Use-parallelQuickSort-in-NearestLivingEntitySensor.patch b/patches/server/0122-Use-parallelQuickSort-in-NearestLivingEntitySensor.patch new file mode 100644 index 000000000..d8d49b1d3 --- /dev/null +++ b/patches/server/0122-Use-parallelQuickSort-in-NearestLivingEntitySensor.patch @@ -0,0 +1,30 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com> +Date: Sat, 26 Oct 2024 15:00:21 +0800 +Subject: [PATCH] Use parallelQuickSort in NearestLivingEntitySensor + + +diff --git a/src/main/java/net/minecraft/world/entity/ai/sensing/NearestLivingEntitySensor.java b/src/main/java/net/minecraft/world/entity/ai/sensing/NearestLivingEntitySensor.java +index 5a059e1ec232d82e8e891ae78fea962bec2f878e..f6cdabf05b034fab5f72d098017bf1115e9ffb57 100644 +--- a/src/main/java/net/minecraft/world/entity/ai/sensing/NearestLivingEntitySensor.java ++++ b/src/main/java/net/minecraft/world/entity/ai/sensing/NearestLivingEntitySensor.java +@@ -16,10 +16,16 @@ public class NearestLivingEntitySensor extends Sensor + protected void doTick(ServerLevel world, T entity) { + AABB aABB = entity.getBoundingBox().inflate((double)this.radiusXZ(), (double)this.radiusY(), (double)this.radiusXZ()); + List list = world.getEntitiesOfClass(LivingEntity.class, aABB, e -> e != entity && e.isAlive()); +- list.sort(Comparator.comparingDouble(entity::distanceToSqr)); ++ // Leaf start - Use parallelQuickSort in NearestLivingEntitySensor ++ LivingEntity[] sorted = list.toArray(new LivingEntity[]{}); ++ it.unimi.dsi.fastutil.objects.ObjectArrays.parallelQuickSort(sorted, Comparator.comparingDouble(entity::distanceToSqr)); ++ List sortedList = java.util.Arrays.asList(sorted); ++ // Leaf end - Use parallelQuickSort in NearestLivingEntitySensor + Brain brain = entity.getBrain(); +- brain.setMemory(MemoryModuleType.NEAREST_LIVING_ENTITIES, list); +- brain.setMemory(MemoryModuleType.NEAREST_VISIBLE_LIVING_ENTITIES, new NearestVisibleLivingEntities(entity, list)); ++ // Leaf start - Use parallelQuickSort in NearestLivingEntitySensor ++ brain.setMemory(MemoryModuleType.NEAREST_LIVING_ENTITIES, sortedList); ++ brain.setMemory(MemoryModuleType.NEAREST_VISIBLE_LIVING_ENTITIES, new NearestVisibleLivingEntities(entity, sortedList)); ++ // Leaf end - Use parallelQuickSort in NearestLivingEntitySensor + } + + protected int radiusXZ() { From e4b518ac1ed9f40cc8f9c3a2fa53853e199ad4c6 Mon Sep 17 00:00:00 2001 From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com> Date: Sat, 26 Oct 2024 16:59:47 +0800 Subject: [PATCH 3/4] Reorder patch --- ...ieldJobSite.patch => 0093-Remove-stream-in-YieldJobSite.patch} | 0 ...94-Replace-Entity-active-effects-map-with-optimized-col.patch} | 0 ...ch => 0095-Replace-brain-maps-with-optimized-collection.patch} | 0 ...n-allocations.patch => 0096-Reduce-worldgen-allocations.patch} | 0 .../server/{0096-Fix-MC-183518.patch => 0097-Fix-MC-183518.patch} | 0 ...98-Use-caffeine-cache-kickPermission-instead-of-using-g.patch} | 0 ...patch => 0099-Do-not-place-player-if-the-server-is-full.patch} | 0 .../server/{0099-Fix-MC-200418.patch => 0100-Fix-MC-200418.patch} | 0 .../server/{0100-Fix-MC-119417.patch => 0101-Fix-MC-119417.patch} | 0 .../server/{0101-Fix-MC-223153.patch => 0102-Fix-MC-223153.patch} | 0 ...ch => 0103-Optimize-LeavesProtocolManager-init-protocol.patch} | 0 ...=> 0104-Cache-CraftEntityType-minecraftToBukkit-convert.patch} | 0 ...mbie.patch => 0105-Configurable-player-knockback-zombie.patch} | 0 ...patch => 0106-Hide-specified-item-components-to-clients.patch} | 0 ...07-Paper-PR-Skip-AI-during-inactive-ticks-for-non-aware.patch} | 0 ...08-Paper-PR-Reduce-work-done-in-CraftMapCanvas.drawImag.patch} | 0 ...s.patch => 0109-Paper-PR-Throttle-failed-spawn-attempts.patch} | 0 ...10-Paper-PR-Prevent-zombie-reinforcements-loading-chunk.patch} | 0 ...-packets.patch => 0111-Dont-send-useless-entity-packets.patch} | 0 ...ull.patch => 0112-Don-t-spawn-if-lastSpawnState-is-null.patch} | 0 ...ltithreaded-Tracker.patch => 0113-Multithreaded-Tracker.patch} | 0 ...yerdata-Save.patch => 0114-Nitori-Async-playerdata-Save.patch} | 0 ...ge-max-stack-count.patch => 0115-Change-max-stack-count.patch} | 0 ...16-Reduce-object-complexity-to-make-block-isValid-calls.patch} | 0 ...atch => 0117-Optimize-nearby-alive-players-for-spawning.patch} | 0 ...e-blockstate-cache.patch => 0118-Cache-blockstate-cache.patch} | 0 .../server/{0118-Fix-MC-177381.patch => 0119-Fix-MC-177381.patch} | 0 ...Asynchronous-locator.patch => 0120-Asynchronous-locator.patch} | 0 ...executor.patch => 0121-Virtual-thread-for-chat-executor.patch} | 0 29 files changed, 0 insertions(+), 0 deletions(-) rename patches/server/{0121-Remove-stream-in-YieldJobSite.patch => 0093-Remove-stream-in-YieldJobSite.patch} (100%) rename patches/server/{0093-Replace-Entity-active-effects-map-with-optimized-col.patch => 0094-Replace-Entity-active-effects-map-with-optimized-col.patch} (100%) rename patches/server/{0094-Replace-brain-maps-with-optimized-collection.patch => 0095-Replace-brain-maps-with-optimized-collection.patch} (100%) rename patches/server/{0095-Reduce-worldgen-allocations.patch => 0096-Reduce-worldgen-allocations.patch} (100%) rename patches/server/{0096-Fix-MC-183518.patch => 0097-Fix-MC-183518.patch} (100%) rename patches/server/{0097-Use-caffeine-cache-kickPermission-instead-of-using-g.patch => 0098-Use-caffeine-cache-kickPermission-instead-of-using-g.patch} (100%) rename patches/server/{0098-Do-not-place-player-if-the-server-is-full.patch => 0099-Do-not-place-player-if-the-server-is-full.patch} (100%) rename patches/server/{0099-Fix-MC-200418.patch => 0100-Fix-MC-200418.patch} (100%) rename patches/server/{0100-Fix-MC-119417.patch => 0101-Fix-MC-119417.patch} (100%) rename patches/server/{0101-Fix-MC-223153.patch => 0102-Fix-MC-223153.patch} (100%) rename patches/server/{0102-Optimize-LeavesProtocolManager-init-protocol.patch => 0103-Optimize-LeavesProtocolManager-init-protocol.patch} (100%) rename patches/server/{0103-Cache-CraftEntityType-minecraftToBukkit-convert.patch => 0104-Cache-CraftEntityType-minecraftToBukkit-convert.patch} (100%) rename patches/server/{0104-Configurable-player-knockback-zombie.patch => 0105-Configurable-player-knockback-zombie.patch} (100%) rename patches/server/{0105-Hide-specified-item-components-to-clients.patch => 0106-Hide-specified-item-components-to-clients.patch} (100%) rename patches/server/{0106-Paper-PR-Skip-AI-during-inactive-ticks-for-non-aware.patch => 0107-Paper-PR-Skip-AI-during-inactive-ticks-for-non-aware.patch} (100%) rename patches/server/{0107-Paper-PR-Reduce-work-done-in-CraftMapCanvas.drawImag.patch => 0108-Paper-PR-Reduce-work-done-in-CraftMapCanvas.drawImag.patch} (100%) rename patches/server/{0108-Paper-PR-Throttle-failed-spawn-attempts.patch => 0109-Paper-PR-Throttle-failed-spawn-attempts.patch} (100%) rename patches/server/{0109-Paper-PR-Prevent-zombie-reinforcements-loading-chunk.patch => 0110-Paper-PR-Prevent-zombie-reinforcements-loading-chunk.patch} (100%) rename patches/server/{0110-Dont-send-useless-entity-packets.patch => 0111-Dont-send-useless-entity-packets.patch} (100%) rename patches/server/{0111-Don-t-spawn-if-lastSpawnState-is-null.patch => 0112-Don-t-spawn-if-lastSpawnState-is-null.patch} (100%) rename patches/server/{0112-Multithreaded-Tracker.patch => 0113-Multithreaded-Tracker.patch} (100%) rename patches/server/{0113-Nitori-Async-playerdata-Save.patch => 0114-Nitori-Async-playerdata-Save.patch} (100%) rename patches/server/{0114-Change-max-stack-count.patch => 0115-Change-max-stack-count.patch} (100%) rename patches/server/{0115-Reduce-object-complexity-to-make-block-isValid-calls.patch => 0116-Reduce-object-complexity-to-make-block-isValid-calls.patch} (100%) rename patches/server/{0116-Optimize-nearby-alive-players-for-spawning.patch => 0117-Optimize-nearby-alive-players-for-spawning.patch} (100%) rename patches/server/{0117-Cache-blockstate-cache.patch => 0118-Cache-blockstate-cache.patch} (100%) rename patches/server/{0118-Fix-MC-177381.patch => 0119-Fix-MC-177381.patch} (100%) rename patches/server/{0119-Asynchronous-locator.patch => 0120-Asynchronous-locator.patch} (100%) rename patches/server/{0120-Virtual-thread-for-chat-executor.patch => 0121-Virtual-thread-for-chat-executor.patch} (100%) diff --git a/patches/server/0121-Remove-stream-in-YieldJobSite.patch b/patches/server/0093-Remove-stream-in-YieldJobSite.patch similarity index 100% rename from patches/server/0121-Remove-stream-in-YieldJobSite.patch rename to patches/server/0093-Remove-stream-in-YieldJobSite.patch diff --git a/patches/server/0093-Replace-Entity-active-effects-map-with-optimized-col.patch b/patches/server/0094-Replace-Entity-active-effects-map-with-optimized-col.patch similarity index 100% rename from patches/server/0093-Replace-Entity-active-effects-map-with-optimized-col.patch rename to patches/server/0094-Replace-Entity-active-effects-map-with-optimized-col.patch diff --git a/patches/server/0094-Replace-brain-maps-with-optimized-collection.patch b/patches/server/0095-Replace-brain-maps-with-optimized-collection.patch similarity index 100% rename from patches/server/0094-Replace-brain-maps-with-optimized-collection.patch rename to patches/server/0095-Replace-brain-maps-with-optimized-collection.patch diff --git a/patches/server/0095-Reduce-worldgen-allocations.patch b/patches/server/0096-Reduce-worldgen-allocations.patch similarity index 100% rename from patches/server/0095-Reduce-worldgen-allocations.patch rename to patches/server/0096-Reduce-worldgen-allocations.patch diff --git a/patches/server/0096-Fix-MC-183518.patch b/patches/server/0097-Fix-MC-183518.patch similarity index 100% rename from patches/server/0096-Fix-MC-183518.patch rename to patches/server/0097-Fix-MC-183518.patch diff --git a/patches/server/0097-Use-caffeine-cache-kickPermission-instead-of-using-g.patch b/patches/server/0098-Use-caffeine-cache-kickPermission-instead-of-using-g.patch similarity index 100% rename from patches/server/0097-Use-caffeine-cache-kickPermission-instead-of-using-g.patch rename to patches/server/0098-Use-caffeine-cache-kickPermission-instead-of-using-g.patch diff --git a/patches/server/0098-Do-not-place-player-if-the-server-is-full.patch b/patches/server/0099-Do-not-place-player-if-the-server-is-full.patch similarity index 100% rename from patches/server/0098-Do-not-place-player-if-the-server-is-full.patch rename to patches/server/0099-Do-not-place-player-if-the-server-is-full.patch diff --git a/patches/server/0099-Fix-MC-200418.patch b/patches/server/0100-Fix-MC-200418.patch similarity index 100% rename from patches/server/0099-Fix-MC-200418.patch rename to patches/server/0100-Fix-MC-200418.patch diff --git a/patches/server/0100-Fix-MC-119417.patch b/patches/server/0101-Fix-MC-119417.patch similarity index 100% rename from patches/server/0100-Fix-MC-119417.patch rename to patches/server/0101-Fix-MC-119417.patch diff --git a/patches/server/0101-Fix-MC-223153.patch b/patches/server/0102-Fix-MC-223153.patch similarity index 100% rename from patches/server/0101-Fix-MC-223153.patch rename to patches/server/0102-Fix-MC-223153.patch diff --git a/patches/server/0102-Optimize-LeavesProtocolManager-init-protocol.patch b/patches/server/0103-Optimize-LeavesProtocolManager-init-protocol.patch similarity index 100% rename from patches/server/0102-Optimize-LeavesProtocolManager-init-protocol.patch rename to patches/server/0103-Optimize-LeavesProtocolManager-init-protocol.patch diff --git a/patches/server/0103-Cache-CraftEntityType-minecraftToBukkit-convert.patch b/patches/server/0104-Cache-CraftEntityType-minecraftToBukkit-convert.patch similarity index 100% rename from patches/server/0103-Cache-CraftEntityType-minecraftToBukkit-convert.patch rename to patches/server/0104-Cache-CraftEntityType-minecraftToBukkit-convert.patch diff --git a/patches/server/0104-Configurable-player-knockback-zombie.patch b/patches/server/0105-Configurable-player-knockback-zombie.patch similarity index 100% rename from patches/server/0104-Configurable-player-knockback-zombie.patch rename to patches/server/0105-Configurable-player-knockback-zombie.patch diff --git a/patches/server/0105-Hide-specified-item-components-to-clients.patch b/patches/server/0106-Hide-specified-item-components-to-clients.patch similarity index 100% rename from patches/server/0105-Hide-specified-item-components-to-clients.patch rename to patches/server/0106-Hide-specified-item-components-to-clients.patch diff --git a/patches/server/0106-Paper-PR-Skip-AI-during-inactive-ticks-for-non-aware.patch b/patches/server/0107-Paper-PR-Skip-AI-during-inactive-ticks-for-non-aware.patch similarity index 100% rename from patches/server/0106-Paper-PR-Skip-AI-during-inactive-ticks-for-non-aware.patch rename to patches/server/0107-Paper-PR-Skip-AI-during-inactive-ticks-for-non-aware.patch diff --git a/patches/server/0107-Paper-PR-Reduce-work-done-in-CraftMapCanvas.drawImag.patch b/patches/server/0108-Paper-PR-Reduce-work-done-in-CraftMapCanvas.drawImag.patch similarity index 100% rename from patches/server/0107-Paper-PR-Reduce-work-done-in-CraftMapCanvas.drawImag.patch rename to patches/server/0108-Paper-PR-Reduce-work-done-in-CraftMapCanvas.drawImag.patch diff --git a/patches/server/0108-Paper-PR-Throttle-failed-spawn-attempts.patch b/patches/server/0109-Paper-PR-Throttle-failed-spawn-attempts.patch similarity index 100% rename from patches/server/0108-Paper-PR-Throttle-failed-spawn-attempts.patch rename to patches/server/0109-Paper-PR-Throttle-failed-spawn-attempts.patch diff --git a/patches/server/0109-Paper-PR-Prevent-zombie-reinforcements-loading-chunk.patch b/patches/server/0110-Paper-PR-Prevent-zombie-reinforcements-loading-chunk.patch similarity index 100% rename from patches/server/0109-Paper-PR-Prevent-zombie-reinforcements-loading-chunk.patch rename to patches/server/0110-Paper-PR-Prevent-zombie-reinforcements-loading-chunk.patch diff --git a/patches/server/0110-Dont-send-useless-entity-packets.patch b/patches/server/0111-Dont-send-useless-entity-packets.patch similarity index 100% rename from patches/server/0110-Dont-send-useless-entity-packets.patch rename to patches/server/0111-Dont-send-useless-entity-packets.patch diff --git a/patches/server/0111-Don-t-spawn-if-lastSpawnState-is-null.patch b/patches/server/0112-Don-t-spawn-if-lastSpawnState-is-null.patch similarity index 100% rename from patches/server/0111-Don-t-spawn-if-lastSpawnState-is-null.patch rename to patches/server/0112-Don-t-spawn-if-lastSpawnState-is-null.patch diff --git a/patches/server/0112-Multithreaded-Tracker.patch b/patches/server/0113-Multithreaded-Tracker.patch similarity index 100% rename from patches/server/0112-Multithreaded-Tracker.patch rename to patches/server/0113-Multithreaded-Tracker.patch diff --git a/patches/server/0113-Nitori-Async-playerdata-Save.patch b/patches/server/0114-Nitori-Async-playerdata-Save.patch similarity index 100% rename from patches/server/0113-Nitori-Async-playerdata-Save.patch rename to patches/server/0114-Nitori-Async-playerdata-Save.patch diff --git a/patches/server/0114-Change-max-stack-count.patch b/patches/server/0115-Change-max-stack-count.patch similarity index 100% rename from patches/server/0114-Change-max-stack-count.patch rename to patches/server/0115-Change-max-stack-count.patch diff --git a/patches/server/0115-Reduce-object-complexity-to-make-block-isValid-calls.patch b/patches/server/0116-Reduce-object-complexity-to-make-block-isValid-calls.patch similarity index 100% rename from patches/server/0115-Reduce-object-complexity-to-make-block-isValid-calls.patch rename to patches/server/0116-Reduce-object-complexity-to-make-block-isValid-calls.patch diff --git a/patches/server/0116-Optimize-nearby-alive-players-for-spawning.patch b/patches/server/0117-Optimize-nearby-alive-players-for-spawning.patch similarity index 100% rename from patches/server/0116-Optimize-nearby-alive-players-for-spawning.patch rename to patches/server/0117-Optimize-nearby-alive-players-for-spawning.patch diff --git a/patches/server/0117-Cache-blockstate-cache.patch b/patches/server/0118-Cache-blockstate-cache.patch similarity index 100% rename from patches/server/0117-Cache-blockstate-cache.patch rename to patches/server/0118-Cache-blockstate-cache.patch diff --git a/patches/server/0118-Fix-MC-177381.patch b/patches/server/0119-Fix-MC-177381.patch similarity index 100% rename from patches/server/0118-Fix-MC-177381.patch rename to patches/server/0119-Fix-MC-177381.patch diff --git a/patches/server/0119-Asynchronous-locator.patch b/patches/server/0120-Asynchronous-locator.patch similarity index 100% rename from patches/server/0119-Asynchronous-locator.patch rename to patches/server/0120-Asynchronous-locator.patch diff --git a/patches/server/0120-Virtual-thread-for-chat-executor.patch b/patches/server/0121-Virtual-thread-for-chat-executor.patch similarity index 100% rename from patches/server/0120-Virtual-thread-for-chat-executor.patch rename to patches/server/0121-Virtual-thread-for-chat-executor.patch From 92a721113d47239f3ea089cb3dfec66f81a8daf6 Mon Sep 17 00:00:00 2001 From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com> Date: Sat, 26 Oct 2024 17:39:33 +0800 Subject: [PATCH 4/4] Use quicksort --- ...ickSort-in-NearestLivingEntitySensor.patch} | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) rename patches/server/{0122-Use-parallelQuickSort-in-NearestLivingEntitySensor.patch => 0122-Use-QuickSort-in-NearestLivingEntitySensor.patch} (70%) diff --git a/patches/server/0122-Use-parallelQuickSort-in-NearestLivingEntitySensor.patch b/patches/server/0122-Use-QuickSort-in-NearestLivingEntitySensor.patch similarity index 70% rename from patches/server/0122-Use-parallelQuickSort-in-NearestLivingEntitySensor.patch rename to patches/server/0122-Use-QuickSort-in-NearestLivingEntitySensor.patch index d8d49b1d3..2d665cf53 100644 --- a/patches/server/0122-Use-parallelQuickSort-in-NearestLivingEntitySensor.patch +++ b/patches/server/0122-Use-QuickSort-in-NearestLivingEntitySensor.patch @@ -1,11 +1,11 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com> Date: Sat, 26 Oct 2024 15:00:21 +0800 -Subject: [PATCH] Use parallelQuickSort in NearestLivingEntitySensor +Subject: [PATCH] Use QuickSort in NearestLivingEntitySensor diff --git a/src/main/java/net/minecraft/world/entity/ai/sensing/NearestLivingEntitySensor.java b/src/main/java/net/minecraft/world/entity/ai/sensing/NearestLivingEntitySensor.java -index 5a059e1ec232d82e8e891ae78fea962bec2f878e..f6cdabf05b034fab5f72d098017bf1115e9ffb57 100644 +index 5a059e1ec232d82e8e891ae78fea962bec2f878e..490c5322f8286f92f9ba4583f59ed60618ad33e5 100644 --- a/src/main/java/net/minecraft/world/entity/ai/sensing/NearestLivingEntitySensor.java +++ b/src/main/java/net/minecraft/world/entity/ai/sensing/NearestLivingEntitySensor.java @@ -16,10 +16,16 @@ public class NearestLivingEntitySensor extends Sensor @@ -13,18 +13,18 @@ index 5a059e1ec232d82e8e891ae78fea962bec2f878e..f6cdabf05b034fab5f72d098017bf111 AABB aABB = entity.getBoundingBox().inflate((double)this.radiusXZ(), (double)this.radiusY(), (double)this.radiusXZ()); List list = world.getEntitiesOfClass(LivingEntity.class, aABB, e -> e != entity && e.isAlive()); - list.sort(Comparator.comparingDouble(entity::distanceToSqr)); -+ // Leaf start - Use parallelQuickSort in NearestLivingEntitySensor -+ LivingEntity[] sorted = list.toArray(new LivingEntity[]{}); -+ it.unimi.dsi.fastutil.objects.ObjectArrays.parallelQuickSort(sorted, Comparator.comparingDouble(entity::distanceToSqr)); -+ List sortedList = java.util.Arrays.asList(sorted); -+ // Leaf end - Use parallelQuickSort in NearestLivingEntitySensor ++ // Leaf start - Use QuickSort in NearestLivingEntitySensor ++ LivingEntity[] sortArray = list.toArray(new LivingEntity[]{}); ++ it.unimi.dsi.fastutil.objects.ObjectArrays.quickSort(sortArray, Comparator.comparingDouble(entity::distanceToSqr)); ++ List sortedList = java.util.Arrays.asList(sortArray); ++ // Leaf end - Use QuickSort in NearestLivingEntitySensor Brain brain = entity.getBrain(); - brain.setMemory(MemoryModuleType.NEAREST_LIVING_ENTITIES, list); - brain.setMemory(MemoryModuleType.NEAREST_VISIBLE_LIVING_ENTITIES, new NearestVisibleLivingEntities(entity, list)); -+ // Leaf start - Use parallelQuickSort in NearestLivingEntitySensor ++ // Leaf start - Use QuickSort in NearestLivingEntitySensor + brain.setMemory(MemoryModuleType.NEAREST_LIVING_ENTITIES, sortedList); + brain.setMemory(MemoryModuleType.NEAREST_VISIBLE_LIVING_ENTITIES, new NearestVisibleLivingEntities(entity, sortedList)); -+ // Leaf end - Use parallelQuickSort in NearestLivingEntitySensor ++ // Leaf end - Use QuickSort in NearestLivingEntitySensor } protected int radiusXZ() {