From c264e38a8db71edd16dac3fa071af98f4855673c Mon Sep 17 00:00:00 2001 From: Samsuik <40902469+Samsuik@users.noreply.github.com> Date: Sun, 19 Nov 2023 21:18:00 +0000 Subject: [PATCH] Reduce living enitty sensing --- .../0034-Reduce-living-entity-sensing.patch | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 patches/server/0034-Reduce-living-entity-sensing.patch diff --git a/patches/server/0034-Reduce-living-entity-sensing.patch b/patches/server/0034-Reduce-living-entity-sensing.patch new file mode 100644 index 0000000..5293afb --- /dev/null +++ b/patches/server/0034-Reduce-living-entity-sensing.patch @@ -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 extends Sensor + @Override + protected void doTick(ServerLevel world, T entity) { + AABB aABB = entity.getBoundingBox().inflate((double)this.radiusXZ(), (double)this.radiusY(), (double)this.radiusXZ()); +- List 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 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));