mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
* DivineMC - Lithium: Early checks for LivingEntity#updateSwingTime and updateFallFlying * C2ME-Reduce-Allocations * Lithium-fast-util * Lithium-CompactSineLUT * Compact-SineLUT * some lithium patches * Create 0141-Use-MCUtil.asyncExecutor-for-MAIN_WORKER_EXECUTOR.patch * Fix tick function & Better inline world height * improve the clamp logic by 1.2x * Remove imports on IterateOutwardsCache * Remove imports from 141 * Rename getCachedOrNewBits to CachedOrNewBitsGetter * Remove thread instanceof checks --------- Co-authored-by: kidofcubes <kidofcubes@gmail.com>
31 lines
2.1 KiB
Diff
31 lines
2.1 KiB
Diff
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 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..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 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 QuickSort in NearestLivingEntitySensor
|
|
+ brain.setMemory(MemoryModuleType.NEAREST_LIVING_ENTITIES, sortedList);
|
|
+ brain.setMemory(MemoryModuleType.NEAREST_VISIBLE_LIVING_ENTITIES, new NearestVisibleLivingEntities(entity, sortedList));
|
|
+ // Leaf end - Use QuickSort in NearestLivingEntitySensor
|
|
}
|
|
|
|
protected int radiusXZ() {
|