mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-26 02:19:19 +00:00
ClassInstanceMultiMap belongs to Minecraft vanilla entity storage. And is unused, since replaced by spottedleaf's entity storage (rewrite chunk system). However these patches might be useful for vanilla entity storage if is used.
37 lines
2.3 KiB
Diff
37 lines
2.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Taiyou06 <kaandindar21@gmail.com>
|
|
Date: Sat, 10 May 2025 22:04:42 +0200
|
|
Subject: [PATCH] Smart sort items in NearestItemSensor
|
|
|
|
|
|
diff --git a/net/minecraft/world/entity/ai/sensing/NearestItemSensor.java b/net/minecraft/world/entity/ai/sensing/NearestItemSensor.java
|
|
index 09fd13e2d958da8326276c4dadf25bf488aff5ac..651797720f7fc6ff9dc614f4de56053c304b1170 100644
|
|
--- a/net/minecraft/world/entity/ai/sensing/NearestItemSensor.java
|
|
+++ b/net/minecraft/world/entity/ai/sensing/NearestItemSensor.java
|
|
@@ -16,6 +16,12 @@ public class NearestItemSensor extends Sensor<Mob> {
|
|
private static final long Y_RANGE = 16L;
|
|
public static final int MAX_DISTANCE_TO_WANTED_ITEM = 32;
|
|
|
|
+ // Leaf start - Smart sort items in NearestItemSensor
|
|
+ private final org.dreeam.leaf.util.FastBitRadixSort itemSorter;
|
|
+ public NearestItemSensor() {
|
|
+ this.itemSorter = new org.dreeam.leaf.util.FastBitRadixSort();
|
|
+ }
|
|
+ // Leaf end - Smart sort items in NearestItemSensor
|
|
@Override
|
|
public Set<MemoryModuleType<?>> requires() {
|
|
return ImmutableSet.of(MemoryModuleType.NEAREST_VISIBLE_WANTED_ITEM);
|
|
@@ -25,10 +31,10 @@ public class NearestItemSensor extends Sensor<Mob> {
|
|
protected void doTick(ServerLevel level, Mob entity) {
|
|
Brain<?> brain = entity.getBrain();
|
|
List<ItemEntity> entitiesOfClass = level.getEntitiesOfClass(ItemEntity.class, entity.getBoundingBox().inflate(32.0, 16.0, 32.0), itemEntity -> itemEntity.closerThan(entity, MAX_DISTANCE_TO_WANTED_ITEM) && entity.wantsToPickUp(level, itemEntity.getItem())); // Paper - Perf: Move predicate into getEntities
|
|
- entitiesOfClass.sort(Comparator.comparingDouble(entity::distanceToSqr));
|
|
+ ItemEntity[] sortedItems = this.itemSorter.sort(entitiesOfClass, entity, ItemEntity.class); // Leaf - Smart sort items in NearestItemSensor
|
|
// Paper start - Perf: remove streams from hot code
|
|
ItemEntity nearest = null;
|
|
- for (final ItemEntity itemEntity : entitiesOfClass) {
|
|
+ for (final ItemEntity itemEntity : sortedItems) { // Leaf - Smart sort items in NearestItemSensor
|
|
if (entity.hasLineOfSight(itemEntity)) { // Paper - Perf: Move predicate into getEntities
|
|
nearest = itemEntity;
|
|
break;
|