v1.1.8: 回退寻路逻辑至 1.1.3 并修复目标区块错位
回退:移除 1.1.4+ 引入的回城自救/接壤校验等寻路改动(导致玩家原地不动),恢复 1.1.3 的寻路行为。 修复错位:Baritone 自带 GoalXZ 容差为 0,精确到区块中心单格,中心不可达时玩家停在相邻区块造成目标错位与反复寻路。新增 ChunkGoal,完成条件改为「玩家脚下方块落在目标区块内」,与 playerChunk.equals(target) 判定一致。
这个提交包含在:
@@ -7,13 +7,10 @@ package autostore.client.bridge;
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.api.pathing.goals.GoalXZ;
|
||||
import autostore.client.config.ExpansionConfig;
|
||||
import autostore.client.territory.ChunkPos;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
||||
/**
|
||||
* Baritone API 封装(桥接层)。
|
||||
@@ -37,16 +34,10 @@ public final class BaritoneBridge {
|
||||
settings.allowPlace.value = config.allowPlace;
|
||||
settings.allowParkour.value = config.allowJump;
|
||||
settings.avoidance.value = config.avoidMobs;
|
||||
// 减少走入地下矿洞:限制无水源时的下落高度,避免掉进深坑/矿洞。
|
||||
// 放宽到 10 格,仍允许穿越峡谷、下坡等正常地形,同时避免掉入深坑
|
||||
settings.maxFallHeightNoWater.value = 10;
|
||||
// 轻微提高挖掘方块的额外代价,让寻路尽量绕行地面而非挖洞穿山,
|
||||
// 但不会阻止必要挖掘(高山、峡谷等仍可通行)
|
||||
settings.blockBreakAdditionalPenalty.value = 0.5;
|
||||
}
|
||||
|
||||
/**
|
||||
* 让 Baritone 寻路前往指定区块的中心。
|
||||
* 让 Baritone 寻路前往指定区块(以“到达区块内”为完成条件)。
|
||||
*
|
||||
* @param chunk 目标区块
|
||||
*/
|
||||
@@ -55,9 +46,11 @@ public final class BaritoneBridge {
|
||||
if (baritone == null) {
|
||||
return;
|
||||
}
|
||||
// 使用 GoalXZ 前往区块中心:Baritone 的 GoalXZ 自带约 10 格容差,
|
||||
// 只需到达区块中心附近即可,避免中心点不可达导致寻路卡死
|
||||
baritone.getCustomGoalProcess().setGoalAndPath(new GoalXZ(chunk.centerBlockX(), chunk.centerBlockZ()));
|
||||
// 使用自定义 ChunkGoal:完成条件为“玩家脚下方块落在目标区块内”,
|
||||
// 与控制器 playerChunk.equals(target) 的判定一致。避免 Baritone 自带
|
||||
// GoalXZ(容差 0,精确到区块中心单格)在中心不可达时停在相邻区块,
|
||||
// 造成目标区块错位与反复寻路。
|
||||
baritone.getCustomGoalProcess().setGoalAndPath(new ChunkGoal(chunk));
|
||||
}
|
||||
|
||||
/** 强制取消当前寻路任务。 */
|
||||
@@ -69,18 +62,6 @@ public final class BaritoneBridge {
|
||||
baritone.getPathingBehavior().forceCancel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送服务器聊天命令(如 /u return 回城),command 参数不含前导斜杠。
|
||||
* 用于寻路超时后的回城自救,避免玩家被困在地下矿洞等位置。
|
||||
*/
|
||||
public void sendCommand(String command) {
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
if (client == null || client.player == null || client.getNetworkHandler() == null) {
|
||||
return;
|
||||
}
|
||||
client.getNetworkHandler().sendChatCommand(command);
|
||||
}
|
||||
|
||||
/** @return 当前是否正在寻路 */
|
||||
public boolean isPathing() {
|
||||
IBaritone baritone = this.primary();
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 本文件为 AutoStore 模组自定义的 Baritone 寻路目标。
|
||||
*/
|
||||
package autostore.client.bridge;
|
||||
|
||||
import autostore.client.territory.ChunkPos;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
|
||||
/**
|
||||
* 以“到达目标区块内”为完成条件的寻路目标。
|
||||
*
|
||||
* <p>修复“目标区块错位”问题:Baritone 自带的 {@code GoalXZ} 容差为 0,
|
||||
* 会要求玩家精确站在区块中心的单个方块上(如 {@code x*16+8, z*16+8})。
|
||||
* 一旦该方块不可达(被树、石头、水、建筑等占据),玩家会被停在区块边缘甚至
|
||||
* 相邻区块,导致玩家所在区块与目标区块错位、反复寻路。</p>
|
||||
*
|
||||
* <p>本目标把完成条件放宽为“玩家脚下方块落在目标区块内”,与控制器中
|
||||
* {@code playerChunk.equals(target)} 的判定完全一致,从而彻底消除
|
||||
* 中心点不可达带来的错位。</p>
|
||||
*/
|
||||
public final class ChunkGoal implements Goal {
|
||||
|
||||
/** 目标区块 X 坐标 */
|
||||
private final int targetX;
|
||||
/** 目标区块 Z 坐标 */
|
||||
private final int targetZ;
|
||||
/** 目标区块中心的方块 X 坐标(用于启发式距离估算) */
|
||||
private final int centerX;
|
||||
/** 目标区块中心的方块 Z 坐标(用于启发式距离估算) */
|
||||
private final int centerZ;
|
||||
|
||||
public ChunkGoal(ChunkPos chunk) {
|
||||
this.targetX = chunk.x();
|
||||
this.targetZ = chunk.z();
|
||||
this.centerX = chunk.centerBlockX();
|
||||
this.centerZ = chunk.centerBlockZ();
|
||||
}
|
||||
|
||||
/** 判断玩家脚下方块是否落在目标区块内 */
|
||||
@Override
|
||||
public boolean isInGoal(int x, int y, int z) {
|
||||
return Math.floorDiv(x, 16) == this.targetX && Math.floorDiv(z, 16) == this.targetZ;
|
||||
}
|
||||
|
||||
/** 启发式:到目标区块中心的水平欧几里得距离(可采纳,保证寻路效率) */
|
||||
@Override
|
||||
public double heuristic(int x, int y, int z) {
|
||||
double dx = x - this.centerX;
|
||||
double dz = z - this.centerZ;
|
||||
return Math.sqrt(dx * dx + dz * dz);
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,6 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
@@ -77,8 +76,6 @@ implements SubtitleChatMonitor.Listener {
|
||||
private final Set<ChunkPos> claimedSet = new HashSet<>();
|
||||
/** 是否正在自动进食 */
|
||||
private boolean eating;
|
||||
/** 回城自救后重新规划时保留重试计数,避免无限循环 */
|
||||
private boolean keepRetryCount;
|
||||
|
||||
public ExpansionController(TerritoryDataService dataService) {
|
||||
this.dataService = dataService;
|
||||
@@ -233,10 +230,6 @@ implements SubtitleChatMonitor.Listener {
|
||||
this.tickNext();
|
||||
break;
|
||||
}
|
||||
case 9: {
|
||||
this.tickReturning();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,10 +268,7 @@ implements SubtitleChatMonitor.Listener {
|
||||
|
||||
/** 让 Baritone 寻路前往当前目标区块,并进入 PATHING 状态 */
|
||||
private void startPathing() {
|
||||
if (!this.keepRetryCount) {
|
||||
this.retryCount = 0;
|
||||
}
|
||||
this.keepRetryCount = false;
|
||||
this.retryCount = 0;
|
||||
this.stageStartedMillis = System.currentTimeMillis();
|
||||
this.lastProgress = 0;
|
||||
this.baritoneBridge.pathTo(this.target);
|
||||
@@ -294,8 +284,8 @@ implements SubtitleChatMonitor.Listener {
|
||||
this.setState(State.NEXT, "\u76ee\u6807\u4e3a\u7a7a");
|
||||
return;
|
||||
}
|
||||
// 目标已失效(被占领或不再与己方领土接壤):立即跳过,避免继续寻路到无效区块
|
||||
if (this.skipIfTargetInvalid()) {
|
||||
// 目标已被他人占领(地图刷新后发现):立即跳过,避免继续寻路到无效区块
|
||||
if (this.skipIfTargetClaimed("\u76ee\u6807\u5df2\u88ab\u5360\u9886")) {
|
||||
return;
|
||||
}
|
||||
if (this.playerChunk.equals(this.target)) {
|
||||
@@ -312,10 +302,6 @@ implements SubtitleChatMonitor.Listener {
|
||||
if (this.retryCount >= this.config.retries) {
|
||||
this.log("\u5bfb\u8def\u8d85\u65f6\uff0c\u8df3\u8fc7 " + this.target.x() + "," + this.target.z());
|
||||
this.setState(State.FAIL, "\u5bfb\u8def\u8d85\u65f6");
|
||||
} else if (this.isUnderground()) {
|
||||
// 玩家被困地下(矿洞等):执行 /u return 回城自救,避免被困
|
||||
this.log("\u5bfb\u8def\u8d85\u65f6\u4e14\u73a9\u5bb6\u5728\u5730\u4e0b\uff0c\u6267\u884c /u return \u56de\u57ce\u81ea\u6551 " + this.retryCount + "/" + this.config.retries);
|
||||
this.returnToCapital("\u56de\u57ce\u540e\u91cd\u65b0\u5bfb\u8def " + this.target.x() + "," + this.target.z());
|
||||
} else {
|
||||
this.log("\u5bfb\u8def\u8d85\u65f6\uff0c\u91cd\u8bd5 " + this.retryCount + "/" + this.config.retries);
|
||||
this.retrySameTarget("\u91cd\u8bd5\u524d\u5f80 " + this.target.x() + "," + this.target.z());
|
||||
@@ -329,8 +315,8 @@ implements SubtitleChatMonitor.Listener {
|
||||
this.setState(State.NEXT, "\u76ee\u6807\u4e3a\u7a7a");
|
||||
return;
|
||||
}
|
||||
// 目标已失效(被占领或不再与己方领土接壤):立即跳过,避免被困在无效区块
|
||||
if (this.skipIfTargetInvalid()) {
|
||||
// 目标已被他人占领(地图刷新后发现):立即跳过,避免被困在已占领区块
|
||||
if (this.skipIfTargetClaimed("\u76ee\u6807\u5df2\u88ab\u5360\u9886")) {
|
||||
return;
|
||||
}
|
||||
// 玩家离开了目标区块(被击退/寻路偏差),重新寻路回去
|
||||
@@ -355,9 +341,8 @@ implements SubtitleChatMonitor.Listener {
|
||||
|
||||
/** 重试当前目标:取消旧寻路,重新让 Baritone 前往同一目标区块 */
|
||||
private void retrySameTarget(String statusText) {
|
||||
// 目标已失效(被占领或不再与己方领土接壤):不再重试,直接跳过,
|
||||
// 避免玩家被反复拉回与领土不接壤的孤立区块
|
||||
if (this.skipIfTargetInvalid()) {
|
||||
// 目标已被他人占领(地图刷新后发现):不再重试,直接跳过,避免玩家被困在已占领区块
|
||||
if (this.skipIfTargetClaimed("\u91cd\u8bd5\u65f6\u53d1\u73b0\u76ee\u6807\u5df2\u88ab\u5360\u9886")) {
|
||||
return;
|
||||
}
|
||||
this.baritoneBridge.cancel();
|
||||
@@ -367,103 +352,19 @@ implements SubtitleChatMonitor.Listener {
|
||||
}
|
||||
|
||||
/**
|
||||
* 若当前目标已失效(被其他邦国占领,或不再与己方领土接壤),
|
||||
* 则取消寻路、记录日志、跳过该目标并进入 NEXT 状态,返回 true。
|
||||
* 用于修复"寻路走到与领土不接壤区块后死等"的 bug:
|
||||
* 地图数据刷新后,若目标周围被他人占领导致不再接壤,立即放弃该目标并重新规划。
|
||||
* 若当前目标区块已被任何邦国占领(含己方与本次会话),
|
||||
* 则记录日志、跳过该目标并进入 NEXT 状态,返回 true。
|
||||
* 用于在地图数据异步刷新后及时识别"已被占领"的区块,避免死循环。
|
||||
*/
|
||||
private boolean skipIfTargetInvalid() {
|
||||
if (this.target == null) {
|
||||
return false;
|
||||
}
|
||||
if (!this.isTargetStillValid()) {
|
||||
this.baritoneBridge.cancel();
|
||||
this.log("\u76ee\u6807\u5df2\u5931\u6548\uff08\u88ab\u5360\u9886\u6216\u4e0d\u518d\u4e0e\u9886\u571f\u63a5\u58e4\uff09\uff0c\u8df3\u8fc7 " + this.target.x() + "," + this.target.z());
|
||||
this.setState(State.NEXT, "\u76ee\u6807\u5931\u6548\uff0c\u91cd\u65b0\u89c4\u5212");
|
||||
private boolean skipIfTargetClaimed(String reason) {
|
||||
if (this.target != null && this.isClaimedByOthers(this.target)) {
|
||||
this.log(reason + " " + this.target.x() + "," + this.target.z() + "\uff0c\u8df3\u8fc7");
|
||||
this.setState(State.NEXT, "\u8df3\u8fc7\u5df2\u5360\u9886\u533a\u5757");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断当前目标是否仍然有效:
|
||||
* 未被任何邦国占领即可——规划器已保证目标与己方领土相邻,
|
||||
* 运行时无需重复验证邻居关系,避免地图刷新后 own 集合不一致导致误判跳过。
|
||||
*
|
||||
* <p>注意:己方领土数据暂时不可用时保守视为有效(可能性极小,仅刷新竞态时发生),
|
||||
* 避免所有目标被误跳过导致玩家原地不动。
|
||||
*/
|
||||
private boolean isTargetStillValid() {
|
||||
if (this.target == null) {
|
||||
return false;
|
||||
}
|
||||
TerritoryModel m = this.dataService.model();
|
||||
return !m.allClaimedChunks().contains(this.target);
|
||||
}
|
||||
|
||||
/** 判断区块是否属于己方领土(含本次会话新占领) */
|
||||
private boolean isInOwnTerritory(ChunkPos chunk) {
|
||||
TerritoryModel m = this.dataService.model();
|
||||
if (m.sessionClaims().contains(chunk)) {
|
||||
return true;
|
||||
}
|
||||
TerritoryState self = m.selfState();
|
||||
return self != null && self.chunks().contains(chunk);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断玩家是否被困在地下(头顶上方连续数格被实心方块遮挡)。
|
||||
* 用于寻路超时时识别"走进矿洞"的情况,从而触发回城自救。
|
||||
*/
|
||||
private boolean isUnderground() {
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
if (client == null || client.player == null || client.world == null) {
|
||||
return false;
|
||||
}
|
||||
BlockPos pos = client.player.getBlockPos();
|
||||
for (int y = pos.getY() + 1; y <= pos.getY() + 3; ++y) {
|
||||
BlockPos above = new BlockPos(pos.getX(), y, pos.getZ());
|
||||
BlockState state = client.world.getBlockState(above);
|
||||
if (state.isOpaqueFullCube()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 回城自救:取消当前寻路,发送 /u return 命令回到国家王城区块,
|
||||
* 并进入 RETURNING 状态等待回城完成后重新规划扩地任务。
|
||||
* 用于避免玩家被困在地下矿洞或无效区块。
|
||||
*/
|
||||
private void returnToCapital(String statusText) {
|
||||
this.baritoneBridge.cancel();
|
||||
this.stageStartedMillis = System.currentTimeMillis();
|
||||
this.keepRetryCount = true;
|
||||
this.baritoneBridge.sendCommand("u return");
|
||||
this.setState(State.RETURNING, "\u56de\u57ce\u81ea\u6551\u4e2d");
|
||||
this.log("\u6267\u884c /u return \u56de\u57ce\uff0c\u7b49\u5f85\u8fd4\u56de\u738b\u57ce\u540e\u7ee7\u7eed");
|
||||
}
|
||||
|
||||
/**
|
||||
* 回城阶段每帧逻辑:等待玩家回到己方领土(含王城)后重新规划。
|
||||
* /u return 传送需要约 10 秒,因此前 10 秒不检查位置,避免传送未完成就误判;
|
||||
* 若等待超时(60 秒)仍未回到领土,则跳过当前目标继续,避免死等。
|
||||
*/
|
||||
private void tickReturning() {
|
||||
long elapsedSeconds = (System.currentTimeMillis() - this.stageStartedMillis) / 1000L;
|
||||
if (elapsedSeconds >= 60) {
|
||||
this.log("\u56de\u57ce\u7b49\u5f85\u8d85\u65f6\uff0c\u8df3\u8fc7\u5f53\u524d\u76ee\u6807\u7ee7\u7eed");
|
||||
this.setState(State.FAIL, "\u56de\u57ce\u8d85\u65f6\uff0c\u8df3\u8fc7\u76ee\u6807");
|
||||
return;
|
||||
}
|
||||
// /u return 传送约需 10 秒,等待传送完成后才检查是否回到己方领土
|
||||
if (elapsedSeconds >= 10 && this.isInOwnTerritory(this.playerChunk)) {
|
||||
this.log("\u5df2\u56de\u5230\u5df1\u65b9\u9886\u571f\uff0c\u91cd\u65b0\u89c4\u5212\u6269\u5730\u4efb\u52a1");
|
||||
this.setState(State.NEXT, "\u5df2\u56de\u57ce\uff0c\u91cd\u65b0\u89c4\u5212");
|
||||
}
|
||||
}
|
||||
|
||||
/** 成功后的过渡:进入 NEXT 状态,准备处理下一个目标 */
|
||||
private void tickSuccess() {
|
||||
this.setState(State.NEXT, "\u5df2\u5b8c\u6210 " + this.completedClaims + (this.config.targetCount > 0 ? "/" + this.config.targetCount : "/\u6301\u7eed"));
|
||||
@@ -729,8 +630,7 @@ implements SubtitleChatMonitor.Listener {
|
||||
FAIL,
|
||||
NEXT,
|
||||
COMPLETE,
|
||||
STOPPED,
|
||||
RETURNING;
|
||||
STOPPED;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户