mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-25 09:59:15 +00:00
update async target finding and block finding (#296)
* reduce overhead on poll * more async search entities * async block search * rename search entity config * cleanup * fix async search block too frequent * remove alertOther Experimental anno * Adjust the delay of RemoveBlockGoal to match vanilla behavior * Optimize TemptGoal * rollback interval change * cleanup * add async finding to DefendVillageTargetGoal * rollback interval change for NearestHealableRaiderTargetGoal * config searchPlayer * fix DefendVillageTargetGoal condition doesn't check * add async finding to BegGoal * rollback interval change for FollowMobGoal * cleanup * add async finding to some follow goal * add async finding to TemptGoal * handle searchPlayer config * fix TemptGoal
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
package org.dreeam.leaf.async.ai;
|
||||
|
||||
public interface AsyncGoal {
|
||||
boolean poll();
|
||||
}
|
||||
@@ -1,19 +1,18 @@
|
||||
package org.dreeam.leaf.async.ai;
|
||||
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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());
|
||||
@Nullable
|
||||
public static java.util.concurrent.ExecutorService EXECUTOR;
|
||||
|
||||
public static final org.apache.logging.log4j.Logger LOGGER = org.apache.logging.log4j.LogManager.getLogger("Leaf Async Entity Lookup");
|
||||
|
||||
public static void runTasks(List<Runnable> tasks) {
|
||||
for (Runnable task : tasks) {
|
||||
task.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package org.dreeam.leaf.config.modules.async;
|
||||
|
||||
import org.dreeam.leaf.config.ConfigModules;
|
||||
import org.dreeam.leaf.config.EnumConfigCategory;
|
||||
|
||||
public class AsyncBlockFinding extends ConfigModules {
|
||||
|
||||
public String getBasePath() {
|
||||
return EnumConfigCategory.ASYNC.getBaseKeyName() + ".async-block-finding";
|
||||
}
|
||||
|
||||
public static boolean enabled = false;
|
||||
public static boolean asyncBlockFindingInitialized;
|
||||
|
||||
@Override
|
||||
public void onLoaded() {
|
||||
config.addCommentRegionBased(getBasePath(), """
|
||||
This moves the expensive search calculations to a background thread while
|
||||
keeping the actual block validation on the main thread.""",
|
||||
"""
|
||||
这会将昂贵的搜索计算移至后台线程, 同时在主线程上保持实际的方块验证.""");
|
||||
|
||||
if (!asyncBlockFindingInitialized) {
|
||||
asyncBlockFindingInitialized = true;
|
||||
enabled = config.getBoolean(getBasePath() + ".enabled", enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,15 @@
|
||||
|
||||
package org.dreeam.leaf.config.modules.async;
|
||||
|
||||
import org.dreeam.leaf.async.ai.AsyncGoalExecutor;
|
||||
import org.dreeam.leaf.config.ConfigModules;
|
||||
import org.dreeam.leaf.config.EnumConfigCategory;
|
||||
import org.dreeam.leaf.config.annotations.Experimental;
|
||||
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class AsyncTargetFinding extends ConfigModules {
|
||||
|
||||
public String getBasePath() {
|
||||
@@ -13,6 +18,11 @@ public class AsyncTargetFinding extends ConfigModules {
|
||||
|
||||
@Experimental
|
||||
public static boolean enabled = false;
|
||||
public static boolean alertOther = true;
|
||||
public static boolean searchBlock = false;
|
||||
public static boolean searchEntity = true;
|
||||
public static boolean searchPlayer = false;
|
||||
public static boolean searchPlayerTempt = false;
|
||||
public static boolean asyncTargetFindingInitialized;
|
||||
|
||||
@Override
|
||||
@@ -24,9 +34,35 @@ public class AsyncTargetFinding extends ConfigModules {
|
||||
"""
|
||||
这会将昂贵的实体目标搜索计算移至后台线程, 同时在主线程上保持实际的实体验证.""");
|
||||
|
||||
if (!asyncTargetFindingInitialized) {
|
||||
asyncTargetFindingInitialized = true;
|
||||
enabled = config.getBoolean(getBasePath() + ".enabled", enabled);
|
||||
if (asyncTargetFindingInitialized) {
|
||||
return;
|
||||
}
|
||||
asyncTargetFindingInitialized = true;
|
||||
enabled = config.getBoolean(getBasePath() + ".enabled", enabled);
|
||||
alertOther = config.getBoolean(getBasePath() + ".async-alert-other", true);
|
||||
searchBlock = config.getBoolean(getBasePath() + ".async-search-block", false);
|
||||
searchEntity = config.getBoolean(getBasePath() + ".async-search-entity", true);
|
||||
searchPlayer = config.getBoolean(getBasePath() + ".async-search-player", false);
|
||||
searchPlayerTempt = config.getBoolean(getBasePath() + ".async-search-player-tempt", false);
|
||||
if (!enabled) {
|
||||
alertOther = false;
|
||||
searchEntity = false;
|
||||
searchBlock = false;
|
||||
searchPlayer = false;
|
||||
searchPlayerTempt = false;
|
||||
return;
|
||||
}
|
||||
AsyncGoalExecutor.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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user