mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-23 00:49:31 +00:00
Moonrise: block counting optimisations
This commit is contained in:
@@ -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 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() {
|
||||
Reference in New Issue
Block a user