Skip to content

Commit

Permalink
Use seated pos when checking entity distance
Browse files Browse the repository at this point in the history
  • Loading branch information
Endalion committed Dec 13, 2024
1 parent fad8c88 commit dd64efa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,29 @@ private void preGetEyePosition(final float partialTicks, final CallbackInfoRetur
cir.setReturnValue(newEyePos);
}

@Inject(method = "getEyePosition()Lnet/minecraft/world/phys/Vec3;", at = @At("HEAD"), cancellable = true)
private void preGetEyePosition2(final CallbackInfoReturnable<Vec3> cir) {
final ShipMountedToData shipMountedToData = VSGameUtilsKt.getShipMountedToData(Entity.class.cast(this), null);
if (shipMountedToData == null) {
return;
}
final LoadedShip shipMountedTo = shipMountedToData.getShipMountedTo();

final ShipTransform shipTransform;
if (shipMountedTo instanceof ShipObjectClient) {
shipTransform = ((ShipObjectClient) shipMountedTo).getRenderTransform();
} else {
shipTransform = shipMountedTo.getShipTransform();
}
final Vector3dc basePos = shipTransform.getShipToWorldMatrix()
.transformPosition(shipMountedToData.getMountPosInShip(), new Vector3d());
final Vector3dc eyeRelativePos = shipTransform.getShipCoordinatesToWorldCoordinatesRotation().transform(
new Vector3d(0.0, getEyeHeight(), 0.0)
);
final Vec3 newEyePos = VectorConversionsMCKt.toMinecraft(basePos.add(eyeRelativePos, new Vector3d()));
cir.setReturnValue(newEyePos);
}

/**
* @reason Needed for players to pick blocks correctly when mounted to a ship
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,11 @@ val Player.playerWrapper get() = (this as PlayerDuck).vs_getPlayer()
/**
* Like [Entity.squaredDistanceTo] except the destination is transformed into world coordinates if it is a ship
*/
fun Entity.squaredDistanceToInclShips(x: Double, y: Double, z: Double) =
level.squaredDistanceBetweenInclShips(x, y, z, this.x, this.y, this.z)
fun Entity.squaredDistanceToInclShips(x: Double, y: Double, z: Double): Double {
var p = this.position()
getShipMountedToData(this, null)?.mountPosInShip?.toMinecraft()?.let{ p = it }
return level().squaredDistanceBetweenInclShips(x, y, z, p.x, p.y, p.z)
}

/**
* Calculates the squared distance between to points.
Expand Down

0 comments on commit dd64efa

Please sign in to comment.