From 86035f311b28094daf1ab7dbda7c888259e56723 Mon Sep 17 00:00:00 2001 From: olim Date: Wed, 31 Jan 2024 10:52:37 +0000 Subject: added powder hud added powder to the dwarven hud --- .../skyblock/dwarven/DwarvenHudConfigScreen.java | 38 +++++++++++++++------- 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java index 6f281ba9..5efa9c03 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java @@ -3,7 +3,9 @@ package de.hysky.skyblocker.skyblock.dwarven; import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.skyblock.dwarven.DwarvenHud.Commission; import de.hysky.skyblocker.skyblock.tabhud.widget.hud.HudCommsWidget; +import de.hysky.skyblocker.skyblock.tabhud.widget.hud.HudPowderWidget; import de.hysky.skyblocker.utils.render.RenderHelper; +import it.unimi.dsi.fastutil.Pair; import it.unimi.dsi.fastutil.ints.IntIntPair; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; @@ -15,9 +17,13 @@ import java.util.List; public class DwarvenHudConfigScreen extends Screen { private static final List CFG_COMMS = List.of(new Commission("Test Commission 1", "1%"), new DwarvenHud.Commission("Test Commission 2", "2%")); + private static final int CFG_MITHRIL = 100; + private static final int CFG_GEMSTONE = 1010; + private int commissionsHudX = SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.commissionsX; + private int commissionsHudY = SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.commissionsY; - private int hudX = SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.x; - private int hudY = SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.y; + private int powderHudX = SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.powderX; + private int powderHudY = SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.powderY; private final Screen parent; protected DwarvenHudConfigScreen() { @@ -33,16 +39,20 @@ public class DwarvenHudConfigScreen extends Screen { public void render(DrawContext context, int mouseX, int mouseY, float delta) { super.render(context, mouseX, mouseY, delta); renderBackground(context, mouseX, mouseY, delta); - DwarvenHud.render(HudCommsWidget.INSTANCE_CFG, context, hudX, hudY, List.of(new DwarvenHud.Commission("Test Commission 1", "1%"), new DwarvenHud.Commission("Test Commission 2", "2%"))); + DwarvenHud.render(HudCommsWidget.INSTANCE_CFG, HudPowderWidget.INSTANCE_CFG, context, commissionsHudX, commissionsHudY,powderHudX,powderHudY,CFG_COMMS,CFG_MITHRIL,CFG_GEMSTONE); context.drawCenteredTextWithShadow(textRenderer, "Right Click To Reset Position", width / 2, height / 2, Color.GRAY.getRGB()); } @Override public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { - IntIntPair dims = DwarvenHud.getDimForConfig(CFG_COMMS); - if (RenderHelper.pointIsInArea(mouseX, mouseY, hudX, hudY, hudX + 200, hudY + 40) && button == 0) { - hudX = (int) Math.max(Math.min(mouseX - (double) dims.leftInt() / 2, this.width - dims.leftInt()), 0); - hudY = (int) Math.max(Math.min(mouseY - (double) dims.rightInt() / 2, this.height - dims.rightInt()), 0); + Pair dims = DwarvenHud.getDimForConfig(CFG_COMMS); + if (RenderHelper.pointIsInArea(mouseX, mouseY, commissionsHudX, commissionsHudY, commissionsHudX + 200, commissionsHudY + 40) && button == 0) { + commissionsHudX = (int) Math.max(Math.min(mouseX - (double) dims.first().leftInt() / 2, this.width - dims.first().leftInt()), 0); + commissionsHudY = (int) Math.max(Math.min(mouseY - (double) dims.first().rightInt() / 2, this.height - dims.first().rightInt()), 0); + } + if (RenderHelper.pointIsInArea(mouseX, mouseY, powderHudX, powderHudY, powderHudX + 200, powderHudY + 40) && button == 0) { + powderHudX = (int) Math.max(Math.min(mouseX - (double) dims.second().leftInt() / 2, this.width - dims.second().leftInt()), 0); + powderHudY = (int) Math.max(Math.min(mouseY - (double) dims.second().rightInt() / 2, this.height - dims.second().rightInt()), 0); } return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); } @@ -50,17 +60,21 @@ public class DwarvenHudConfigScreen extends Screen { @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { if (button == 1) { - IntIntPair dims = DwarvenHud.getDimForConfig(CFG_COMMS); - hudX = this.width / 2 - dims.leftInt(); - hudY = this.height / 2 - dims.rightInt(); + Pair dims = DwarvenHud.getDimForConfig(CFG_COMMS); + commissionsHudX = this.width / 2 - dims.left().leftInt(); + commissionsHudY = this.height / 2 - dims.left().rightInt(); + powderHudX = this.width / 2 - dims.right().leftInt(); + powderHudY = this.height / 2 - dims.right().rightInt() + dims.left().rightInt(); //add this to make it bellow the other widget } return super.mouseClicked(mouseX, mouseY, button); } @Override public void close() { - SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.x = hudX; - SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.y = hudY; + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.commissionsX = commissionsHudX; + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.commissionsY = commissionsHudY; + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.powderX = powderHudX; + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.powderY = powderHudY; SkyblockerConfigManager.save(); client.setScreen(parent); -- cgit From 1f991fb10bafc4082c3b75e1b29c57d72e246919 Mon Sep 17 00:00:00 2001 From: olim Date: Thu, 1 Feb 2024 17:46:27 +0000 Subject: fix request changes fixed the issues brought. and also fixed issue that dwarven hud render classic did not have values for powder --- .../hysky/skyblocker/config/SkyblockerConfig.java | 8 +--- .../skyblocker/skyblock/dwarven/CrystalsHud.java | 8 ++-- .../skyblock/dwarven/CrystalsLocationsManager.java | 25 ++++-------- .../skyblock/dwarven/CrystalsWaypoint.java | 18 +++------ .../skyblocker/skyblock/dwarven/DwarvenHud.java | 45 ++++++++++++--------- .../skyblock/dwarven/DwarvenHudConfigScreen.java | 12 +++--- .../resources/assets/skyblocker/lang/en_us.json | 2 +- .../skyblocker/textures/gui/crystals_map.png | Bin 39156 -> 38864 bytes 8 files changed, 52 insertions(+), 66 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java') diff --git a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java index a07b0084..775c70ce 100644 --- a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java @@ -898,10 +898,10 @@ public class SkyblockerConfig { public boolean enableBackground = true; @SerialEntry - public int commissionsX = 10; + public int x = 10; @SerialEntry - public int commissionsY = 10; + public int y = 10; @SerialEntry public int powderX = 10; @@ -931,10 +931,6 @@ public class SkyblockerConfig { @SerialEntry public boolean findInChat = true; - @SerialEntry - public Map ActiveWaypoints = new HashMap<>() {}; - - } public enum DwarvenHudStyle { 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 6b26d043..59d70405 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java @@ -14,6 +14,7 @@ import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.util.Identifier; +import net.minecraft.util.math.MathHelper; import java.awt.*; import java.util.Arrays; @@ -67,7 +68,7 @@ public class CrystalsHud { 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){ - Map ActiveWaypoints= SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.ActiveWaypoints; + Map ActiveWaypoints= CrystalsLocationsManager.ActiveWaypoints; for (CrystalsWaypoint waypoint : ActiveWaypoints.values()){ Color waypointColor = waypoint.category.color; Pair renderPos = transformLocation(waypoint.pos.getX(),waypoint.pos.getZ()); @@ -106,9 +107,8 @@ public class CrystalsHud { //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 = Math.max(0, Math.min(62, transformedX)); - transformedY = Math.max(0, Math.min(62, transformedY)); - + transformedX = MathHelper.clamp(transformedX,0, 62); + transformedY = MathHelper.clamp(transformedY,0, 62); return Pair.of(transformedX,transformedY); } /** diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java index eb68ed9f..74730315 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -1,14 +1,11 @@ package de.hysky.skyblocker.skyblock.dwarven; -import com.mojang.authlib.GameProfile; import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; import de.hysky.skyblocker.SkyblockerMod; import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.utils.Utils; -import de.hysky.skyblocker.utils.scheduler.Scheduler; -import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; @@ -17,19 +14,14 @@ import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; import net.minecraft.client.MinecraftClient; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.argument.BlockPosArgumentType; -import net.minecraft.command.argument.DefaultPosArgument; import net.minecraft.command.argument.PosArgument; -import net.minecraft.network.message.MessageType; -import net.minecraft.network.message.SignedMessage; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.ClickEvent; import net.minecraft.text.MutableText; import net.minecraft.text.Text; -import net.minecraft.util.Util; import net.minecraft.util.math.BlockPos; import java.awt.*; -import java.time.Instant; import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -47,16 +39,17 @@ public class CrystalsLocationsManager { * A look-up table to convert between location names and waypoint in the {@link CrystalsWaypoint.Category} values. */ public static final Map WAYPOINTLOCATIONS = Map.of( - "Jungle Temple", CrystalsWaypoint.Category.JUNGLETEMPLE, - "Mines Of Divan", CrystalsWaypoint.Category.MINESOFDIVAN, - "Goblin Queen's Den", CrystalsWaypoint.Category.GOBLINQUEENSDEN, - "Lost Precursor City", CrystalsWaypoint.Category.LOSTPRECURSORCITY, + "Jungle Temple", CrystalsWaypoint.Category.JUNGLE_TEMPLE, + "Mines Of Divan", CrystalsWaypoint.Category.MINES_OF_DIVAN, + "Goblin Queen's Den", CrystalsWaypoint.Category.GOBLIN_QUEENS_DEN, + "Lost Precursor City", CrystalsWaypoint.Category.LOST_PRECURSOR_CITY, "Khazad-dûm", CrystalsWaypoint.Category.KHAZADUM, - "Fairy Grotto", CrystalsWaypoint.Category.FAIRYGROTTO, - "Dragon's Lair", CrystalsWaypoint.Category.DRAGONSLAIR, + "Fairy Grotto", CrystalsWaypoint.Category.FAIRY_GROTTO, + "Dragon's Lair", CrystalsWaypoint.Category.DRAGONS_LAIR, "Corleone", CrystalsWaypoint.Category.CORLEONE, "King", CrystalsWaypoint.Category.KING ); + protected static Map ActiveWaypoints = new HashMap<>() {}; private static final Pattern TEXT_CWORDS_PATTERN = Pattern.compile("([0-9][0-9][0-9]) ([0-9][0-9][0-9]?) ([0-9][0-9][0-9])"); @@ -149,13 +142,11 @@ public class CrystalsLocationsManager { private static void addCustomWaypoint( Text waypointName, BlockPos pos) { CrystalsWaypoint.Category category = WAYPOINTLOCATIONS.get(waypointName.getString()); CrystalsWaypoint waypoint = new CrystalsWaypoint(category, waypointName, pos); - Map ActiveWaypoints= SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.ActiveWaypoints; ActiveWaypoints.put(waypointName.getString(),waypoint); } public static void render(WorldRenderContext context) { if (SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.enabled ) { - Map ActiveWaypoints= SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.ActiveWaypoints; for (CrystalsWaypoint crystalsWaypoint : ActiveWaypoints.values()) { if (crystalsWaypoint.shouldRender()) { crystalsWaypoint.render(context); @@ -166,13 +157,11 @@ public class CrystalsLocationsManager { public static void update() { if (client.player == null || client.getNetworkHandler() == null || !SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.enabled || !Utils.isInCrystals()) { - SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.ActiveWaypoints= new HashMap<>(); return; } //get if the player is in the crystals String location = Utils.getIslandArea().replace("⏣ ",""); //if new location and needs waypoint add waypoint - Map ActiveWaypoints= SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.ActiveWaypoints; if (!location.equals("Unknown") && WAYPOINTLOCATIONS.containsKey(location) && !ActiveWaypoints.containsKey(location)){ //add waypoint at player location BlockPos playerLocation = client.player.getBlockPos(); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java index 3ae56c47..f9016f3a 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java @@ -1,20 +1,16 @@ package de.hysky.skyblocker.skyblock.dwarven; import com.google.gson.JsonObject; -import com.mojang.brigadier.context.CommandContext; import com.mojang.serialization.Codec; import com.mojang.serialization.JsonOps; -import com.mojang.serialization.codecs.RecordCodecBuilder; import de.hysky.skyblocker.config.SkyblockerConfig; import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.utils.render.RenderHelper; import de.hysky.skyblocker.utils.waypoint.Waypoint; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; import net.minecraft.client.MinecraftClient; -import net.minecraft.command.argument.EnumArgumentType; import net.minecraft.entity.Entity; import net.minecraft.text.Text; -import net.minecraft.text.TextCodecs; import net.minecraft.util.Formatting; import net.minecraft.util.StringIdentifiable; import net.minecraft.util.math.BlockPos; @@ -23,8 +19,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.awt.*; -import java.util.List; -import java.util.Map; import java.util.function.Predicate; import java.util.function.Supplier; import java.util.function.ToDoubleFunction; @@ -84,13 +78,13 @@ public class CrystalsWaypoint extends Waypoint { * enum for the different waypoints used int the crystals hud each with a {@link Category#name} and associated {@link Category#color} */ enum Category implements StringIdentifiable { - JUNGLETEMPLE("Jungle Temple",Color.GREEN), - MINESOFDIVAN("Mines Of Divan",Color.CYAN), - GOBLINQUEENSDEN("Goblin Queen's Den",Color.ORANGE), - LOSTPRECURSORCITY("Lost Precursor City",Color.BLUE), + JUNGLE_TEMPLE("Jungle Temple",Color.GREEN), + MINES_OF_DIVAN("Mines Of Divan",Color.CYAN), + GOBLIN_QUEENS_DEN("Goblin Queen's Den",Color.ORANGE), + LOST_PRECURSOR_CITY("Lost Precursor City",Color.BLUE), KHAZADUM("Khazad-dûm",Color.RED), - FAIRYGROTTO("Fairy Grotto",Color.PINK), - DRAGONSLAIR("Dragon's Lair",Color.BLACK), + FAIRY_GROTTO("Fairy Grotto",Color.PINK), + DRAGONS_LAIR("Dragon's Lair",Color.BLACK), CORLEONE("Corleone",Color.gray), KING("King",Color.yellow), DEFAULT("Default",Color.BLACK); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java index fb055b87..5c3498bc 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java @@ -15,6 +15,7 @@ import net.minecraft.client.gui.DrawContext; import net.minecraft.text.Text; import net.minecraft.util.Formatting; +import java.awt.*; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; @@ -27,8 +28,8 @@ public class DwarvenHud { public static final MinecraftClient client = MinecraftClient.getInstance(); public static List commissionList = new ArrayList<>(); - public static int mithrilPowder = 0; - public static int gemStonePowder = 0; + public static String mithrilPowder = "0"; + public static String gemStonePowder = "0"; public static final List COMMISSIONS = Stream.of( "(?:Titanium|Mithril|Hard Stone) Miner", @@ -44,6 +45,8 @@ public class DwarvenHud { "(?:Amber|Sapphire|Jade|Amethyst|Topaz) Crystal Hunter", "Chest Looter").map(s -> Pattern.compile("^.*(" + s + "): (\\d+\\.?\\d*%|DONE)")) .collect(Collectors.toList()); + public static final Pattern MITHRIL_PATTERN = Pattern.compile("Mithril Powder: [0-9,]+"); + public static final Pattern GEMSTONE_PATTERN = Pattern.compile("Gemstone Powder: [0-9,]+"); public static void init() { ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(ClientCommandManager.literal("skyblocker") @@ -59,11 +62,11 @@ public class DwarvenHud { return; } render(HudCommsWidget.INSTANCE,HudPowderWidget.INSTANCE, context, - SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.commissionsX, - SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.commissionsY, + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.x, + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.y, SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.powderX, SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.powderY, - commissionList,mithrilPowder,gemStonePowder); + commissionList); }); } @@ -107,11 +110,11 @@ public class DwarvenHud { }; } - public static void render(HudCommsWidget hcw, HudPowderWidget hpw, DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List commissions,int mithril, int gemStone) { + public static void render(HudCommsWidget hcw, HudPowderWidget hpw, DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List commissions) { switch (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.style) { - case SIMPLE -> renderSimple(hcw,hpw, context, comHudX, comHudY,powderHudX,powderHudY, commissions,mithril,gemStone); - case FANCY -> renderFancy(hcw,hpw, context, comHudX, comHudY,powderHudX,powderHudY, commissions,mithril,gemStone); + case SIMPLE -> renderSimple(hcw,hpw, context, comHudX, comHudY,powderHudX,powderHudY, commissions); + case FANCY -> renderFancy(hcw,hpw, context, comHudX, comHudY,powderHudX,powderHudY, commissions); case CLASSIC -> renderClassic(context, comHudX, comHudY,powderHudX,powderHudY, commissions); } } @@ -142,10 +145,8 @@ public class DwarvenHud { context .drawTextWithShadow(client.textRenderer, - Text.literal(commission.commission + ": ") - .styled(style -> style.withColor(Formatting.AQUA)) - .append(Text.literal(commission.progression) - .styled(style -> style.withColor(Colors.hypixelProgressColor(percentage)))), + Text.literal(commission.commission + ": ").formatted(Formatting.AQUA) + .append(Text.literal(commission.progression).formatted(Colors.hypixelProgressColor(percentage))), comHudX + 5, comHudY + y + 5, 0xFFFFFFFF); y += 20; } @@ -154,18 +155,16 @@ public class DwarvenHud { //render mithril powder then gemstone context .drawTextWithShadow(client.textRenderer, - Text.literal("Mithril: " + mithrilPowder) - .styled(style -> style.withColor(Formatting.AQUA)), + Text.literal("Mithril: " + mithrilPowder).formatted(Formatting.AQUA), powderHudX + 5, powderHudY + 5, 0xFFFFFFFF); context .drawTextWithShadow(client.textRenderer, - Text.literal("Gemstone: " + gemStonePowder) - .styled(style -> style.withColor(Formatting.DARK_PURPLE)), + Text.literal("Gemstone: " + gemStonePowder).formatted(Formatting.DARK_PURPLE), powderHudX + 5, powderHudY + 25, 0xFFFFFFFF); } } - public static void renderSimple(HudCommsWidget hcw, HudPowderWidget hpw, DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List commissions,int mithril, int gemStone) { + public static void renderSimple(HudCommsWidget hcw, HudPowderWidget hpw, DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List commissions) { if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions) { hcw.updateData(commissions, false); hcw.update(); @@ -183,7 +182,7 @@ public class DwarvenHud { } } - public static void renderFancy(HudCommsWidget hcw, HudPowderWidget hpw, DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List commissions,int mithril, int gemStone) { + public static void renderFancy(HudCommsWidget hcw, HudPowderWidget hpw, DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List commissions) { if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions) { hcw.updateData(commissions, true); hcw.update(); @@ -208,6 +207,7 @@ public class DwarvenHud { client.getNetworkHandler().getPlayerList().forEach(playerListEntry -> { if (playerListEntry.getDisplayName() != null) { + //find commissions for (Pattern pattern : COMMISSIONS) { Matcher matcher = pattern.matcher(playerListEntry.getDisplayName().getString()); if (matcher.find()) { @@ -215,6 +215,15 @@ public class DwarvenHud { } } + //find powder + Matcher mithrilMatcher = MITHRIL_PATTERN.matcher(playerListEntry.getDisplayName().getString()); + if (mithrilMatcher.find()){ + mithrilPowder = mithrilMatcher.group(0).split(": ")[1]; + } + Matcher gemstoneMatcher = GEMSTONE_PATTERN.matcher(playerListEntry.getDisplayName().getString()); + if (gemstoneMatcher.find()){ + gemStonePowder = gemstoneMatcher.group(0).split(": ")[1]; + } } }); } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java index 5efa9c03..4214ca89 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java @@ -17,10 +17,8 @@ import java.util.List; public class DwarvenHudConfigScreen extends Screen { private static final List CFG_COMMS = List.of(new Commission("Test Commission 1", "1%"), new DwarvenHud.Commission("Test Commission 2", "2%")); - private static final int CFG_MITHRIL = 100; - private static final int CFG_GEMSTONE = 1010; - private int commissionsHudX = SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.commissionsX; - private int commissionsHudY = SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.commissionsY; + private int commissionsHudX = SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.x; + private int commissionsHudY = SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.y; private int powderHudX = SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.powderX; private int powderHudY = SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.powderY; @@ -39,7 +37,7 @@ public class DwarvenHudConfigScreen extends Screen { public void render(DrawContext context, int mouseX, int mouseY, float delta) { super.render(context, mouseX, mouseY, delta); renderBackground(context, mouseX, mouseY, delta); - DwarvenHud.render(HudCommsWidget.INSTANCE_CFG, HudPowderWidget.INSTANCE_CFG, context, commissionsHudX, commissionsHudY,powderHudX,powderHudY,CFG_COMMS,CFG_MITHRIL,CFG_GEMSTONE); + DwarvenHud.render(HudCommsWidget.INSTANCE_CFG, HudPowderWidget.INSTANCE_CFG, context, commissionsHudX, commissionsHudY,powderHudX,powderHudY,CFG_COMMS); context.drawCenteredTextWithShadow(textRenderer, "Right Click To Reset Position", width / 2, height / 2, Color.GRAY.getRGB()); } @@ -71,8 +69,8 @@ public class DwarvenHudConfigScreen extends Screen { @Override public void close() { - SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.commissionsX = commissionsHudX; - SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.commissionsY = commissionsHudY; + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.x = commissionsHudX; + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.y = commissionsHudY; SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.powderX = powderHudX; SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.powderY = powderHudY; SkyblockerConfigManager.save(); diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 8c3a2dc5..fd583639 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -285,7 +285,7 @@ "text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.showLocations.locationSize.@Tooltip": "How big the locations show up on the map.", "text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints": "Crystal Hollows Waypoints", "text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.enabled": "Enabled Waypoints", - "text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.enabled.@Tooltip": "Show a waypoint (waypoint selected in general/waypoints) at important areas in teh crystal hollows e.g. Jungle Temple and Fairy Grotto. ", + "text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.enabled.@Tooltip": "Show a waypoint (waypoint selected in general/waypoints) at important areas in the crystal hollows e.g. Jungle Temple and Fairy Grotto. ", "text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.findInChat": "Find Waypoints In Chat", "text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.findInChat.@Tooltip": "When in crystal hollows read the chat to see if coordinates are sent and extract these to show as waypoint or on the map", diff --git a/src/main/resources/assets/skyblocker/textures/gui/crystals_map.png b/src/main/resources/assets/skyblocker/textures/gui/crystals_map.png index 4e807ea1..b7386eeb 100644 Binary files a/src/main/resources/assets/skyblocker/textures/gui/crystals_map.png and b/src/main/resources/assets/skyblocker/textures/gui/crystals_map.png differ -- cgit From 1ade575c76517a62f8666a57db7072d7b7b6634b Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Thu, 1 Feb 2024 18:38:22 -0500 Subject: Refactor + Other changes - Fix Mines of Divan not showing - Code formatting - Small Optimizations/Changes --- .../hysky/skyblocker/config/SkyblockerConfig.java | 2 + .../skyblocker/skyblock/dwarven/CrystalsHud.java | 70 ++++++----- .../skyblock/dwarven/CrystalsHudConfigScreen.java | 1 - .../skyblock/dwarven/CrystalsLocationsManager.java | 129 +++++++++++++-------- .../skyblock/dwarven/CrystalsWaypoint.java | 23 ++-- .../skyblocker/skyblock/dwarven/DwarvenHud.java | 11 +- .../skyblock/dwarven/DwarvenHudConfigScreen.java | 2 +- .../tabhud/widget/hud/HudPowderWidget.java | 7 -- src/main/java/de/hysky/skyblocker/utils/Utils.java | 8 +- .../resources/assets/skyblocker/lang/en_us.json | 2 +- .../skyblock/dwarven/CrystalsHudTest.java | 10 +- .../dwarven/CrystalsLocationManagerTest.java | 7 +- 12 files changed, 148 insertions(+), 124 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java') diff --git a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java index 775c70ce..5ca9604c 100644 --- a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java @@ -909,6 +909,7 @@ public class SkyblockerConfig { @SerialEntry public int powderY = 70; } + public static class CrystalsHud { @SerialEntry public boolean enabled = true; @@ -925,6 +926,7 @@ public class SkyblockerConfig { @SerialEntry public int y = 130; } + public static class CrystalsWaypoints { @SerialEntry public boolean enabled = true; 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 ActiveWaypoints= CrystalsLocationsManager.activeWaypoints; - for (CrystalsWaypoint waypoint : ActiveWaypoints.values()){ + + for (CrystalsWaypoint waypoint : ActiveWaypoints.values()) { Color waypointColor = waypoint.category.color; Pair 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 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 transformLocation(double x, double z){ + protected static Pair 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(); } - } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudConfigScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudConfigScreen.java index 18be8bed..e30d6390 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudConfigScreen.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudConfigScreen.java @@ -1,7 +1,6 @@ package de.hysky.skyblocker.skyblock.dwarven; import de.hysky.skyblocker.config.SkyblockerConfigManager; -import de.hysky.skyblocker.skyblock.tabhud.widget.hud.HudCommsWidget; import de.hysky.skyblocker.utils.render.RenderHelper; import it.unimi.dsi.fastutil.ints.IntIntPair; import net.minecraft.client.gui.DrawContext; diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java index 8101fae6..5b196f8e 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -3,12 +3,16 @@ package de.hysky.skyblocker.skyblock.dwarven; import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.logging.LogUtils; + import de.hysky.skyblocker.SkyblockerMod; import de.hysky.skyblocker.config.SkyblockerConfigManager; +import de.hysky.skyblocker.utils.Constants; import de.hysky.skyblocker.utils.Utils; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; import net.minecraft.client.MinecraftClient; @@ -28,19 +32,22 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.slf4j.Logger; + import static com.mojang.brigadier.arguments.StringArgumentType.getString; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; public class CrystalsLocationsManager { - public static final MinecraftClient client = MinecraftClient.getInstance(); + private static final Logger LOGGER = LogUtils.getLogger(); + private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); /** * A look-up table to convert between location names and waypoint in the {@link CrystalsWaypoint.Category} values. */ - public static final Map WAYPOINTLOCATIONS = Map.of( + protected static final Map WAYPOINT_LOCATIONS = Map.of( "Jungle Temple", CrystalsWaypoint.Category.JUNGLE_TEMPLE, - "Mines Of Divan", CrystalsWaypoint.Category.MINES_OF_DIVAN, + "Mines of Divan", CrystalsWaypoint.Category.MINES_OF_DIVAN, "Goblin Queen's Den", CrystalsWaypoint.Category.GOBLIN_QUEENS_DEN, "Lost Precursor City", CrystalsWaypoint.Category.LOST_PRECURSOR_CITY, "Khazad-dûm", CrystalsWaypoint.Category.KHAZADUM, @@ -49,53 +56,64 @@ public class CrystalsLocationsManager { "Corleone", CrystalsWaypoint.Category.CORLEONE, "King", CrystalsWaypoint.Category.KING ); - protected static Map activeWaypoints = new HashMap<>() {}; - private static final Pattern TEXT_CWORDS_PATTERN = Pattern.compile("([0-9][0-9][0-9]) ([0-9][0-9][0-9]?) ([0-9][0-9][0-9])"); + protected static Map activeWaypoints = new HashMap<>(); public static void init() { WorldRenderEvents.AFTER_TRANSLUCENT.register(CrystalsLocationsManager::render); ClientReceiveMessageEvents.GAME.register(CrystalsLocationsManager::extractLocationFromMessage); ClientCommandRegistrationCallback.EVENT.register(CrystalsLocationsManager::registerWaypointLocationCommands); + ClientPlayConnectionEvents.JOIN.register((_handler, _sender, _client) -> reset()); } - private static void extractLocationFromMessage(Text message, Boolean overlay){ - if (!SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.findInChat || !Utils.isInCrystals()) { + + private static void extractLocationFromMessage(Text message, Boolean overlay) { + if (!SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.findInChat || !Utils.isInCrystalHollows()) { return; } - //get the message text - String value = message.getString(); - Matcher matcher = TEXT_CWORDS_PATTERN.matcher(value); - //if there are coordinates in the message try to get them and what they are talking about - if (matcher.find()){ - String location = matcher.group(); - Integer[] coordinates = Arrays.stream(location.split(" ",3)).map(Integer::parseInt).toArray(Integer[]::new); - BlockPos blockPos = new BlockPos(coordinates[0],coordinates[1],coordinates[2]); - //if position is not in the hollows do not add it - if (!checkInCrystals(blockPos)){ - return; - } - //see if there is a name of a location to add to this - for (String waypointLocation : WAYPOINTLOCATIONS.keySet()){ - if (value.toLowerCase().contains(waypointLocation.toLowerCase())){ //todo be more lenient - //all data found to create waypoint - addCustomWaypoint(Text.of(waypointLocation),blockPos); + + try { + //get the message text + String value = message.getString(); + Matcher matcher = TEXT_CWORDS_PATTERN.matcher(value); + //if there are coordinates in the message try to get them and what they are talking about + if (matcher.find()) { + String location = matcher.group(); + int[] coordinates = Arrays.stream(location.split(" ", 3)).mapToInt(Integer::parseInt).toArray(); + BlockPos blockPos = new BlockPos(coordinates[0], coordinates[1], coordinates[2]); + + //if position is not in the hollows do not add it + if (!checkInCrystals(blockPos)) { return; } + + //see if there is a name of a location to add to this + for (String waypointLocation : WAYPOINT_LOCATIONS.keySet()) { + if (value.toLowerCase().contains(waypointLocation.toLowerCase())) { //todo be more lenient + //all data found to create waypoint + addCustomWaypoint(Text.of(waypointLocation),blockPos); + return; + } + } + + //if the location is not found ask the user for the location (could have been in a previous chat message) + if (CLIENT.player == null || CLIENT.getNetworkHandler() == null) { + return; + } + + CLIENT.player.sendMessage(getLocationInputText(location), false); } - //if the location is not found ask the user for the location (could have been in a previous chat message) - if (client.player == null || client.getNetworkHandler() == null ) { - return; - } - client.player.sendMessage(getLocationInputText(location), false); + } catch (Exception e) { + LOGGER.error("[Skyblocker Crystals Locations Manager] Encountered an exception while extracing a location from a chat message!", e); } } protected static Boolean checkInCrystals(BlockPos pos){ //checks if a location is inside crystal hollows bounds - return pos.getX() >= 202 && pos.getX() <= 823 + return pos.getX() >= 202 && pos.getX() <= 823 && pos.getZ() >= 202 && pos.getZ() <= 823 && pos.getY() >= 31 && pos.getY() <= 188; } + private static void registerWaypointLocationCommands(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { dispatcher.register(literal(SkyblockerMod.NAMESPACE) .then(literal("crystalWaypoints") @@ -107,46 +125,55 @@ public class CrystalsLocationsManager { ) ); } + protected static Text getSetLocationMessage(String location,BlockPos blockPos) { - MutableText text = Text.empty(); + MutableText text = Constants.PREFIX.get(); text.append(Text.literal("Added waypoint for ")); - Color locationColor = WAYPOINTLOCATIONS.get(location).color; + Color locationColor = WAYPOINT_LOCATIONS.get(location).color; text.append(Text.literal(location).withColor(locationColor.getRGB())); - text.append(Text.literal(" at : "+blockPos.getX()+" "+blockPos.getY()+" "+blockPos.getZ()+".")); + text.append(Text.literal(" at : " + blockPos.getX() + " " + blockPos.getY() + " " + blockPos.getZ() + ".")); + return text; } + private static Text getLocationInputText(String location) { - MutableText text = Text.empty(); - for (String waypointLocation : WAYPOINTLOCATIONS.keySet()){ - Color locationColor = WAYPOINTLOCATIONS.get(waypointLocation).color; - text.append(Text.literal("["+waypointLocation+"]").withColor(locationColor.getRGB()).styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/skyblocker crystalWaypoints "+location+" "+waypointLocation)))); + MutableText text = Constants.PREFIX.get(); + + for (String waypointLocation : WAYPOINT_LOCATIONS.keySet()) { + Color locationColor = WAYPOINT_LOCATIONS.get(waypointLocation).color; + text.append(Text.literal("[" + waypointLocation + "]").withColor(locationColor.getRGB()).styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/skyblocker crystalWaypoints " + location + " " + waypointLocation)))); } return text; } + public static int addWaypointFromCommand(FabricClientCommandSource source, String place, PosArgument location) { // TODO Less hacky way with custom ClientBlockPosArgumentType BlockPos blockPos = location.toAbsoluteBlockPos(new ServerCommandSource(null, source.getPosition(), source.getRotation(), null, 0, null, null, null, null)); - if (WAYPOINTLOCATIONS.containsKey(place)){ + + if (WAYPOINT_LOCATIONS.containsKey(place)) { addCustomWaypoint(Text.of(place), blockPos); + //tell the client it has done this - if (client.player == null || client.getNetworkHandler() == null ) { + if (CLIENT.player == null || CLIENT.getNetworkHandler() == null) { return 0; } - client.player.sendMessage(getSetLocationMessage(place, blockPos), false); + + CLIENT.player.sendMessage(getSetLocationMessage(place, blockPos), false); } + return Command.SINGLE_SUCCESS; } private static void addCustomWaypoint( Text waypointName, BlockPos pos) { - CrystalsWaypoint.Category category = WAYPOINTLOCATIONS.get(waypointName.getString()); + CrystalsWaypoint.Category category = WAYPOINT_LOCATIONS.get(waypointName.getString()); CrystalsWaypoint waypoint = new CrystalsWaypoint(category, waypointName, pos); activeWaypoints.put(waypointName.getString(),waypoint); } public static void render(WorldRenderContext context) { - if (SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.enabled ) { + if (SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.enabled) { for (CrystalsWaypoint crystalsWaypoint : activeWaypoints.values()) { if (crystalsWaypoint.shouldRender()) { crystalsWaypoint.render(context); @@ -155,20 +182,22 @@ public class CrystalsLocationsManager { } } + private static void reset() { + activeWaypoints.clear(); + } + public static void update() { - if (client.player == null || client.getNetworkHandler() == null || !SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.enabled || !Utils.isInCrystals()) { - activeWaypoints = new HashMap<>(); + if (CLIENT.player == null || CLIENT.getNetworkHandler() == null || !SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.enabled || !Utils.isInCrystalHollows()) { return; } + //get if the player is in the crystals - String location = Utils.getIslandArea().replace("⏣ ",""); + String location = Utils.getIslandArea().replace("⏣ ", ""); //if new location and needs waypoint add waypoint - if (!location.equals("Unknown") && WAYPOINTLOCATIONS.containsKey(location) && !activeWaypoints.containsKey(location)){ + if (!location.equals("Unknown") && WAYPOINT_LOCATIONS.containsKey(location) && !activeWaypoints.containsKey(location)) { //add waypoint at player location - BlockPos playerLocation = client.player.getBlockPos(); - addCustomWaypoint(Text.of(location),playerLocation); + BlockPos playerLocation = CLIENT.player.getBlockPos(); + addCustomWaypoint(Text.of(location), playerLocation); } - - } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java index f9016f3a..ad85e763 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java @@ -27,7 +27,7 @@ public class CrystalsWaypoint extends Waypoint { private static final Logger LOGGER = LoggerFactory.getLogger(CrystalsWaypoint.class); private static final Supplier CONFIG = () -> SkyblockerConfigManager.get().general.waypoints; - static final Supplier TYPE_SUPPLIER = () -> CONFIG.get().waypointType; + private static final Supplier TYPE_SUPPLIER = () -> CONFIG.get().waypointType; final Category category; final Text name; private final Vec3d centerPos; @@ -52,7 +52,6 @@ public class CrystalsWaypoint extends Waypoint { return super.shouldRender() ; } - @Override public boolean equals(Object obj) { return super.equals(obj) || obj instanceof CrystalsWaypoint other && category == other.category && name.equals(other.name) && pos.equals(other.pos); @@ -78,16 +77,16 @@ public class CrystalsWaypoint extends Waypoint { * enum for the different waypoints used int the crystals hud each with a {@link Category#name} and associated {@link Category#color} */ enum Category implements StringIdentifiable { - JUNGLE_TEMPLE("Jungle Temple",Color.GREEN), - MINES_OF_DIVAN("Mines Of Divan",Color.CYAN), - GOBLIN_QUEENS_DEN("Goblin Queen's Den",Color.ORANGE), - LOST_PRECURSOR_CITY("Lost Precursor City",Color.BLUE), - KHAZADUM("Khazad-dûm",Color.RED), - FAIRY_GROTTO("Fairy Grotto",Color.PINK), - DRAGONS_LAIR("Dragon's Lair",Color.BLACK), - CORLEONE("Corleone",Color.gray), - KING("King",Color.yellow), - DEFAULT("Default",Color.BLACK); + JUNGLE_TEMPLE("Jungle Temple", Color.GREEN), + MINES_OF_DIVAN("Mines of Divan", Color.CYAN), + GOBLIN_QUEENS_DEN("Goblin Queen's Den", Color.ORANGE), + LOST_PRECURSOR_CITY("Lost Precursor City", Color.BLUE), + KHAZADUM("Khazad-dûm", Color.RED), + FAIRY_GROTTO("Fairy Grotto", Color.PINK), + DRAGONS_LAIR("Dragon's Lair", Color.BLACK), + CORLEONE("Corleone", Color.gray), + KING("King", Color.yellow), + DEFAULT("Default", Color.BLACK); public final Color color; diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java index 5c3498bc..3eef66d7 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java @@ -4,6 +4,7 @@ import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.skyblock.tabhud.util.Colors; import de.hysky.skyblocker.skyblock.tabhud.widget.hud.HudCommsWidget; import de.hysky.skyblocker.skyblock.tabhud.widget.hud.HudPowderWidget; +import de.hysky.skyblocker.utils.Utils; import de.hysky.skyblocker.utils.scheduler.Scheduler; import it.unimi.dsi.fastutil.Pair; import it.unimi.dsi.fastutil.ints.IntIntPair; @@ -15,7 +16,6 @@ import net.minecraft.client.gui.DrawContext; import net.minecraft.text.Text; import net.minecraft.util.Formatting; -import java.awt.*; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; @@ -61,7 +61,8 @@ public class DwarvenHud { || commissionList.isEmpty()) { return; } - render(HudCommsWidget.INSTANCE,HudPowderWidget.INSTANCE, context, + + render(HudCommsWidget.INSTANCE, HudPowderWidget.INSTANCE, context, SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.x, SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.y, SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.powderX, @@ -201,10 +202,12 @@ public class DwarvenHud { } public static void update() { - commissionList = new ArrayList<>(); - if (client.player == null || client.getNetworkHandler() == null || !SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions) + if (client.player == null || client.getNetworkHandler() == null || !SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions || (!Utils.isInCrystalHollows() + && !Utils.getLocationRaw().equals("mining_3"))) return; + commissionList = new ArrayList<>(); + client.getNetworkHandler().getPlayerList().forEach(playerListEntry -> { if (playerListEntry.getDisplayName() != null) { //find commissions diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java index 4214ca89..d5dc19f2 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHudConfigScreen.java @@ -37,7 +37,7 @@ public class DwarvenHudConfigScreen extends Screen { public void render(DrawContext context, int mouseX, int mouseY, float delta) { super.render(context, mouseX, mouseY, delta); renderBackground(context, mouseX, mouseY, delta); - DwarvenHud.render(HudCommsWidget.INSTANCE_CFG, HudPowderWidget.INSTANCE_CFG, context, commissionsHudX, commissionsHudY,powderHudX,powderHudY,CFG_COMMS); + DwarvenHud.render(HudCommsWidget.INSTANCE_CFG, HudPowderWidget.INSTANCE_CFG, context, commissionsHudX, commissionsHudY, powderHudX, powderHudY, CFG_COMMS); context.drawCenteredTextWithShadow(textRenderer, "Right Click To Reset Position", width / 2, height / 2, Color.GRAY.getRGB()); } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudPowderWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudPowderWidget.java index 345794d8..1d11c2a6 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudPowderWidget.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudPowderWidget.java @@ -1,14 +1,7 @@ package de.hysky.skyblocker.skyblock.tabhud.widget.hud; -import java.util.List; - -import de.hysky.skyblocker.skyblock.dwarven.DwarvenHud.Commission; -import de.hysky.skyblocker.skyblock.tabhud.util.Colors; import de.hysky.skyblocker.skyblock.tabhud.util.Ico; import de.hysky.skyblocker.skyblock.tabhud.widget.Widget; -import de.hysky.skyblocker.skyblock.tabhud.widget.component.Component; -import de.hysky.skyblocker.skyblock.tabhud.widget.component.PlainTextComponent; -import de.hysky.skyblocker.skyblock.tabhud.widget.component.ProgressComponent; import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; diff --git a/src/main/java/de/hysky/skyblocker/utils/Utils.java b/src/main/java/de/hysky/skyblocker/utils/Utils.java index a8a0d3d6..066bc19b 100644 --- a/src/main/java/de/hysky/skyblocker/utils/Utils.java +++ b/src/main/java/de/hysky/skyblocker/utils/Utils.java @@ -25,7 +25,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -37,7 +36,7 @@ public class Utils { private static final Logger LOGGER = LoggerFactory.getLogger(Utils.class); private static final String ALTERNATE_HYPIXEL_ADDRESS = System.getProperty("skyblocker.alternateHypixelAddress", ""); private static final String DUNGEONS_LOCATION = "dungeon"; - public static final String CRYSTALS_LOCATION = "crystal_hollows"; + private static final String CRYSTAL_HOLLOWS_LOCATION = "crystal_hollows"; private static final String PROFILE_PREFIX = "Profile: "; private static boolean isOnHypixel = false; @@ -88,8 +87,9 @@ public class Utils { public static boolean isInDungeons() { return getLocationRaw().equals(DUNGEONS_LOCATION) || FabricLoader.getInstance().isDevelopmentEnvironment(); } - public static boolean isInCrystals(){ - return getLocationRaw().equals(CRYSTALS_LOCATION) || FabricLoader.getInstance().isDevelopmentEnvironment(); + + public static boolean isInCrystalHollows() { + return getLocationRaw().equals(CRYSTAL_HOLLOWS_LOCATION) || FabricLoader.getInstance().isDevelopmentEnvironment(); } public static boolean isInTheRift() { diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index fd583639..936ac1fa 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -278,7 +278,7 @@ "text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.enableBackground": "Enable Background", "text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud": "Crystal Hollows Map", "text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.enabled": "Enabled", - "text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.screen": "Crystals HUD Config...", + "text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.screen": "Crystal Hollows Map Placement Config...", "text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.showLocations": "Show Waypoints", "text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.showLocations.@Tooltip": "Show boxes on important areas in the crystal hollows e.g. Jungle Temple and Fairy Grotto.", "text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.showLocations.locationSize": "Location Size", diff --git a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudTest.java b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudTest.java index 3086a3e4..d8cb806c 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudTest.java @@ -8,12 +8,12 @@ public class CrystalsHudTest { @Test void testLocationTransformation(){ - Assertions.assertEquals(CrystalsHud.transformLocation(202,202), Pair.of(0,0)); - Assertions.assertEquals(CrystalsHud.transformLocation(823,823), Pair.of(62,62)); + Assertions.assertEquals(CrystalsHud.transformLocation(202, 202), Pair.of(0, 0)); + Assertions.assertEquals(CrystalsHud.transformLocation(823, 823), Pair.of(62, 62)); - Assertions.assertEquals(CrystalsHud.transformLocation(512.5,512.5), Pair.of(31,31)); + Assertions.assertEquals(CrystalsHud.transformLocation(512.5, 512.5), Pair.of(31, 31)); - Assertions.assertEquals(CrystalsHud.transformLocation(-50,-50), Pair.of(0,0)); - Assertions.assertEquals(CrystalsHud.transformLocation(1000,1000), Pair.of(62,62)); + Assertions.assertEquals(CrystalsHud.transformLocation(-50, -50), Pair.of(0, 0)); + Assertions.assertEquals(CrystalsHud.transformLocation(1000, 1000), Pair.of(62, 62)); } } diff --git a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java index 592e5ecb..ecfc1234 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java @@ -1,10 +1,11 @@ package de.hysky.skyblocker.skyblock.dwarven; -import net.minecraft.text.Text; import net.minecraft.util.math.BlockPos; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import de.hysky.skyblocker.utils.Constants; + public class CrystalsLocationManagerTest { @Test @@ -25,7 +26,7 @@ public class CrystalsLocationManagerTest { @Test void testSetLocationMessage(){ - Assertions.assertEquals(CrystalsLocationsManager.getSetLocationMessage("Jungle Temple",new BlockPos(10,11,12)).getString(), "Added waypoint for Jungle Temple at : 10 11 12."); - Assertions.assertEquals(CrystalsLocationsManager.getSetLocationMessage("Fairy Grotto",new BlockPos(0,0,0)).getString(), "Added waypoint for Fairy Grotto at : 0 0 0."); + Assertions.assertEquals(CrystalsLocationsManager.getSetLocationMessage("Jungle Temple",new BlockPos(10,11,12)).getString(), Constants.PREFIX.get().getString() + "Added waypoint for Jungle Temple at : 10 11 12."); + Assertions.assertEquals(CrystalsLocationsManager.getSetLocationMessage("Fairy Grotto",new BlockPos(0,0,0)).getString(), Constants.PREFIX.get().getString() + "Added waypoint for Fairy Grotto at : 0 0 0."); } } -- cgit