Skip to content

Commit

Permalink
fix: #313 improve vertical facing direction
Browse files Browse the repository at this point in the history
  • Loading branch information
boholder committed Aug 3, 2024
1 parent e3dcaf4 commit ef0efb9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,6 +18,7 @@
/**
* Functions about getting player entity's position, facing direction etc.
*/
@Slf4j
public class PlayerPositionUtils {
private final PlayerEntity player;

Expand Down Expand Up @@ -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;
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/resources/assets/minecraft_access/lang
Submodule lang updated 2 files
+1 −0 en_us.json
+1 −0 zh_cn.json

0 comments on commit ef0efb9

Please sign in to comment.