v1.1.8: 回退寻路逻辑至 1.1.3 并修复目标区块错位
回退:移除 1.1.4+ 引入的回城自救/接壤校验等寻路改动(导致玩家原地不动),恢复 1.1.3 的寻路行为。 修复错位:Baritone 自带 GoalXZ 容差为 0,精确到区块中心单格,中心不可达时玩家停在相邻区块造成目标错位与反复寻路。新增 ChunkGoal,完成条件改为「玩家脚下方块落在目标区块内」,与 playerChunk.equals(target) 判定一致。
这个提交包含在:
@@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户