From e8f6009a66ef34daf8433feeead0a7633550aa5a Mon Sep 17 00:00:00 2001 From: Lyizai Date: Mon, 17 Aug 2026 12:27:38 +0000 Subject: [PATCH] =?UTF-8?q?v1.1.4:=20=E5=AF=BB=E8=B7=AF=E4=BC=98=E5=8C=96?= =?UTF-8?q?=EF=BC=88=E9=81=BF=E7=9F=BF=E6=B4=9E+=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E5=9B=9E=E5=9F=8E=E8=87=AA=E6=95=91+=E4=B8=8D=E6=8E=A5?= =?UTF-8?q?=E5=A3=A4=E7=9B=AE=E6=A0=87=E6=A0=A1=E9=AA=8C=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Baritone设置:限制下落高度(10格)与轻微挖方块惩罚,减少走入矿洞,同时保留峡谷/高山通行 - 寻路超时且玩家在地下时自动执行 /u return 回城自救,等待10秒传送后重新规划 - 新增目标有效性校验:寻路/等待/重试前实时校验目标是否仍与己方领土接壤,不接壤立即跳过并重新规划,修复走到不接壤区块死等bug --- .../client/bridge/BaritoneBridge.java | 19 +++ .../controller/ExpansionController.java | 146 ++++++++++++++++-- src/main/resources/fabric.mod.json | 2 +- 3 files changed, 151 insertions(+), 16 deletions(-) diff --git a/src/main/java/autostore/client/bridge/BaritoneBridge.java b/src/main/java/autostore/client/bridge/BaritoneBridge.java index 2cc690f..f18b00b 100644 --- a/src/main/java/autostore/client/bridge/BaritoneBridge.java +++ b/src/main/java/autostore/client/bridge/BaritoneBridge.java @@ -13,6 +13,7 @@ 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 封装(桥接层)。 @@ -36,6 +37,12 @@ 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; } /** @@ -62,6 +69,18 @@ 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(); diff --git a/src/main/java/autostore/client/controller/ExpansionController.java b/src/main/java/autostore/client/controller/ExpansionController.java index 1eae339..7dbeab3 100644 --- a/src/main/java/autostore/client/controller/ExpansionController.java +++ b/src/main/java/autostore/client/controller/ExpansionController.java @@ -20,6 +20,7 @@ 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; @@ -76,6 +77,8 @@ implements SubtitleChatMonitor.Listener { private final Set claimedSet = new HashSet<>(); /** 是否正在自动进食 */ private boolean eating; + /** 回城自救后重新规划时保留重试计数,避免无限循环 */ + private boolean keepRetryCount; public ExpansionController(TerritoryDataService dataService) { this.dataService = dataService; @@ -230,6 +233,10 @@ implements SubtitleChatMonitor.Listener { this.tickNext(); break; } + case 9: { + this.tickReturning(); + break; + } } } @@ -268,7 +275,10 @@ implements SubtitleChatMonitor.Listener { /** 让 Baritone 寻路前往当前目标区块,并进入 PATHING 状态 */ private void startPathing() { - this.retryCount = 0; + if (!this.keepRetryCount) { + this.retryCount = 0; + } + this.keepRetryCount = false; this.stageStartedMillis = System.currentTimeMillis(); this.lastProgress = 0; this.baritoneBridge.pathTo(this.target); @@ -284,8 +294,8 @@ implements SubtitleChatMonitor.Listener { this.setState(State.NEXT, "\u76ee\u6807\u4e3a\u7a7a"); return; } - // 目标已被他人占领(地图刷新后发现):立即跳过,避免继续寻路到无效区块 - if (this.skipIfTargetClaimed("\u76ee\u6807\u5df2\u88ab\u5360\u9886")) { + // 目标已失效(被占领或不再与己方领土接壤):立即跳过,避免继续寻路到无效区块 + if (this.skipIfTargetInvalid()) { return; } if (this.playerChunk.equals(this.target)) { @@ -302,6 +312,10 @@ 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()); @@ -315,8 +329,8 @@ implements SubtitleChatMonitor.Listener { this.setState(State.NEXT, "\u76ee\u6807\u4e3a\u7a7a"); return; } - // 目标已被他人占领(地图刷新后发现):立即跳过,避免被困在已占领区块 - if (this.skipIfTargetClaimed("\u76ee\u6807\u5df2\u88ab\u5360\u9886")) { + // 目标已失效(被占领或不再与己方领土接壤):立即跳过,避免被困在无效区块 + if (this.skipIfTargetInvalid()) { return; } // 玩家离开了目标区块(被击退/寻路偏差),重新寻路回去 @@ -341,8 +355,9 @@ implements SubtitleChatMonitor.Listener { /** 重试当前目标:取消旧寻路,重新让 Baritone 前往同一目标区块 */ private void retrySameTarget(String statusText) { - // 目标已被他人占领(地图刷新后发现):不再重试,直接跳过,避免玩家被困在已占领区块 - if (this.skipIfTargetClaimed("\u91cd\u8bd5\u65f6\u53d1\u73b0\u76ee\u6807\u5df2\u88ab\u5360\u9886")) { + // 目标已失效(被占领或不再与己方领土接壤):不再重试,直接跳过, + // 避免玩家被反复拉回与领土不接壤的孤立区块 + if (this.skipIfTargetInvalid()) { return; } this.baritoneBridge.cancel(); @@ -352,19 +367,119 @@ implements SubtitleChatMonitor.Listener { } /** - * 若当前目标区块已被任何邦国占领(含己方与本次会话), - * 则记录日志、跳过该目标并进入 NEXT 状态,返回 true。 - * 用于在地图数据异步刷新后及时识别"已被占领"的区块,避免死循环。 + * 若当前目标已失效(被其他邦国占领,或不再与己方领土接壤), + * 则取消寻路、记录日志、跳过该目标并进入 NEXT 状态,返回 true。 + * 用于修复"寻路走到与领土不接壤区块后死等"的 bug: + * 地图数据刷新后,若目标周围被他人占领导致不再接壤,立即放弃该目标并重新规划。 */ - 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"); + 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"); return true; } return false; } + /** + * 判断当前目标是否仍然有效: + * 未被任何邦国占领,且与己方领土(含本次会话新占领)至少一个区块接壤。 + * 使用实时地图数据校验,避免寻路到与领土不接壤的孤立区块。 + */ + private boolean isTargetStillValid() { + if (this.target == null) { + return false; + } + TerritoryModel m = this.dataService.model(); + if (m.allClaimedChunks().contains(this.target)) { + return false; + } + HashSet own = new HashSet(m.sessionClaims()); + TerritoryState self = m.selfState(); + if (self != null) { + own.addAll(self.chunks()); + } + return this.ownNeighbors(this.target, own) > 0; + } + + /** 统计区块周围(上下左右)属于给定集合的邻居数量 */ + private int ownNeighbors(ChunkPos chunk, Set own) { + int count = 0; + for (ChunkPos neighbor : this.cardinalNeighbors(chunk)) { + if (own.contains(neighbor)) { + ++count; + } + } + return count; + } + + /** 判断区块是否属于己方领土(含本次会话新占领) */ + 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")); @@ -630,7 +745,8 @@ implements SubtitleChatMonitor.Listener { FAIL, NEXT, COMPLETE, - STOPPED; + STOPPED, + RETURNING; } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index c0ee746..aaabb06 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1 +1 @@ -{"schemaVersion":1,"id":"autostore","version":"1.1.3","name":"AutoStore","description":"","authors":[],"contact":{},"license":"All-Rights-Reserved","environment":"client","entrypoints":{"fabric-datagen":["autostore.client.AutoStoreModDataGenerator"],"client":["autostore.client.AutoStoreModClient"],"main":["autostore.AutoStoreMod"]},"mixins":["autostore.mixins.json",{"config":"autostore.client.mixins.json","environment":"client"}],"depends":{"fabricloader":">=0.16.14","fabric-api":"*","minecraft":"1.21.4"},"jars":[{"file":"META-INF/jars/baritone-api-fabric-1.13.1.jar"}]} \ No newline at end of file +{"schemaVersion":1,"id":"autostore","version":"1.1.4","name":"AutoStore","description":"","authors":[],"contact":{},"license":"All-Rights-Reserved","environment":"client","entrypoints":{"fabric-datagen":["autostore.client.AutoStoreModDataGenerator"],"client":["autostore.client.AutoStoreModClient"],"main":["autostore.AutoStoreMod"]},"mixins":["autostore.mixins.json",{"config":"autostore.client.mixins.json","environment":"client"}],"depends":{"fabricloader":">=0.16.14","fabric-api":"*","minecraft":"1.21.4"},"jars":[{"file":"META-INF/jars/baritone-api-fabric-1.13.1.jar"}]} \ No newline at end of file