9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-25 09:59:15 +00:00

improve Async target finding (#294)

* fix NearestHealableRaiderTargetGoal not async and fix data race in Async target finding

* remove unnecessary requiresUpdateEveryTick

* add AsyncGoal

* use cow list on ServerLevel#players

* move warning

* run tasks after entity tick
This commit is contained in:
hayanesuru
2025-04-22 23:55:01 +08:00
committed by GitHub
parent ef1559c781
commit 9db6bfba3b
3 changed files with 329 additions and 128 deletions

View File

@@ -0,0 +1,5 @@
package org.dreeam.leaf.async.ai;
public interface AsyncGoal {
boolean poll();
}

View File

@@ -0,0 +1,19 @@
package org.dreeam.leaf.async.ai;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class AsyncGoalExecutor {
public static final java.util.concurrent.ExecutorService EXECUTOR = new ThreadPoolExecutor(
1,
1,
0L,
TimeUnit.MILLISECONDS,
new ArrayBlockingQueue<>(128),
new com.google.common.util.concurrent.ThreadFactoryBuilder()
.setNameFormat("Leaf Async Target Finding Thread")
.setDaemon(true)
.setPriority(Thread.NORM_PRIORITY - 2)
.build(), new ThreadPoolExecutor.CallerRunsPolicy());
}