9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0272-Use-ActivationList-on-runningBehaviors.patch
2025-06-27 19:11:50 +08:00

106 lines
4.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Sat, 7 Jun 2025 23:22:56 +0200
Subject: [PATCH] Use ActivationList on runningBehaviors
diff --git a/net/minecraft/world/entity/ai/Brain.java b/net/minecraft/world/entity/ai/Brain.java
index 7f6572d2259cd244222e5893c9e906075cc3cb92..521f07a1ef8bfa708fcabf1434fdf133022ee92a 100644
--- a/net/minecraft/world/entity/ai/Brain.java
+++ b/net/minecraft/world/entity/ai/Brain.java
@@ -61,6 +61,7 @@ public class Brain<E extends LivingEntity> {
private long lastScheduleUpdate = -9999L;
private ObjectArrayList<BehaviorControl<? super E>> cachedPotentialBehaviors; // Leaf - Cache potential behaviors in Brain
+ private org.dreeam.leaf.util.list.ActivationList<BehaviorControl<? super E>> runningBehaviors; // Leaf - Use ActivationList on runningBehaviors
public static <E extends LivingEntity> Brain.Provider<E> provider(
Collection<? extends MemoryModuleType<?>> memoryTypes, Collection<? extends SensorType<? extends Sensor<? super E>>> sensorTypes
) {
@@ -273,19 +274,7 @@ public class Brain<E extends LivingEntity> {
@Deprecated
@VisibleForDebug
public List<BehaviorControl<? super E>> getRunningBehaviors() {
- List<BehaviorControl<? super E>> list = new ObjectArrayList<>();
-
- 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);
- }
- }
- }
- }
-
- return list;
+ return this.getRunningBehaviorsList(); // Leaf - Use ActivationList on runningBehaviors
}
public void useDefaultActivity() {
@@ -462,6 +451,7 @@ public class Brain<E extends LivingEntity> {
long gameTime = owner.level().getGameTime();
for (BehaviorControl<? super E> behaviorControl : this.getRunningBehaviors()) {
+ this.getRunningBehaviorsList().setVisibility(behaviorControl, false); // Leaf - Use ActivationList on runningBehaviors
behaviorControl.doStop(level, owner, gameTime);
}
}
@@ -469,6 +459,7 @@ public class Brain<E extends LivingEntity> {
// Leaf start - Cache potential behaviors in Brain
private void invalidateBehaviorCache() {
this.cachedPotentialBehaviors = null;
+ this.runningBehaviors = null; // Leaf - Use ActivationList on runningBehaviors
}
private void rebuildBehaviorCache() {
@@ -486,6 +477,27 @@ public class Brain<E extends LivingEntity> {
}
}
+ // Leaf start - Use ActivationList on runningBehaviors
+ private void initializeRunningBehaviors() {
+ this.runningBehaviors = new org.dreeam.leaf.util.list.ActivationList<>(false);
+
+ for (Map<Activity, Set<BehaviorControl<? super E>>> map : this.availableBehaviorsByPriority.values()) {
+ for (Set<BehaviorControl<? super E>> set : map.values()) {
+ for (BehaviorControl<? super E> task : set) {
+ this.runningBehaviors.addOrUpdate(task, task.getStatus() == Behavior.Status.RUNNING);
+ }
+ }
+ }
+ }
+
+ private org.dreeam.leaf.util.list.ActivationList<BehaviorControl<? super E>> getRunningBehaviorsList() {
+ if (this.runningBehaviors == null) {
+ this.initializeRunningBehaviors();
+ }
+ return this.runningBehaviors;
+ }
+ // Leaf end - Use ActivationList on runningBehaviors
+
private ObjectArrayList<BehaviorControl<? super E>> getPotentialBehaviors() {
if (this.cachedPotentialBehaviors == null) {
this.rebuildBehaviorCache();
@@ -499,6 +511,9 @@ public class Brain<E extends LivingEntity> {
for (BehaviorControl<? super E> task : this.getPotentialBehaviors()) {
if (task.getStatus() == Behavior.Status.STOPPED) {
task.tryStart(level, entity, startTime);
+ if (task.getStatus() == Behavior.Status.RUNNING) {
+ this.getRunningBehaviorsList().setVisibility(task, true);
+ }
}
}
}
@@ -509,6 +524,11 @@ public class Brain<E extends LivingEntity> {
for (BehaviorControl<? super E> behaviorControl : this.getRunningBehaviors()) {
behaviorControl.tickOrStop(level, entity, gameTime);
+ // Leaf start - Use ActivationList on runningBehaviors
+ if (behaviorControl.getStatus() != Behavior.Status.RUNNING) {
+ this.getRunningBehaviorsList().setVisibility(behaviorControl, false);
+ }
+ // Leaf end - Use ActivationList on runningBehaviors
}
}