mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-21 07:49:29 +00:00
Reduce living enitty sensing
This commit is contained in:
36
patches/server/0034-Reduce-living-entity-sensing.patch
Normal file
36
patches/server/0034-Reduce-living-entity-sensing.patch
Normal file
@@ -0,0 +1,36 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Samsuik <40902469+Samsuik@users.noreply.github.com>
|
||||
Date: Sat, 18 Nov 2023 17:24:19 +0000
|
||||
Subject: [PATCH] Reduce living entity sensing
|
||||
|
||||
|
||||
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 d8cf99a3014a4b8152ae819fa663c2fdf34dce57..f7c3684ddd7c9c5386256511a867c29f01ab1697 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
|
||||
@@ -15,10 +15,21 @@ public class NearestLivingEntitySensor<T extends LivingEntity> extends Sensor<T>
|
||||
@Override
|
||||
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) -> {
|
||||
- return e != entity && e.isAlive();
|
||||
- });
|
||||
- list.sort(Comparator.comparingDouble(entity::distanceToSqr));
|
||||
+ // Sakura start - reduce nearest living sensing
|
||||
+ var distanceMap = new it.unimi.dsi.fastutil.objects.Reference2DoubleOpenHashMap<>();
|
||||
+ distanceMap.defaultReturnValue(Double.MAX_VALUE);
|
||||
+ List<LivingEntity> list = world.getLimitedEntitiesOfClass(LivingEntity.class, aABB, (e) -> {
|
||||
+ if (e == entity || !e.isAlive())
|
||||
+ return false;
|
||||
+ double stored = distanceMap.getDouble(e.getType());
|
||||
+ double distance = e.distanceToSqr(entity);
|
||||
+ if (stored < distance)
|
||||
+ return false;
|
||||
+ distanceMap.put(e.getType(), distance);
|
||||
+ return true;
|
||||
+ }, 12, Integer.MAX_VALUE);
|
||||
+ java.util.Collections.reverse(list);
|
||||
+ // Sakura end
|
||||
Brain<?> brain = entity.getBrain();
|
||||
brain.setMemory(MemoryModuleType.NEAREST_LIVING_ENTITIES, list);
|
||||
brain.setMemory(MemoryModuleType.NEAREST_VISIBLE_LIVING_ENTITIES, new NearestVisibleLivingEntities(entity, list));
|
||||
Reference in New Issue
Block a user