v1.2.2: 寻路不再带玩家下地下矿坑——ChunkGoal增加高度约束,目标为该区块内经排除树叶的地表最高处,停在矿坑不算到达,不搭方块到树上
这个提交包含在:
@@ -15,6 +15,9 @@ import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* Baritone API 封装(桥接层)。
|
||||
@@ -78,11 +81,39 @@ public final class BaritoneBridge {
|
||||
if (baritone == null) {
|
||||
return;
|
||||
}
|
||||
// 使用自定义 ChunkGoal:完成条件为“玩家脚下方块落在目标区块内”,
|
||||
// 与控制器 playerChunk.equals(target) 的判定一致。避免 Baritone 自带
|
||||
// GoalXZ(容差 0,精确到区块中心单格)在中心不可达时停在相邻区块,
|
||||
// 造成目标区块错位与反复寻路。
|
||||
baritone.getCustomGoalProcess().setGoalAndPath(new ChunkGoal(chunk));
|
||||
// 使用自定义 ChunkGoal:完成条件为“玩家脚下方块落在目标区块内地表”,
|
||||
// 与控制器 playerChunk.equals(target) 的判定一致,并对高度施加约束,
|
||||
// 避免 Baritone 把终点停在地下洞穴/矿坑里。避免 Baritone 自带 GoalXZ
|
||||
//(容差 0,精确到区块中心单格)在中心不可达时停在相邻区块,造成目标区块错位。
|
||||
baritone.getCustomGoalProcess().setGoalAndPath(new ChunkGoal(chunk, this.surfaceY(chunk)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算目标区块内地表高度(方块 Y 上限):
|
||||
* 遍历该区块 16×16 各列,取“排除树叶的实体地表”的最高值,作为高度约束目标。
|
||||
* 区块尚未加载时各列取到 0,max 仍取已加载列;若整块均未加载则返回 0(不约束高度)。
|
||||
*
|
||||
* @param chunk 目标区块
|
||||
* @return 地表最高 Y;0 表示暂无法确定(不施加高度约束)
|
||||
*/
|
||||
private int surfaceY(ChunkPos chunk) {
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
if (client == null || client.world == null) {
|
||||
return 0;
|
||||
}
|
||||
World world = client.world;
|
||||
int x0 = chunk.x() * 16;
|
||||
int z0 = chunk.z() * 16;
|
||||
int maxY = 0;
|
||||
for (int bx = x0; bx < x0 + 16; ++bx) {
|
||||
for (int bz = z0; bz < z0 + 16; ++bz) {
|
||||
int top = world.getTopY(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, bx, bz);
|
||||
if (top > maxY) {
|
||||
maxY = top;
|
||||
}
|
||||
}
|
||||
}
|
||||
return maxY;
|
||||
}
|
||||
|
||||
/** 强制取消当前寻路任务。 */
|
||||
|
||||
在新工单中引用
屏蔽一个用户