Skip to content

Commit

Permalink
Merge pull request #637
Browse files Browse the repository at this point in the history
* fix climb with need to walk to surface

* 部分修正
  • Loading branch information
Azumic authored Jan 6, 2025
1 parent 9d42979 commit 49f47cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ protected boolean canStillUse(ServerLevel pLevel, EntityMaid pEntity, long pGame
@Override
protected void tick(ServerLevel level, EntityMaid maid, long pGameTime) {
Path path = maid.getNavigation().getPath();
if (path == null) {
if (path == null || path.isDone()) {
maid.setCanClimb(false);
return;
}

maid.setCanClimb(true);
// 获取基础信息:下一个要到达的节点、女仆当前所处坐标、方块
int beGoNodeIndex = path.getNextNodeIndex();
Node beGoNode = path.getNode(beGoNodeIndex);
Expand Down Expand Up @@ -112,6 +114,7 @@ protected void tick(ServerLevel level, EntityMaid maid, long pGameTime) {

boolean beWalkSurface = pointNext.y == currentNext.y;
if (beWalkSurface || pointNext == path.getEndNode() || maidFeetPos.getY() == currentNext.y) {
maid.setCanClimb(false);
// 给予女仆当前坐标与水平节点的x、z方向的差值向量,
// 让其向着那个水平节点进发,脱离楼梯等可爬行物体,不再继续爬楼梯或者停留在上面
int x1 = pointNext.x - currentNext.x;
Expand All @@ -127,7 +130,7 @@ protected void tick(ServerLevel level, EntityMaid maid, long pGameTime) {

@Override
protected void stop(ServerLevel pLevel, EntityMaid maid, long pGameTime) {
maid.getNavigation().stop();
maid.setShiftKeyDown(false);
maid.setCanClimb(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ public class EntityMaid extends TamableAnimal implements CrossbowAttackMob, IMai
* 女仆现在可以在前哨站生成,那么会打上这个标签
*/
private boolean structureSpawn = false;
/**
* 女仆主动爬行标志位,用于管控女仆当前时刻需不需要攀爬
*/
private boolean canClimb = false;

protected EntityMaid(EntityType<EntityMaid> type, Level world) {
super(type, world);
Expand Down Expand Up @@ -2010,7 +2014,7 @@ public ItemStack[] getHandItemsForAnimation() {
public Vec3 handleOnClimbable(Vec3 deltaMovement) {
Vec3 oriDelta = super.handleOnClimbable(deltaMovement);
// 主动爬行过程中严禁水平方向偏移,防止摔伤,y轴保持原样
if (this.onClimbable()) {
if (this.isCanClimb()) {
Vec3 vec3 = this.position();
if (vec3.x() % 1 != 0.5D || vec3.z() % 1 != 0.5) {
BlockPos currentPosition = this.blockPosition().mutable();
Expand All @@ -2028,10 +2032,6 @@ public Vec3 handleOnClimbable(Vec3 deltaMovement) {
@Override
public boolean onClimbable() {
boolean result = super.onClimbable();
if (level.isClientSide) {
// 客户端检测不到路径,所以客户端需要额外返回
return result;
}
if (result) {
// 爬梯时,禁止旋转
this.getLastClimbablePos().ifPresent(climbablePos -> {
Expand All @@ -2043,7 +2043,7 @@ public boolean onClimbable() {
});
});
}
return result && !this.getNavigation().isDone();
return result;
}

/**
Expand All @@ -2057,6 +2057,14 @@ public Vec3 handleRelativeFrictionAndCalculateMovement(Vec3 deltaMovement, float
return this.getDeltaMovement();
}

public boolean isCanClimb() {
return canClimb;
}

public void setCanClimb(boolean canClimb) {
this.canClimb = canClimb;
}

public void setNavigation(PathNavigation navigation) {
this.navigation = navigation;
}
Expand Down

0 comments on commit 49f47cf

Please sign in to comment.