diff options
author | Aaron <51387595+AzureAaron@users.noreply.github.com> | 2024-02-01 18:38:22 -0500 |
---|---|---|
committer | Aaron <51387595+AzureAaron@users.noreply.github.com> | 2024-02-01 18:38:22 -0500 |
commit | 1ade575c76517a62f8666a57db7072d7b7b6634b (patch) | |
tree | 2cf3495c5d99a086bca16302b8603bc8b42d1ae9 /src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java | |
parent | 0e8a0102298b67318cb3a533f74f042994edaabc (diff) | |
download | Skyblocker-1ade575c76517a62f8666a57db7072d7b7b6634b.tar.gz Skyblocker-1ade575c76517a62f8666a57db7072d7b7b6634b.tar.bz2 Skyblocker-1ade575c76517a62f8666a57db7072d7b7b6634b.zip |
Refactor + Other changes
- Fix Mines of Divan not showing
- Code formatting
- Small Optimizations/Changes
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java')
-rw-r--r-- | src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java | 70 |
1 files changed, 34 insertions, 36 deletions
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 0c3d40eb..171f13ea 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java @@ -19,17 +19,13 @@ import java.util.Arrays; import java.util.Map; public class CrystalsHud { - public static final MinecraftClient client = MinecraftClient.getInstance(); - - protected static final Identifier MAP_TEXTURE = new Identifier(SkyblockerMod.NAMESPACE, "textures/gui/crystals_map.png"); - + private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); + private static final Identifier MAP_TEXTURE = new Identifier(SkyblockerMod.NAMESPACE, "textures/gui/crystals_map.png"); private static final Identifier MAP_ICON = new Identifier("textures/map/map_icons.png"); - - private static final String[] SMALL_LOCATIONS = new String[] {"Fairy Grotto","King","Corleone"}; + private static final String[] SMALL_LOCATIONS = { "Fairy Grotto", "King", "Corleone" }; public static boolean visible = false; - public static void init() { ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(ClientCommandManager.literal("skyblocker") .then(ClientCommandManager.literal("hud") @@ -38,8 +34,7 @@ public class CrystalsHud { HudRenderCallback.EVENT.register((context, tickDelta) -> { if (!SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.enabled - || client.options.playerListKey.isPressed() - || client.player == null + || CLIENT.player == null || !visible) { return; } @@ -48,7 +43,7 @@ public class CrystalsHud { }); } - public static IntIntPair getDimForConfig() { + protected static IntIntPair getDimForConfig() { return IntIntPair.of(62, 62); } @@ -60,40 +55,43 @@ public class CrystalsHud { * @param hudX Top left X coordinate of the map * @param hudY Top left Y coordinate of the map */ - public static void render( DrawContext context, int hudX, int hudY) { + protected static void render(DrawContext context, int hudX, int hudY) { //draw map texture - context. - drawTexture(MAP_TEXTURE,hudX,hudY,0,0,62,62,62,62); + context.drawTexture(MAP_TEXTURE, hudX, hudY, 0, 0, 62, 62, 62, 62); + //if enabled add waypoint locations to map - if (SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.showLocations){ + if (SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.showLocations) { Map<String,CrystalsWaypoint> ActiveWaypoints= CrystalsLocationsManager.activeWaypoints; - for (CrystalsWaypoint waypoint : ActiveWaypoints.values()){ + + for (CrystalsWaypoint waypoint : ActiveWaypoints.values()) { Color waypointColor = waypoint.category.color; Pair<Integer, Integer> renderPos = transformLocation(waypoint.pos.getX(),waypoint.pos.getZ()); int locationSize = SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.locationSize; - if (Arrays.asList(SMALL_LOCATIONS).contains(waypoint.name.getString())){//if small location half the location size - locationSize = locationSize/2; + + if (Arrays.asList(SMALL_LOCATIONS).contains(waypoint.name.getString())) {//if small location half the location size + locationSize = locationSize / 2; } + //fill square of size locationSize around the coordinates of the location - context.fill(hudX+renderPos.first()-locationSize/2,hudY+renderPos.second()-locationSize/2,hudX+renderPos.first()+locationSize/2,hudY+renderPos.second()+locationSize/2,waypointColor.getRGB()); + context.fill(hudX + renderPos.first() - locationSize / 2, hudY + renderPos.second() - locationSize / 2, hudX + renderPos.first() + locationSize / 2, hudY + renderPos.second() + locationSize / 2, waypointColor.getRGB()); } } + //draw player on map - if (client.player == null || client.getNetworkHandler() == null) { + if (CLIENT.player == null || CLIENT.getNetworkHandler() == null) { return; } + //get player location - double playerX = client.player.getX(); - double playerZ = client.player.getZ(); - double facing = client.player.getYaw(); + double playerX = CLIENT.player.getX(); + double playerZ = CLIENT.player.getZ(); Pair<Integer, Integer> renderPos = transformLocation(playerX,playerZ); //draw marker on map - context. - drawTexture(MAP_ICON,hudX+renderPos.first()-2,hudY+renderPos.second()-2,58,2,4,4,128,128); + context.drawTexture(MAP_ICON, hudX + renderPos.first() - 2, hudY + renderPos.second() - 2, 58, 2, 4, 4, 128, 128); //todo add direction and scale (can not work out how to rotate) - } + /** * Converts an X and Z coordinate in the crystal hollow to a X and Y coordinate on the map. * @@ -101,27 +99,27 @@ public class CrystalsHud { * @param z the world Z coordinate * @return the pair of values for x and y */ - protected static Pair<Integer, Integer> transformLocation(double x, double z){ + protected static Pair<Integer, Integer> transformLocation(double x, double z) { //converts an x and z to a location on the map - int transformedX = (int)((x-202)/621 * 62); - int transformedY = (int)((z -202)/621 * 62); - transformedX = MathHelper.clamp(transformedX,0, 62); - transformedY = MathHelper.clamp(transformedY,0, 62); - return Pair.of(transformedX,transformedY); + int transformedX = (int)((x - 202) / 621 * 62); + int transformedY = (int)((z - 202) / 621 * 62); + transformedX = MathHelper.clamp(transformedX, 0, 62); + transformedY = MathHelper.clamp(transformedY, 0, 62); + + return Pair.of(transformedX,transformedY); } + /** * Works out if the crystals map should be rendered and sets {@link CrystalsHud#visible} accordingly. * */ public static void update() { - if (client.player == null || client.getNetworkHandler() == null || !SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.enabled) { + if (CLIENT.player == null || CLIENT.getNetworkHandler() == null || !SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.enabled) { visible = false; return; } - //get if the player is in the crystals - visible = Utils.isInCrystals(); - + //get if the player is in the crystals + visible = Utils.isInCrystalHollows(); } - } |