From ebd53811b276b28bf4848846503c8c2a78104223 Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Sat, 3 Feb 2024 06:13:42 -0500 Subject: Vanilla-like marker rotation --- .../de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java index d1303675..35f26c0e 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java @@ -106,7 +106,7 @@ public class CrystalsHud { //position, scale and rotate the player marker matrices.translate(renderX, renderY, 0f); matrices.scale(0.75f, 0.75f, 0f); - matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(playerRotation + 180f), 2, 3, 0); + matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(yaw2Cardinal(playerRotation)), 2, 3, 0); //draw marker on map context.drawTexture(MAP_ICON, 0, 0, 2, 0, 5, 7, 128, 128); @@ -132,6 +132,18 @@ public class CrystalsHud { return IntIntPair.of(transformedX,transformedY); } + /** + * Converts yaw to the cardinal directions that a player marker can be rotated towards on a map. + * The rotations of a marker follow this order: N, NNE, NE, ENE, E, ESE, SE, SSE, S, SSW, SW, WSW, W, WNW, NW, NNW. + *

+ * Based off code from {@link net.minecraft.client.render.MapRenderer} + */ + private static float yaw2Cardinal(float yaw) { + byte clipped = (byte)((yaw += yaw < 0.0 ? -8.0 : 8.0) * 16.0 / 360.0); + + return (clipped * 360f) / 16f; + } + /** * Works out if the crystals map should be rendered and sets {@link CrystalsHud#visible} accordingly. * -- cgit