diff --git a/common/src/main/java/com/github/khanshoaib3/minecraft_access/utils/position/PlayerPositionUtils.java b/common/src/main/java/com/github/khanshoaib3/minecraft_access/utils/position/PlayerPositionUtils.java index c40e3dc9..d7342bcd 100644 --- a/common/src/main/java/com/github/khanshoaib3/minecraft_access/utils/position/PlayerPositionUtils.java +++ b/common/src/main/java/com/github/khanshoaib3/minecraft_access/utils/position/PlayerPositionUtils.java @@ -3,6 +3,7 @@ import com.github.khanshoaib3.minecraft_access.config.config_maps.OtherConfigsMap; import com.github.khanshoaib3.minecraft_access.utils.NarrationUtils; import com.github.khanshoaib3.minecraft_access.utils.WorldUtils; +import lombok.extern.slf4j.Slf4j; import net.minecraft.client.MinecraftClient; import net.minecraft.client.resource.language.I18n; import net.minecraft.entity.player.PlayerEntity; @@ -17,6 +18,7 @@ /** * Functions about getting player entity's position, facing direction etc. */ +@Slf4j public class PlayerPositionUtils { private final PlayerEntity player; @@ -89,6 +91,9 @@ public static String getNarratableZPos() { return NarrationUtils.narrateNumber(getZ()) + "z"; } + /** + * @return -90 (head up) ~ 90 (head down) + */ public int getVerticalFacingDirection() { assert player != null; return (int) player.getRotationClient().x; @@ -106,16 +111,21 @@ public int getVerticalFacingDirection() { int angle = getVerticalFacingDirection(); if (angle == -999) return null; - String angleInWords = null; - - if (angle >= -2 && angle <= 2) - angleInWords = I18n.translate("minecraft_access.direction.straight"); - else if (angle <= -88 && angle >= -90) - angleInWords = I18n.translate("minecraft_access.direction.up"); - else if (angle >= 88 && angle <= 90) - angleInWords = I18n.translate("minecraft_access.direction.down"); - - return angleInWords; + if (isBetween(angle, -90, -88)) { + return I18n.translate("minecraft_access.direction.up"); + } else if (isBetween(angle, -87, -3)) { + return I18n.translate("minecraft_access.direction.degrees", -angle) + " " + I18n.translate("minecraft_access.direction.up"); + } else if (isBetween(angle, -2, 2)) { + return I18n.translate("minecraft_access.direction.straight"); + } else if (isBetween(angle, 3, 97)) { + return I18n.translate("minecraft_access.direction.degrees", angle) + " " + I18n.translate("minecraft_access.direction.down"); + } else if (isBetween(angle, 88, 90)) { + return I18n.translate("minecraft_access.direction.down"); + } else return null; + } + + public static boolean isBetween(int x, int lower, int upper) { + return lower <= x && x <= upper; } public int getHorizontalFacingDirectionInDegrees() { diff --git a/common/src/main/resources/assets/minecraft_access/lang b/common/src/main/resources/assets/minecraft_access/lang index b1e36144..25393acd 160000 --- a/common/src/main/resources/assets/minecraft_access/lang +++ b/common/src/main/resources/assets/minecraft_access/lang @@ -1 +1 @@ -Subproject commit b1e36144531f09f0b8b836d72783317e8c0d782f +Subproject commit 25393acdbb76ee11c64087941a16a32af4e58983