fix: 自动游泳改为持续按住空格(只在水中且 Baritone 未接管时)
原逻辑: 完全没入水中时调用一次 player.jump(),离开水面后停止。
新逻辑: 玩家处于水中(player.isTouchingWater())、Baritone 未寻路(!baritoneBridge.isPathing())、
玩家不在船中时持续按下 jumpKey;
离开水/Baritone 接管/坐上船/任务停止任一条件即释放空格键。
新增 holdingJump 字段跟踪按压状态,stop() 中显式释放避免卡键。
这个提交包含在:
@@ -35,6 +35,7 @@ import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.entity.vehicle.AbstractBoatEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
@@ -129,6 +130,8 @@ implements SubtitleChatMonitor.Listener, BaritoneBridge.PathListener {
|
||||
private boolean returnThenStop;
|
||||
/** 自动攻击当前目标的实体 ID(-1 为无目标),仅用于避免重复记录战斗日志 */
|
||||
private int combatTargetEntityId = -1;
|
||||
/** 当前是否正持续按住空格键(自动游泳用),用于 stop() 与离开条件时精准释放 */
|
||||
private boolean holdingJump;
|
||||
|
||||
public ExpansionController(TerritoryDataService dataService) {
|
||||
this.dataService = dataService;
|
||||
@@ -278,6 +281,8 @@ implements SubtitleChatMonitor.Listener, BaritoneBridge.PathListener {
|
||||
if (this.sideStepping) {
|
||||
this.stopSideStep(false);
|
||||
}
|
||||
// 若处于自动游泳持续按空格阶段,先释放空格键
|
||||
this.releaseJump(MinecraftClient.getInstance());
|
||||
// 若正处于自动用船动作流程,先释放蹲伏键与暂存的主手槽位
|
||||
this.autoBoat.reset(MinecraftClient.getInstance(), true);
|
||||
this.eating = false;
|
||||
@@ -893,20 +898,41 @@ implements SubtitleChatMonitor.Listener, BaritoneBridge.PathListener {
|
||||
|
||||
/**
|
||||
* 自动游泳逻辑(每帧调用):
|
||||
* 仅在玩家完全没入水中(有溺水风险)时自动跳跃,保持浮在水面。
|
||||
* 玩家在水面上正常游泳时不做任何干预,避免干扰 Baritone 的水平寻路。
|
||||
* 仅在玩家处于水中(含没入 / 水面 / 浅水)、Baritone 未接管寻路、玩家不在船中时,
|
||||
* 持续按住跳跃键,使玩家不断浮到水面,避免溺水。
|
||||
* 任务停止、离开水、Baritone 开始寻路、坐上船等条件触发时立即释放跳跃键,
|
||||
* 避免干扰 Baritone 与其它流程。
|
||||
*/
|
||||
private void tickAutoSwim(MinecraftClient client) {
|
||||
if (!this.isRunning()) {
|
||||
if (!this.isRunning() || client.player == null) {
|
||||
this.releaseJump(client);
|
||||
return;
|
||||
}
|
||||
PlayerEntity player = client.player;
|
||||
if (player == null) {
|
||||
return;
|
||||
// 水中 + Baritone 未接管 + 玩家不在船中(船里前进靠船自身,不需要自动跳)→ 持续按住空格
|
||||
boolean inWater = player.isTouchingWater();
|
||||
boolean baritoneControlling = this.baritoneBridge.isPathing();
|
||||
boolean inBoat = player.getVehicle() instanceof AbstractBoatEntity;
|
||||
if (inWater && !baritoneControlling && !inBoat) {
|
||||
this.pressJump(client);
|
||||
} else {
|
||||
this.releaseJump(client);
|
||||
}
|
||||
// 只有完全没入水中(头部在水面以下)才有溺水风险,此时才需要跳跃上浮
|
||||
if (player.isSubmergedInWater()) {
|
||||
player.jump();
|
||||
}
|
||||
|
||||
/** 按住跳跃键(仅在当前未按时生效,避免重复赋值) */
|
||||
private void pressJump(MinecraftClient client) {
|
||||
if (!this.holdingJump && client.options != null) {
|
||||
client.options.jumpKey.setPressed(true);
|
||||
this.holdingJump = true;
|
||||
}
|
||||
}
|
||||
|
||||
/** 释放跳跃键(仅在当前按住时生效,避免误清玩家手动按下的状态——但本模组自己设置的就该清掉) */
|
||||
private void releaseJump(MinecraftClient client) {
|
||||
if (this.holdingJump && client.options != null) {
|
||||
client.options.jumpKey.setPressed(false);
|
||||
this.holdingJump = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
在新工单中引用
屏蔽一个用户