-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
9 additions
and
9 deletions.
There are no files selected for viewing
18 changes: 9 additions & 9 deletions
18
...ckSort-in-NearestLivingEntitySensor.patch → ...ckSort-in-NearestLivingEntitySensor.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +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 | ||
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<T extends LivingEntity> extends Sensor<T> | ||
protected void doTick(ServerLevel world, T entity) { | ||
AABB aABB = entity.getBoundingBox().inflate((double)this.radiusXZ(), (double)this.radiusY(), (double)this.radiusXZ()); | ||
List<LivingEntity> 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<LivingEntity> 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<LivingEntity> 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() { |