9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-20 23:49:31 +00:00
Files
Leaf/patches/server/0151-Collect-then-startEachNonRunningBehavior-in-Brain.patch
Dreeam 27134f699a Added some optimizations (#164)
* uwu

* reorder

* Change author

* Sync upstream

* Lithium: equipment tracking

* Faster CraftServer#getworlds list creation

Co-Authored-By: Kobe ⑧ <102713261+HaHaWTH@users.noreply.github.com>
2024-11-14 06:50:59 -05:00

50 lines
2.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Tue, 9 Nov 2077 00:00:00 +0800
Subject: [PATCH] Collect then startEachNonRunningBehavior in Brain
diff --git a/src/main/java/net/minecraft/world/entity/ai/Brain.java b/src/main/java/net/minecraft/world/entity/ai/Brain.java
index 65bd8c2cccd0a4a68984ea8ff4cd3cf365330630..aeb74b96704e0f187178e2ae106e0a3f6d95717c 100644
--- a/src/main/java/net/minecraft/world/entity/ai/Brain.java
+++ b/src/main/java/net/minecraft/world/entity/ai/Brain.java
@@ -466,20 +466,30 @@ public class Brain<E extends LivingEntity> {
}
private void startEachNonRunningBehavior(ServerLevel world, E entity) {
- long l = world.getGameTime();
+ // Leaf start - Collect first then start
+ final long gameTime = world.getGameTime();
- for (Map<Activity, Set<BehaviorControl<? super E>>> map : this.availableBehaviorsByPriority.values()) {
- for (Entry<Activity, Set<BehaviorControl<? super E>>> entry : map.entrySet()) {
- Activity activity = entry.getKey();
- if (this.activeActivities.contains(activity)) {
- for (BehaviorControl<? super E> behaviorControl : entry.getValue()) {
- if (behaviorControl.getStatus() == Behavior.Status.STOPPED) {
- behaviorControl.tryStart(world, entity, l);
+ List<BehaviorControl<? super E>> behaviorsToStart = new ObjectArrayList<>();
+
+ for (Activity activeActivity : this.activeActivities) {
+ for (Map<Activity, Set<BehaviorControl<? super E>>> priorityMap : this.availableBehaviorsByPriority.values()) {
+ Set<BehaviorControl<? super E>> behaviors = priorityMap.get(activeActivity);
+
+ if (behaviors != null && !behaviors.isEmpty()) {
+ for (BehaviorControl<? super E> behavior : behaviors) {
+ if (behavior.getStatus() == Behavior.Status.STOPPED) {
+ behaviorsToStart.add(behavior);
}
}
}
}
}
+ if (!behaviorsToStart.isEmpty()) {
+ for (BehaviorControl<? super E> behavior : behaviorsToStart) {
+ behavior.tryStart(world, entity, gameTime);
+ }
+ }
+ // Leaf end - Collect first then start
}
private void tickEachRunningBehavior(ServerLevel world, E entity) {