mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2026-01-04 15:41:40 +00:00
55 lines
3.0 KiB
Diff
55 lines
3.0 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Taiyou06 <kaandindar21@gmail.com>
|
|
Date: Sat, 8 Feb 2025 22:36:31 +0100
|
|
Subject: [PATCH] Optimize baby villager sensor
|
|
|
|
In the test, this can give ~16.58% improvement (~2316ms -> ~1932ms),
|
|
under 2048 villagers situation.
|
|
And ~42.93% improvement (~764ms -> ~436ms), under 512 villagers situation.
|
|
|
|
diff --git a/net/minecraft/world/entity/ai/memory/NearestVisibleLivingEntities.java b/net/minecraft/world/entity/ai/memory/NearestVisibleLivingEntities.java
|
|
index 1c010e5b75506945e5281021a2ddad424044d28f..2b973a3ba7d65330fa4690e71e5321c28457ec61 100644
|
|
--- a/net/minecraft/world/entity/ai/memory/NearestVisibleLivingEntities.java
|
|
+++ b/net/minecraft/world/entity/ai/memory/NearestVisibleLivingEntities.java
|
|
@@ -42,7 +42,7 @@ public class NearestVisibleLivingEntities {
|
|
}
|
|
|
|
public Iterable<LivingEntity> findAll(Predicate<LivingEntity> predicate) {
|
|
- return Iterables.filter(this.nearbyEntities, target -> predicate.test(target) && this.lineOfSightTest.test(target));
|
|
+ return Iterables.filter(this.nearbyEntities, target -> predicate.test(target) && this.lineOfSightTest.test(target)); // Leaf - Optimize baby villager sensor - diff on change
|
|
}
|
|
|
|
public Stream<LivingEntity> find(Predicate<LivingEntity> predicate) {
|
|
diff --git a/net/minecraft/world/entity/ai/sensing/VillagerBabiesSensor.java b/net/minecraft/world/entity/ai/sensing/VillagerBabiesSensor.java
|
|
index 24d1928445b5571e040a2b12d5c82e77a880d9bd..4b2964aeb4e21fe41f42c2902db63ce28322063a 100644
|
|
--- a/net/minecraft/world/entity/ai/sensing/VillagerBabiesSensor.java
|
|
+++ b/net/minecraft/world/entity/ai/sensing/VillagerBabiesSensor.java
|
|
@@ -22,11 +22,25 @@ public class VillagerBabiesSensor extends Sensor<LivingEntity> {
|
|
}
|
|
|
|
private List<LivingEntity> getNearestVillagerBabies(LivingEntity livingEntity) {
|
|
- return ImmutableList.copyOf(this.getVisibleEntities(livingEntity).findAll(this::isVillagerBaby));
|
|
+ // Leaf start - Optimize baby villager sensor
|
|
+ NearestVisibleLivingEntities visibleEntities = this.getVisibleEntities(livingEntity);
|
|
+ ImmutableList.Builder<LivingEntity> babies = ImmutableList.builder();
|
|
+
|
|
+ // Inline and use single loop - copy from NearestVisibleLivingEntities#findAll and isVillagerBaby
|
|
+ for (LivingEntity target : visibleEntities.nearbyEntities) {
|
|
+ if (target.getType() == EntityType.VILLAGER
|
|
+ && target.isBaby()
|
|
+ && visibleEntities.lineOfSightTest.test(target)) {
|
|
+ babies.add(target);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return babies.build();
|
|
+ // Leaf end - Optimize baby villager sensor
|
|
}
|
|
|
|
private boolean isVillagerBaby(LivingEntity livingEntity) {
|
|
- return livingEntity.getType() == EntityType.VILLAGER && livingEntity.isBaby();
|
|
+ return livingEntity.getType() == EntityType.VILLAGER && livingEntity.isBaby(); // Leaf - Optimize baby villager sensor - diff on change
|
|
}
|
|
|
|
private NearestVisibleLivingEntities getVisibleEntities(LivingEntity livingEntity) {
|