55 lines
3.3 KiB
Diff
55 lines
3.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: MrHua269 <mrhua269@gmail.com>
|
|
Date: Sat, 8 Mar 2025 09:56:15 +0800
|
|
Subject: [PATCH] Add config for entity to clean memory value which is not
|
|
belong to current tickregion
|
|
|
|
Folia does not fully get the entity AI patched correctly, like some memories in entity's brain is still exists when switched dimension or teleported to the new tickregion, which entity is still accessing in the next tick then it will trigger the async catcher, which lead the entity go disappear and throw an exception in the console.In this patch, if this function is turned on, the server will clean the memory that doesn't belong to the entity's tickregion before ticking any behaviors, which can simply fix that.
|
|
|
|
diff --git a/net/minecraft/world/entity/ai/Brain.java b/net/minecraft/world/entity/ai/Brain.java
|
|
index 3eb1362e6597faa21b27c9d1611d64a236491f98..c589e18b68e45d5991291db3a0bdd833588ce945 100644
|
|
--- a/net/minecraft/world/entity/ai/Brain.java
|
|
+++ b/net/minecraft/world/entity/ai/Brain.java
|
|
@@ -408,7 +408,7 @@ public class Brain<E extends LivingEntity> {
|
|
}
|
|
|
|
public void tick(ServerLevel level, E entity) {
|
|
- this.forgetOutdatedMemories();
|
|
+ this.forgetOutdatedMemories(entity); // Luminol - Add config to force clean entity memory that don't belong to current tick region
|
|
this.tickSensors(level, entity);
|
|
this.startEachNonRunningBehavior(level, entity);
|
|
this.tickEachRunningBehavior(level, entity);
|
|
@@ -420,10 +420,31 @@ public class Brain<E extends LivingEntity> {
|
|
}
|
|
}
|
|
|
|
- private void forgetOutdatedMemories() {
|
|
+ private void forgetOutdatedMemories(E owner) { // Luminol - Add config to force clean entity memory that don't belong to current tick region
|
|
for (Entry<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> entry : this.memories.entrySet()) {
|
|
if (entry.getValue().isPresent()) {
|
|
ExpirableValue<?> expirableValue = (ExpirableValue<?>)entry.getValue().get();
|
|
+ // Luminol start - Add config to force clean entity memory that don't belong to current tick region
|
|
+ final Object value = expirableValue.getValue();
|
|
+ final net.minecraft.world.level.Level ownerLevel = owner.level();
|
|
+
|
|
+ // type: entity
|
|
+ if (me.earthme.luminol.config.modules.fixes.ForceCleanupEntityBrainMemoryConfig.enabledForEntity && value instanceof LivingEntity entity) {
|
|
+ if (!ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(entity)) {
|
|
+ this.eraseMemory(entry.getKey());
|
|
+ continue;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ // type: block_pos
|
|
+ if (me.earthme.luminol.config.modules.fixes.ForceCleanupEntityBrainMemoryConfig.enabledForBlockPos && value instanceof net.minecraft.core.BlockPos blockPos) {
|
|
+ if (!ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(ownerLevel, blockPos)) {
|
|
+ this.eraseMemory(entry.getKey());
|
|
+ continue;
|
|
+ }
|
|
+ }
|
|
+ // Luminol end
|
|
+
|
|
if (expirableValue.hasExpired()) {
|
|
this.eraseMemory(entry.getKey());
|
|
}
|