mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
1. Wet the drys 2. Dry the wets 3. Wet the drys 4. Dry the wets 5. Wet the drys 6. Now dust the wets
73 lines
3.1 KiB
Diff
73 lines
3.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Taiyou06 <kaandindar21@gmail.com>
|
|
Date: Fri, 14 Feb 2025 14:58:59 +0100
|
|
Subject: [PATCH] Alternative Brain Behaviour
|
|
|
|
In the test, this can give ~54.87% improvement (~25712ms -> ~11604ms),
|
|
under 1024 villagers situation.
|
|
|
|
diff --git a/net/minecraft/world/entity/ai/Brain.java b/net/minecraft/world/entity/ai/Brain.java
|
|
index e27284f9897923f67985e3d60c3438bd00cc4a51..0ff7564e0e848bd38e82f9089bfd7249fa649dc5 100644
|
|
--- a/net/minecraft/world/entity/ai/Brain.java
|
|
+++ b/net/minecraft/world/entity/ai/Brain.java
|
|
@@ -268,23 +268,52 @@ public class Brain<E extends LivingEntity> {
|
|
return this.activeActivities;
|
|
}
|
|
|
|
+ // Leaf start - Alternative Brain Behaviour
|
|
+ private ObjectArrayList<BehaviorControl<? super E>> runningBehaviorsCache;
|
|
+ private long lastRunningBehaviorCheck = -1;
|
|
+ // Leaf end - Alternative Brain Behaviour
|
|
+
|
|
@Deprecated
|
|
@VisibleForDebug
|
|
public List<BehaviorControl<? super E>> getRunningBehaviors() {
|
|
- List<BehaviorControl<? super E>> list = new ObjectArrayList<>();
|
|
+ // Leaf start - Alternative Brain Behaviour
|
|
+ long currentTick = getCurrentTick();
|
|
+
|
|
+ // Use cached result if within update interval
|
|
+ if (runningBehaviorsCache != null && (currentTick - lastRunningBehaviorCheck) < org.dreeam.leaf.config.modules.opt.BrainRunningBehaviorCacheUpdate.interval) {
|
|
+ return runningBehaviorsCache;
|
|
+ }
|
|
+
|
|
+ // Initialize or reuse cache list
|
|
+ if (runningBehaviorsCache == null) {
|
|
+ runningBehaviorsCache = new ObjectArrayList<>(32);
|
|
+ } else {
|
|
+ runningBehaviorsCache.clear();
|
|
+ }
|
|
+
|
|
+ for (Map<Activity, Set<BehaviorControl<? super E>>> activityMap : availableBehaviorsByPriority.values()) {
|
|
+ for (Set<BehaviorControl<? super E>> behaviors : activityMap.values()) {
|
|
+ if (behaviors.isEmpty()) continue;
|
|
|
|
- for (Map<Activity, Set<BehaviorControl<? super E>>> map : this.availableBehaviorsByPriority.values()) {
|
|
- for (Set<BehaviorControl<? super E>> set : map.values()) {
|
|
- for (BehaviorControl<? super E> behaviorControl : set) {
|
|
- if (behaviorControl.getStatus() == Behavior.Status.RUNNING) {
|
|
- list.add(behaviorControl);
|
|
+ for (BehaviorControl<? super E> behavior : behaviors) {
|
|
+ if (behavior.getStatus() == Behavior.Status.RUNNING) {
|
|
+ runningBehaviorsCache.add(behavior);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
- return list;
|
|
+ lastRunningBehaviorCheck = currentTick;
|
|
+
|
|
+ return runningBehaviorsCache;
|
|
+ }
|
|
+
|
|
+ // Helper method to get current tick
|
|
+ private long getCurrentTick() {
|
|
+ // This should be implemented to return the current game tick
|
|
+ return System.nanoTime() / 50_000_000; // Approximate tick time of 50ms
|
|
}
|
|
+ // Leaf end - Alternative Brain Behaviour
|
|
|
|
public void useDefaultActivity() {
|
|
this.setActiveActivity(this.defaultActivity);
|