From fb583f4d085e4b34609e24399a72701210bb682c Mon Sep 17 00:00:00 2001 From: olim Date: Tue, 30 Jan 2024 12:28:25 +0000 Subject: start of crystal hollows fetures basic implementation of a map and way-points features for the crystal hollows --- .../java/de/hysky/skyblocker/SkyblockerMod.java | 6 + .../hysky/skyblocker/config/SkyblockerConfig.java | 30 ++++ .../config/categories/DwarvenMinesCategory.java | 47 +++++- .../skyblocker/skyblock/dwarven/CrystalsHud.java | 101 ++++++++++++ .../skyblock/dwarven/CrystalsHudConfigScreen.java | 64 ++++++++ .../skyblock/dwarven/CrystalsLocationsManager.java | 171 +++++++++++++++++++++ .../skyblock/dwarven/CrystalsWaypoint.java | 149 ++++++++++++++++++ src/main/java/de/hysky/skyblocker/utils/Utils.java | 6 + 8 files changed, 573 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudConfigScreen.java create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java (limited to 'src/main/java/de') diff --git a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java index 3fca09ce..c11e4c86 100644 --- a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java +++ b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java @@ -13,6 +13,8 @@ import de.hysky.skyblocker.skyblock.dungeon.puzzle.TicTacToe; import de.hysky.skyblocker.skyblock.dungeon.puzzle.waterboard.Waterboard; import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager; import de.hysky.skyblocker.skyblock.dungeon.secrets.SecretsTracker; +import de.hysky.skyblocker.skyblock.dwarven.CrystalsHud; +import de.hysky.skyblocker.skyblock.dwarven.CrystalsLocationsManager; import de.hysky.skyblocker.skyblock.dwarven.DwarvenHud; import de.hysky.skyblocker.skyblock.end.BeaconHighlighter; import de.hysky.skyblocker.skyblock.item.*; @@ -99,6 +101,8 @@ public class SkyblockerMod implements ClientModInitializer { QuickNav.init(); ItemCooldowns.init(); DwarvenHud.init(); + CrystalsHud.init(); + CrystalsLocationsManager.init(); ChatMessageListener.init(); Shortcuts.init(); DiscordRPCManager.init(); @@ -142,6 +146,8 @@ public class SkyblockerMod implements ClientModInitializer { Scheduler.INSTANCE.scheduleCyclic(LividColor::update, 10); Scheduler.INSTANCE.scheduleCyclic(BackpackPreview::tick, 50); Scheduler.INSTANCE.scheduleCyclic(DwarvenHud::update, 40); + Scheduler.INSTANCE.scheduleCyclic(CrystalsHud::update, 40); + Scheduler.INSTANCE.scheduleCyclic(CrystalsLocationsManager::update, 40); Scheduler.INSTANCE.scheduleCyclic(PlayerListMgr::updateList, 20); } diff --git a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java index a7569adb..886f81fb 100644 --- a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java @@ -873,6 +873,12 @@ public class SkyblockerConfig { @SerialEntry public DwarvenHud dwarvenHud = new DwarvenHud(); + + @SerialEntry + public CrystalsHud crystalsHud = new CrystalsHud(); + + @SerialEntry + public CrystalsWaypoints crystalsWaypoints = new CrystalsWaypoints(); } public static class DwarvenHud { @@ -891,6 +897,30 @@ public class SkyblockerConfig { @SerialEntry public int y = 10; } + public static class CrystalsHud { + @SerialEntry + public boolean enabled = true; + + + @SerialEntry + public boolean enableBackground = true; + + @SerialEntry + public int x = 10; + + @SerialEntry + public int y = 50; + } + public static class CrystalsWaypoints { + @SerialEntry + public boolean enabled = true; + + @SerialEntry + public boolean findInChat = true; + + @SerialEntry + public Waypoint.Type waypointType = Waypoint.Type.WAYPOINT; + } public enum DwarvenHudStyle { SIMPLE, FANCY, CLASSIC; diff --git a/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java index 80d6485b..4a7e6854 100644 --- a/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java +++ b/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java @@ -2,6 +2,7 @@ package de.hysky.skyblocker.config.categories; import de.hysky.skyblocker.config.ConfigUtils; import de.hysky.skyblocker.config.SkyblockerConfig; +import de.hysky.skyblocker.skyblock.dwarven.CrystalsHudConfigScreen; import dev.isxander.yacl3.api.ButtonOption; import dev.isxander.yacl3.api.ConfigCategory; import dev.isxander.yacl3.api.Option; @@ -53,7 +54,7 @@ public class DwarvenMinesCategory { .build()) .option(Option.createBuilder() .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.style")) - .description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.style.@Tooltip[0]"), + .description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.style.@Tooltip[0]"), Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.style.@Tooltip[1]"), Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.style.@Tooltip[2]"))) .binding(defaults.locations.dwarvenMines.dwarvenHud.style, @@ -74,6 +75,50 @@ public class DwarvenMinesCategory { .controller(ConfigUtils::createBooleanController) .build()) .build()) + //crystal HUD + .group(OptionGroup.createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud")) //todo i do not know if i need to duplicate text + .collapsed(false) + .option(Option.createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.enabled")) + .binding(defaults.locations.dwarvenMines.crystalsHud.enabled, + () -> config.locations.dwarvenMines.crystalsHud.enabled, + newValue -> config.locations.dwarvenMines.crystalsHud.enabled = newValue) + .controller(ConfigUtils::createBooleanController) + .build()) + .option(ButtonOption.createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.screen")) + .text(Text.translatable("text.skyblocker.open")) + .action((screen, opt) -> MinecraftClient.getInstance().setScreen(new CrystalsHudConfigScreen(screen))) + .build()) + .option(Option.createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.enableBackground")) + .binding(defaults.locations.dwarvenMines.crystalsHud.enableBackground, + () -> config.locations.dwarvenMines.crystalsHud.enableBackground, + newValue -> config.locations.dwarvenMines.crystalsHud.enableBackground = newValue) + .controller(ConfigUtils::createBooleanController) + .build()) + .build()) + //crystals waypoints + .group(OptionGroup.createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints")) //todo i do not know if i need to duplicate text + .collapsed(false) + .option(Option.createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.enabled")) + .binding(defaults.locations.dwarvenMines.crystalsWaypoints.enabled, + () -> config.locations.dwarvenMines.crystalsWaypoints.enabled, + newValue -> config.locations.dwarvenMines.crystalsWaypoints.enabled = newValue) + .controller(ConfigUtils::createBooleanController) + .build()) + .option(Option.createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.findInChat")) + .binding(defaults.locations.dwarvenMines.crystalsWaypoints.findInChat, + () -> config.locations.dwarvenMines.crystalsWaypoints.findInChat, + newValue -> config.locations.dwarvenMines.crystalsWaypoints.findInChat = newValue) + .controller(ConfigUtils::createBooleanController) + .build()) + + .build()) .build(); } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java new file mode 100644 index 00000000..7ec9cefa --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java @@ -0,0 +1,101 @@ +package de.hysky.skyblocker.skyblock.dwarven; + +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 it.unimi.dsi.fastutil.ints.IntIntPair; +import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; +import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; +import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.texture.atlas.Sprite; +import net.minecraft.util.Identifier; +import org.apache.commons.math3.analysis.UnivariateMatrixFunction; + +import java.awt.*; +import java.util.Arrays; + +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"); //todo is this the right place to store file + + private static final Identifier MAP_ICON = new Identifier("textures/map/map_icons.png"); + + public static boolean visable = false; + + + + + public static void init() { + ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(ClientCommandManager.literal("skyblocker") + .then(ClientCommandManager.literal("hud") + .then(ClientCommandManager.literal("crystals") + .executes(Scheduler.queueOpenScreenCommand(CrystalsHudConfigScreen::new)))))); + + HudRenderCallback.EVENT.register((context, tickDelta) -> { + if (!SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.enabled + || client.options.playerListKey.isPressed() + || client.player == null + || !visable) { + return; + } + render(context, SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.x, + SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.y); + }); + } + + public static IntIntPair getDimForConfig() { + return IntIntPair.of(62, 62); + } + + public static void render( DrawContext context, int hudX, int hudY) { + + if (SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.enableBackground) { + context.fill(hudX, hudY, hudX + 62, hudY + 62, 0x64000000); + } + + + //draw map texture + context. + drawTexture(MAP_TEXTURE,hudX,hudY,0,0,62,62,62,62); + //draw player on map + 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(); + //map location to map + int renderX = (int)((playerX-202)/621 * 62); + int renderY = (int)((playerZ -202)/621 * 62); + int renderAngle = (int)(facing %360); + if (renderAngle < 0){//make sure the angle is always correct between 0 and 360 + renderAngle = 360 + renderAngle; + } + //clamp location to map + renderX = Math.max(0, Math.min(62, renderX)); + renderY = Math.max(0, Math.min(62, renderY)); + //draw marker on map + context. + drawTexture(MAP_ICON,hudX+renderX,hudY+renderY,2,0,5,7,128,128); + + //todo add direction and scale (could be wrong drawing methods) and offset to center on player + + } + + public static void update() { + if (client.player == null || client.getNetworkHandler() == null || !SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.enabled) { + visable = false; + return; + } + //get if the player is in the crystals + visable = Utils.isInCrystals(); + + + } + +} diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudConfigScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudConfigScreen.java new file mode 100644 index 00000000..18be8bed --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudConfigScreen.java @@ -0,0 +1,64 @@ +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; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.text.Text; + +import java.awt.*; + +public class CrystalsHudConfigScreen extends Screen { + + private int hudX = SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.x; + private int hudY = SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.y; + private final Screen parent; + + protected CrystalsHudConfigScreen() { + this(null); + } + + public CrystalsHudConfigScreen(Screen parent) { + super(Text.of("Crystals HUD Config")); + this.parent = parent; + } + + @Override + public void render(DrawContext context, int mouseX, int mouseY, float delta) { + super.render(context, mouseX, mouseY, delta); + renderBackground(context, mouseX, mouseY, delta); + CrystalsHud.render( context, hudX, hudY); + 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 = CrystalsHud.getDimForConfig(); + 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); + } + return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (button == 1) { + IntIntPair dims = CrystalsHud.getDimForConfig(); + hudX = this.width / 2 - dims.leftInt(); + hudY = this.height / 2 - dims.rightInt(); + } + return super.mouseClicked(mouseX, mouseY, button); + } + + @Override + public void close() { + SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.x = hudX; + SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.y = hudY; + SkyblockerConfigManager.save(); + + client.setScreen(parent); + } +} diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java new file mode 100644 index 00000000..d9f31f1d --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -0,0 +1,171 @@ +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; +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; +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.math.BlockPos; + +import java.time.Instant; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +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(); + public static Map ActiveWaypoints= new HashMap<>() {}; + + 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, + "Khazad-dûm", CrystalsWaypoint.Category.KHAZADUM, + "Fairy Grotto", CrystalsWaypoint.Category.FAIRYGROTTO, + "Dragon's Lair", CrystalsWaypoint.Category.DRAGONSLAIR + ); + 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])"); + + + public static void init() { + ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(ClientCommandManager.literal("skyblocker") + .then(ClientCommandManager.literal("hud") + .then(ClientCommandManager.literal("crystals") + .executes(Scheduler.queueOpenScreenCommand(CrystalsHudConfigScreen::new)))))); + + WorldRenderEvents.AFTER_TRANSLUCENT.register(CrystalsLocationsManager::render); + ClientReceiveMessageEvents.CHAT.register(CrystalsLocationsManager::extractLocationFromMessage); + ClientCommandRegistrationCallback.EVENT.register(CrystalsLocationsManager::registerWaypointLocationCommands); + } + private static void extractLocationFromMessage(Text message, SignedMessage signedMessage, GameProfile sender, MessageType.Parameters params, Instant receptionTimestamp){ + if (!SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.findInChat ) { //todo || !Utils.isInCrystals() + return; + } + //get the message text + String value = signedMessage.getContent().getString(); + Matcher matcher = TEXT_CWORDS_PATTERN.matcher(value); + //if there are cwords in the message try to get them and what they are talking about + if (matcher.find()){ + String location = matcher.group(); + Integer[] cowordinates = Arrays.stream(location.split(" ",3)).map(Integer::parseInt).toArray(Integer[]::new); + BlockPos blockPos = new BlockPos(cowordinates[0],cowordinates[1],cowordinates[2]); + //todo make sure this is in bounds of crystals + //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); + 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); + } + + + } + private static void registerWaypointLocationCommands(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { + dispatcher.register(literal(SkyblockerMod.NAMESPACE) + .then(literal("crystalWaypoints") + .then(argument("pos", BlockPosArgumentType.blockPos()) + .then(argument("place", StringArgumentType.greedyString()) + .executes(context -> addWaypointFromCommand(context.getSource(), getString(context, "place"),context.getArgument("pos", PosArgument.class))) + ) + ) + ) + ); + } + private static Text getSetLocationMessage(String location,BlockPos blockPos) { + MutableText text = Text.empty(); + text.append(Text.literal("Added waypoint for "+location+" at :"+blockPos.getX()+" "+blockPos.getY()+" "+blockPos.getZ()+".")); //todo add colours + + return text; + } + private static Text getLocationInputText(String location) { + MutableText text = Text.empty(); + for (String waypointLocation : WAYPOINTLOCATIONS.keySet()){ + //todo add colour codes + text.append(Text.literal("["+waypointLocation+"]").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)){ + addCustomWaypoint(Text.of(place), blockPos); + //todo send to map + //tell the client it has done this + if (client.player == null || client.getNetworkHandler() == null ) { + return Command.SINGLE_SUCCESS; + } + 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 waypoint = new CrystalsWaypoint(category, waypointName, pos); + ActiveWaypoints.put(waypointName.getString(),waypoint); + } + public static void render(WorldRenderContext context) { + if (SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.enabled ) { + for (CrystalsWaypoint crystalsWaypoint : ActiveWaypoints.values()) { + if (crystalsWaypoint.shouldRender()) { + crystalsWaypoint.render(context); + } + } + } + } + + public static void update() { + if (client.player == null || client.getNetworkHandler() == null || !SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.enabled) { + 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 + if (!location.equals("Unknown") && WAYPOINTLOCATIONS.containsKey(location) && !ActiveWaypoints.containsKey(location)){ + //add waypoint at player location + BlockPos playerLocation = client.player.getBlockPos(); + addCustomWaypoint(Text.of(location),playerLocation); + //todo send to map gui + } + + + } +} diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java new file mode 100644 index 00000000..9c6db04f --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java @@ -0,0 +1,149 @@ +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; +import net.minecraft.util.math.Vec3d; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.function.ToDoubleFunction; + +public class CrystalsWaypoint extends Waypoint { + private static final Logger LOGGER = LoggerFactory.getLogger(CrystalsWaypoint.class); + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Category.CODEC.fieldOf("category").forGetter(crystalsWaypoint -> crystalsWaypoint.category), + TextCodecs.CODEC.fieldOf("name").forGetter(crystalsWaypoint -> crystalsWaypoint.name), + BlockPos.CODEC.fieldOf("pos").forGetter(crystalsWaypoint -> crystalsWaypoint.pos) + ).apply(instance, CrystalsWaypoint::new)); + public static final Codec> LIST_CODEC = CODEC.listOf(); + static final List SECRET_ITEMS = List.of("Decoy", "Defuse Kit", "Dungeon Chest Key", "Healing VIII", "Inflatable Jerry", "Spirit Leap", "Training Weights", "Trap", "Treasure Talisman"); + private static final Supplier CONFIG = () -> SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints; + static final Supplier TYPE_SUPPLIER = () -> CONFIG.get().waypointType; + final Category category; + final Text name; + private final Vec3d centerPos; + + CrystalsWaypoint( JsonObject waypoint, String name, BlockPos pos) { + this(Category.get(waypoint), name, pos); + } + + CrystalsWaypoint(Category category, String name, BlockPos pos) { + this( category, Text.of(name), pos); + } + + CrystalsWaypoint( Category category, Text name, BlockPos pos) { + super(pos, TYPE_SUPPLIER, category.colorComponents); + this.category = category; + this.name = name; + this.centerPos = pos.toCenterPos(); + } + + static ToDoubleFunction getSquaredDistanceToFunction(Entity entity) { + return crystalsWaypoint -> entity.squaredDistanceTo(crystalsWaypoint.centerPos); + } + + static Predicate getRangePredicate(Entity entity) { + return crystalsWaypoint -> entity.squaredDistanceTo(crystalsWaypoint.centerPos) <= 36D; + } + + @Override + public boolean shouldRender() { + 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); + } + + /** + * Renders the secret waypoint, including a waypoint through {@link Waypoint#render(WorldRenderContext)}, the name, and the distance from the player. + */ + @Override + public void render(WorldRenderContext context) { + //TODO In the future, shrink the box for wither essence and items so its more realistic + super.render(context); + + + Vec3d posUp = centerPos.add(0, 1, 0); + RenderHelper.renderText(context, name, posUp, true); + double distance = context.camera().getPos().distanceTo(centerPos); + RenderHelper.renderText(context, Text.literal(Math.round(distance) + "m").formatted(Formatting.YELLOW), posUp, 1, MinecraftClient.getInstance().textRenderer.fontHeight + 1, true); + + } + + + + enum Category implements StringIdentifiable { //todo set better colours and remove extra data + JUNGLETEMPLE("Jungle Temple", 0, 255, 0), + MINESOFDIVAN("Mines Of Divan", 255, 0, 0), + GOBLINQUEENSDEN("Goblin Queen's Den", 2, 213, 250), + LOSTPRECURSORCITY("Lost Precursor City", 2, 64, 250), + KHAZADUM("Khazad-dûm", 142, 66, 0), + FAIRYGROTTO("Fairy Grotto", 30, 30, 30), + DRAGONSLAIR("Dragon's Lair", 250, 217, 2), + DEFAULT("default", 190, 255, 252); + + private static final Codec CODEC = StringIdentifiable.createCodec(Category::values); + private final String name; + + private final float[] colorComponents; + + Category(String name, int... intColorComponents) { + this.name = name; + + colorComponents = new float[intColorComponents.length]; + for (int i = 0; i < intColorComponents.length; i++) { + colorComponents[i] = intColorComponents[i] / 255F; + } + } + + static Category get(JsonObject waypointJson) { + return CODEC.parse(JsonOps.INSTANCE, waypointJson.get("category")).resultOrPartial(LOGGER::error).orElse(Category.DEFAULT); + } + + @Override + public String toString() { + return name; + } + + @Override + public String asString() { + return name; + } + + static class CategoryArgumentType extends EnumArgumentType { + CategoryArgumentType() { + super(Category.CODEC, Category::values); + } + + static CategoryArgumentType category() { + return new CategoryArgumentType(); + } + + static Category getCategory(CommandContext context, String name) { + return context.getArgument(name, Category.class); + } + } + } +} diff --git a/src/main/java/de/hysky/skyblocker/utils/Utils.java b/src/main/java/de/hysky/skyblocker/utils/Utils.java index 3f07622c..a8a0d3d6 100644 --- a/src/main/java/de/hysky/skyblocker/utils/Utils.java +++ b/src/main/java/de/hysky/skyblocker/utils/Utils.java @@ -25,6 +25,7 @@ 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; @@ -36,6 +37,8 @@ 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 PROFILE_PREFIX = "Profile: "; private static boolean isOnHypixel = false; private static boolean isOnSkyblock = false; @@ -85,6 +88,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 isInTheRift() { return getLocationRaw().equals(TheRift.LOCATION); -- cgit From 4725a42df06d8bf72bc6a901bd24dda25d761623 Mon Sep 17 00:00:00 2001 From: olim Date: Tue, 30 Jan 2024 14:43:42 +0000 Subject: location colors and on map made it so that locations in the crystal hollows can be shown on them map as well as way points. and also add colors for the way points and map. --- .../hysky/skyblocker/config/SkyblockerConfig.java | 11 +++++-- .../config/categories/DwarvenMinesCategory.java | 7 ++++ .../skyblocker/skyblock/dwarven/CrystalsHud.java | 35 +++++++++++++------- .../skyblock/dwarven/CrystalsLocationsManager.java | 29 +++++++++-------- .../skyblock/dwarven/CrystalsWaypoint.java | 37 ++++++++++++---------- .../resources/assets/skyblocker/lang/en_us.json | 1 + 6 files changed, 76 insertions(+), 44 deletions(-) (limited to 'src/main/java/de') diff --git a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java index 886f81fb..6f7db908 100644 --- a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java @@ -1,6 +1,7 @@ package de.hysky.skyblocker.config; import de.hysky.skyblocker.SkyblockerMod; +import de.hysky.skyblocker.skyblock.dwarven.CrystalsWaypoint; import de.hysky.skyblocker.skyblock.item.CustomArmorTrims; import de.hysky.skyblocker.utils.chat.ChatFilterResult; import de.hysky.skyblocker.utils.waypoint.Waypoint; @@ -14,7 +15,9 @@ import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class SkyblockerConfig { @SerialEntry @@ -901,10 +904,12 @@ public class SkyblockerConfig { @SerialEntry public boolean enabled = true; - @SerialEntry public boolean enableBackground = true; + @SerialEntry + public boolean showLocations = true; + @SerialEntry public int x = 10; @@ -917,9 +922,11 @@ public class SkyblockerConfig { @SerialEntry public boolean findInChat = true; + @SerialEntry + public Map ActiveWaypoints = new HashMap<>() {}; @SerialEntry - public Waypoint.Type waypointType = Waypoint.Type.WAYPOINT; + public Waypoint.Type waypointType = Waypoint.Type.WAYPOINT; //todo see if best option / give player a choice } public enum DwarvenHudStyle { diff --git a/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java index 4a7e6854..7581af4f 100644 --- a/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java +++ b/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java @@ -98,6 +98,13 @@ public class DwarvenMinesCategory { newValue -> config.locations.dwarvenMines.crystalsHud.enableBackground = newValue) .controller(ConfigUtils::createBooleanController) .build()) + .option(Option.createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.showLocations")) + .binding(defaults.locations.dwarvenMines.crystalsHud.showLocations, + () -> config.locations.dwarvenMines.crystalsHud.showLocations, + newValue -> config.locations.dwarvenMines.crystalsHud.showLocations = newValue) + .controller(ConfigUtils::createBooleanController) + .build()) .build()) //crystals waypoints .group(OptionGroup.createBuilder() 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 7ec9cefa..f9eaa65f 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java @@ -4,6 +4,7 @@ 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 it.unimi.dsi.fastutil.Pair; import it.unimi.dsi.fastutil.ints.IntIntPair; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; @@ -16,6 +17,7 @@ import org.apache.commons.math3.analysis.UnivariateMatrixFunction; import java.awt.*; import java.util.Arrays; +import java.util.Map; public class CrystalsHud { public static final MinecraftClient client = MinecraftClient.getInstance(); @@ -26,6 +28,7 @@ public class CrystalsHud { public static boolean visable = false; + public static final int LOCATION_SIZE = 10; //todo possible config option @@ -61,6 +64,16 @@ public class CrystalsHud { //draw map texture 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){ + Map ActiveWaypoints= SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.ActiveWaypoints; + for (CrystalsWaypoint waypoint : ActiveWaypoints.values()){ + Color waypointColor = waypoint.category.color; + Pair renderPos = transformLocation(waypoint.pos.getX(),waypoint.pos.getZ()); + //fill square of size LOCATION_SIZE around the coordinates of the location + context.fill(hudX+renderPos.first()-LOCATION_SIZE/2,hudY+renderPos.second()-LOCATION_SIZE/2,hudX+renderPos.first()+LOCATION_SIZE/2,hudY+renderPos.second()+LOCATION_SIZE/2,waypointColor.getRGB()); + } + } //draw player on map if (client.player == null || client.getNetworkHandler() == null) { return; @@ -69,23 +82,23 @@ public class CrystalsHud { double playerX = client.player.getX(); double playerZ = client.player.getZ(); double facing = client.player.getYaw(); - //map location to map - int renderX = (int)((playerX-202)/621 * 62); - int renderY = (int)((playerZ -202)/621 * 62); - int renderAngle = (int)(facing %360); - if (renderAngle < 0){//make sure the angle is always correct between 0 and 360 - renderAngle = 360 + renderAngle; - } - //clamp location to map - renderX = Math.max(0, Math.min(62, renderX)); - renderY = Math.max(0, Math.min(62, renderY)); + Pair renderPos = transformLocation(playerX,playerZ); //draw marker on map context. - drawTexture(MAP_ICON,hudX+renderX,hudY+renderY,2,0,5,7,128,128); + drawTexture(MAP_ICON,hudX+renderPos.first(),hudY+renderPos.second(),2,0,5,7,128,128); //todo add direction and scale (could be wrong drawing methods) and offset to center on player } + private 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 = Math.max(0, Math.min(62, transformedX)); + transformedY = Math.max(0, Math.min(62, transformedY)); + + return Pair.of(transformedX,transformedY); + } public static void update() { if (client.player == null || client.getNetworkHandler() == null || !SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.enabled) { 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 d9f31f1d..e5f7d473 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -27,6 +27,7 @@ import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.math.BlockPos; +import java.awt.*; import java.time.Instant; import java.util.Arrays; import java.util.HashMap; @@ -40,7 +41,7 @@ import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.lit public class CrystalsLocationsManager { public static final MinecraftClient client = MinecraftClient.getInstance(); - public static Map ActiveWaypoints= new HashMap<>() {}; + public static final Map WAYPOINTLOCATIONS = Map.of( "Jungle Temple", CrystalsWaypoint.Category.JUNGLETEMPLE, @@ -51,15 +52,11 @@ public class CrystalsLocationsManager { "Fairy Grotto", CrystalsWaypoint.Category.FAIRYGROTTO, "Dragon's Lair", CrystalsWaypoint.Category.DRAGONSLAIR ); + 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])"); public static void init() { - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(ClientCommandManager.literal("skyblocker") - .then(ClientCommandManager.literal("hud") - .then(ClientCommandManager.literal("crystals") - .executes(Scheduler.queueOpenScreenCommand(CrystalsHudConfigScreen::new)))))); - WorldRenderEvents.AFTER_TRANSLUCENT.register(CrystalsLocationsManager::render); ClientReceiveMessageEvents.CHAT.register(CrystalsLocationsManager::extractLocationFromMessage); ClientCommandRegistrationCallback.EVENT.register(CrystalsLocationsManager::registerWaypointLocationCommands); @@ -107,15 +104,17 @@ public class CrystalsLocationsManager { } private static Text getSetLocationMessage(String location,BlockPos blockPos) { MutableText text = Text.empty(); - text.append(Text.literal("Added waypoint for "+location+" at :"+blockPos.getX()+" "+blockPos.getY()+" "+blockPos.getZ()+".")); //todo add colours - + text.append(Text.literal("Added waypoint for ")); + Color locationColor = WAYPOINTLOCATIONS.get(location).color; + text.append(Text.literal(location).withColor(locationColor.getRGB())); + 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()){ - //todo add colour codes - text.append(Text.literal("["+waypointLocation+"]").styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/skyblocker crystalWaypoints "+location+" "+waypointLocation)))); + 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)))); } return text; @@ -125,10 +124,9 @@ public class CrystalsLocationsManager { BlockPos blockPos = location.toAbsoluteBlockPos(new ServerCommandSource(null, source.getPosition(), source.getRotation(), null, 0, null, null, null, null)); if (WAYPOINTLOCATIONS.containsKey(place)){ addCustomWaypoint(Text.of(place), blockPos); - //todo send to map //tell the client it has done this if (client.player == null || client.getNetworkHandler() == null ) { - return Command.SINGLE_SUCCESS; + return 0; } client.player.sendMessage(getSetLocationMessage(place, blockPos), false); } @@ -139,10 +137,13 @@ 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); @@ -153,17 +154,17 @@ public class CrystalsLocationsManager { public static void update() { if (client.player == null || client.getNetworkHandler() == null || !SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.enabled) { - ActiveWaypoints= new HashMap<>(); + 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(); addCustomWaypoint(Text.of(location),playerLocation); - //todo send to map gui } 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 9c6db04f..551821ca 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java @@ -22,7 +22,9 @@ import net.minecraft.util.math.Vec3d; 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; @@ -34,8 +36,9 @@ public class CrystalsWaypoint extends Waypoint { TextCodecs.CODEC.fieldOf("name").forGetter(crystalsWaypoint -> crystalsWaypoint.name), BlockPos.CODEC.fieldOf("pos").forGetter(crystalsWaypoint -> crystalsWaypoint.pos) ).apply(instance, CrystalsWaypoint::new)); - public static final Codec> LIST_CODEC = CODEC.listOf(); - static final List SECRET_ITEMS = List.of("Decoy", "Defuse Kit", "Dungeon Chest Key", "Healing VIII", "Inflatable Jerry", "Spirit Leap", "Training Weights", "Trap", "Treasure Talisman"); + + + private static final Supplier CONFIG = () -> SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints; static final Supplier TYPE_SUPPLIER = () -> CONFIG.get().waypointType; final Category category; @@ -81,7 +84,6 @@ public class CrystalsWaypoint extends Waypoint { */ @Override public void render(WorldRenderContext context) { - //TODO In the future, shrink the box for wither essence and items so its more realistic super.render(context); @@ -94,28 +96,29 @@ public class CrystalsWaypoint extends Waypoint { - enum Category implements StringIdentifiable { //todo set better colours and remove extra data - JUNGLETEMPLE("Jungle Temple", 0, 255, 0), - MINESOFDIVAN("Mines Of Divan", 255, 0, 0), - GOBLINQUEENSDEN("Goblin Queen's Den", 2, 213, 250), - LOSTPRECURSORCITY("Lost Precursor City", 2, 64, 250), - KHAZADUM("Khazad-dûm", 142, 66, 0), - FAIRYGROTTO("Fairy Grotto", 30, 30, 30), - DRAGONSLAIR("Dragon's Lair", 250, 217, 2), - DEFAULT("default", 190, 255, 252); + 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), + KHAZADUM("Khazad-dûm",Color.RED), + FAIRYGROTTO("Fairy Grotto",Color.PINK), + DRAGONSLAIR("Dragon's Lair",Color.BLACK), + DEFAULT("Default",Color.BLACK); + + public final Color color; private static final Codec CODEC = StringIdentifiable.createCodec(Category::values); private final String name; private final float[] colorComponents; - Category(String name, int... intColorComponents) { + Category(String name,Color color) { this.name = name; + this.color = color; + colorComponents = color.getColorComponents(null); + - colorComponents = new float[intColorComponents.length]; - for (int i = 0; i < intColorComponents.length; i++) { - colorComponents[i] = intColorComponents[i] / 255F; - } } static Category get(JsonObject waypointJson) { diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 903d702e..0a6ae442 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -276,6 +276,7 @@ "text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.screen": "Dwarven HUD Config...", "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.showLocations": "Show Waypoints", "text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints": "Crystal Hollows Waypoints", "text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.findInChat": "Find Waypoints In Chat", -- cgit From 622b29b2f855f66ec47974d23f4931d81dffb5e9 Mon Sep 17 00:00:00 2001 From: olim Date: Tue, 30 Jan 2024 14:52:55 +0000 Subject: Update CrystalsLocationsManager.java makes sure the coordinates from a chat message are in the bound of crystal hollows map. and re add check that the user is in the crystal hollow to get coordinates --- .../skyblock/dwarven/CrystalsLocationsManager.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/main/java/de') 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 e5f7d473..3484bafd 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -62,7 +62,7 @@ public class CrystalsLocationsManager { ClientCommandRegistrationCallback.EVENT.register(CrystalsLocationsManager::registerWaypointLocationCommands); } private static void extractLocationFromMessage(Text message, SignedMessage signedMessage, GameProfile sender, MessageType.Parameters params, Instant receptionTimestamp){ - if (!SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.findInChat ) { //todo || !Utils.isInCrystals() + if (!SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.findInChat || !Utils.isInCrystals()) { return; } //get the message text @@ -73,7 +73,10 @@ public class CrystalsLocationsManager { String location = matcher.group(); Integer[] cowordinates = Arrays.stream(location.split(" ",3)).map(Integer::parseInt).toArray(Integer[]::new); BlockPos blockPos = new BlockPos(cowordinates[0],cowordinates[1],cowordinates[2]); - //todo make sure this is in bounds of crystals + //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 @@ -90,6 +93,12 @@ public class CrystalsLocationsManager { } + } + private static Boolean checkInCrystals(BlockPos pos){ + //checks if a location is inside crystal hollows bounds + 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) -- cgit From 51b7043abab1d91beb4f0dabec6b9ffe8ca7b1bf Mon Sep 17 00:00:00 2001 From: olim Date: Tue, 30 Jan 2024 16:11:11 +0000 Subject: add Corleone and map icon changes changed map icon so it smaller centred on player and dose not look like it can rotate as that is non functional. and added Corleone to locations --- src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java | 4 ++-- .../hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java | 5 +++-- .../java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src/main/java/de') 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 f9eaa65f..6a9ac743 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java @@ -85,9 +85,9 @@ public class CrystalsHud { Pair renderPos = transformLocation(playerX,playerZ); //draw marker on map context. - drawTexture(MAP_ICON,hudX+renderPos.first(),hudY+renderPos.second(),2,0,5,7,128,128); + drawTexture(MAP_ICON,hudX+renderPos.first()-2,hudY+renderPos.second()-2,58,2,4,4,128,128); - //todo add direction and scale (could be wrong drawing methods) and offset to center on player + //todo add direction and scale (can not work out how to rotate) } private static Pair transformLocation(double x, double z){ 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 3484bafd..743d4ef5 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -50,7 +50,8 @@ public class CrystalsLocationsManager { "Lost Precursor City", CrystalsWaypoint.Category.LOSTPRECURSORCITY, "Khazad-dûm", CrystalsWaypoint.Category.KHAZADUM, "Fairy Grotto", CrystalsWaypoint.Category.FAIRYGROTTO, - "Dragon's Lair", CrystalsWaypoint.Category.DRAGONSLAIR + "Dragon's Lair", CrystalsWaypoint.Category.DRAGONSLAIR, + "Corleone", CrystalsWaypoint.Category.DRAGONSLAIR ); 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])"); @@ -62,7 +63,7 @@ public class CrystalsLocationsManager { ClientCommandRegistrationCallback.EVENT.register(CrystalsLocationsManager::registerWaypointLocationCommands); } private static void extractLocationFromMessage(Text message, SignedMessage signedMessage, GameProfile sender, MessageType.Parameters params, Instant receptionTimestamp){ - if (!SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.findInChat || !Utils.isInCrystals()) { + if (!SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.findInChat || !Utils.isInCrystals()) { return; } //get the message text 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 551821ca..c33251d7 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java @@ -104,6 +104,7 @@ public class CrystalsWaypoint extends Waypoint { KHAZADUM("Khazad-dûm",Color.RED), FAIRYGROTTO("Fairy Grotto",Color.PINK), DRAGONSLAIR("Dragon's Lair",Color.BLACK), + CORLEONE("Corleone",Color.ORANGE), DEFAULT("Default",Color.BLACK); -- cgit From bc5cf9a37e4241096bd5ec1b2491ad71281593ff Mon Sep 17 00:00:00 2001 From: olim Date: Tue, 30 Jan 2024 19:30:10 +0000 Subject: fixed cwords from chat fixed not being able to get coordinates from chat by using the correct ClientReceiveMessageEvent of GAME instead of CHAT --- .../config/categories/DwarvenMinesCategory.java | 15 ++++----------- .../skyblock/dwarven/CrystalsLocationsManager.java | 14 +++++++------- 2 files changed, 11 insertions(+), 18 deletions(-) (limited to 'src/main/java/de') diff --git a/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java index 7581af4f..c575616a 100644 --- a/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java +++ b/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java @@ -46,10 +46,10 @@ public class DwarvenMinesCategory { .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud")) .collapsed(false) .option(Option.createBuilder() - .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.enabled")) - .binding(defaults.locations.dwarvenMines.dwarvenHud.enabled, - () -> config.locations.dwarvenMines.dwarvenHud.enabled, - newValue -> config.locations.dwarvenMines.dwarvenHud.enabled = newValue) + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.enabled"))//todo seperate coms and powder + .binding(defaults.locations.dwarvenMines.dwarvenHud.enabledCommissions, + () -> config.locations.dwarvenMines.dwarvenHud.enabledCommissions, + newValue -> config.locations.dwarvenMines.dwarvenHud.enabledCommissions = newValue) .controller(ConfigUtils::createBooleanController) .build()) .option(Option.createBuilder() @@ -91,13 +91,6 @@ public class DwarvenMinesCategory { .text(Text.translatable("text.skyblocker.open")) .action((screen, opt) -> MinecraftClient.getInstance().setScreen(new CrystalsHudConfigScreen(screen))) .build()) - .option(Option.createBuilder() - .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.enableBackground")) - .binding(defaults.locations.dwarvenMines.crystalsHud.enableBackground, - () -> config.locations.dwarvenMines.crystalsHud.enableBackground, - newValue -> config.locations.dwarvenMines.crystalsHud.enableBackground = newValue) - .controller(ConfigUtils::createBooleanController) - .build()) .option(Option.createBuilder() .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.showLocations")) .binding(defaults.locations.dwarvenMines.crystalsHud.showLocations, 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 743d4ef5..4ca38a04 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -59,21 +59,21 @@ public class CrystalsLocationsManager { public static void init() { WorldRenderEvents.AFTER_TRANSLUCENT.register(CrystalsLocationsManager::render); - ClientReceiveMessageEvents.CHAT.register(CrystalsLocationsManager::extractLocationFromMessage); + ClientReceiveMessageEvents.GAME.register(CrystalsLocationsManager::extractLocationFromMessage); ClientCommandRegistrationCallback.EVENT.register(CrystalsLocationsManager::registerWaypointLocationCommands); } - private static void extractLocationFromMessage(Text message, SignedMessage signedMessage, GameProfile sender, MessageType.Parameters params, Instant receptionTimestamp){ + private static void extractLocationFromMessage(Text message, Boolean overlay){ if (!SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.findInChat || !Utils.isInCrystals()) { return; } //get the message text - String value = signedMessage.getContent().getString(); + String value = message.getString(); Matcher matcher = TEXT_CWORDS_PATTERN.matcher(value); - //if there are cwords in the message try to get them and what they are talking about + //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[] cowordinates = Arrays.stream(location.split(" ",3)).map(Integer::parseInt).toArray(Integer[]::new); - BlockPos blockPos = new BlockPos(cowordinates[0],cowordinates[1],cowordinates[2]); + 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; @@ -164,7 +164,7 @@ public class CrystalsLocationsManager { public static void update() { if (client.player == null || client.getNetworkHandler() == null || !SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.enabled) { - SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.ActiveWaypoints= new HashMap<>(); + SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.ActiveWaypoints= new HashMap<>(); //todo dose not seem to be working return; } //get if the player is in the crystals -- cgit 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 --- .../hysky/skyblocker/config/SkyblockerConfig.java | 20 ++- .../config/categories/DwarvenMinesCategory.java | 9 +- .../skyblocker/skyblock/dwarven/DwarvenHud.java | 151 ++++++++++++++------- .../skyblock/dwarven/DwarvenHudConfigScreen.java | 38 ++++-- .../tabhud/widget/hud/HudPowderWidget.java | 47 +++++++ .../resources/assets/skyblocker/lang/en_us.json | 3 +- 6 files changed, 201 insertions(+), 67 deletions(-) create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudPowderWidget.java (limited to 'src/main/java/de') diff --git a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java index 6f7db908..e84d2d85 100644 --- a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java @@ -886,7 +886,10 @@ public class SkyblockerConfig { public static class DwarvenHud { @SerialEntry - public boolean enabled = true; + public boolean enabledCommissions = true; + + @SerialEntry + public boolean enabledPowder = true; @SerialEntry public DwarvenHudStyle style = DwarvenHudStyle.SIMPLE; @@ -895,18 +898,21 @@ public class SkyblockerConfig { public boolean enableBackground = true; @SerialEntry - public int x = 10; + public int commissionsX = 10; @SerialEntry - public int y = 10; + public int commissionsY = 10; + + @SerialEntry + public int powderX = 10; + + @SerialEntry + public int powderY = 70; } public static class CrystalsHud { @SerialEntry public boolean enabled = true; - @SerialEntry - public boolean enableBackground = true; - @SerialEntry public boolean showLocations = true; @@ -914,7 +920,7 @@ public class SkyblockerConfig { public int x = 10; @SerialEntry - public int y = 50; + public int y = 130; } public static class CrystalsWaypoints { @SerialEntry diff --git a/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java index c575616a..4bacc2b6 100644 --- a/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java +++ b/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java @@ -46,12 +46,19 @@ public class DwarvenMinesCategory { .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud")) .collapsed(false) .option(Option.createBuilder() - .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.enabled"))//todo seperate coms and powder + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.enabledCommissions")) .binding(defaults.locations.dwarvenMines.dwarvenHud.enabledCommissions, () -> config.locations.dwarvenMines.dwarvenHud.enabledCommissions, newValue -> config.locations.dwarvenMines.dwarvenHud.enabledCommissions = newValue) .controller(ConfigUtils::createBooleanController) .build()) + .option(Option.createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.enabledPowder")) + .binding(defaults.locations.dwarvenMines.dwarvenHud.enabledPowder, + () -> config.locations.dwarvenMines.dwarvenHud.enabledPowder, + newValue -> config.locations.dwarvenMines.dwarvenHud.enabledPowder = newValue) + .controller(ConfigUtils::createBooleanController) + .build()) .option(Option.createBuilder() .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.style")) .description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.style.@Tooltip[0]"), 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 6fa03816..e7ffe362 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java @@ -3,7 +3,9 @@ package de.hysky.skyblocker.skyblock.dwarven; 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.scheduler.Scheduler; +import it.unimi.dsi.fastutil.Pair; import it.unimi.dsi.fastutil.ints.IntIntPair; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; @@ -25,6 +27,9 @@ 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 final List COMMISSIONS = Stream.of( "(?:Titanium|Mithril|Hard Stone) Miner", "(?:Ice Walker|Golden Goblin|(? { - if (!SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabled + if ((!SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions && !SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledPowder) || client.options.playerListKey.isPressed() || client.player == null || commissionList.isEmpty()) { return; } - render(HudCommsWidget.INSTANCE, context, SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.x, - SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.y, commissionList); + render(HudCommsWidget.INSTANCE,HudPowderWidget.INSTANCE, context, + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.commissionsX, + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.commissionsY, + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.powderX, + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.powderY, + commissionList,mithrilPowder,gemStonePowder); }); } - public static IntIntPair getDimForConfig(List commissions) { + public static Pair getDimForConfig(List commissions) { //todo add powder return switch (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.style) { case SIMPLE -> { HudCommsWidget.INSTANCE_CFG.updateData(commissions, false); - yield IntIntPair.of( - HudCommsWidget.INSTANCE_CFG.getWidth(), - HudCommsWidget.INSTANCE_CFG.getHeight()); + yield Pair.of( + IntIntPair.of( + HudCommsWidget.INSTANCE_CFG.getWidth(), + HudCommsWidget.INSTANCE_CFG.getHeight()), + IntIntPair.of( + HudPowderWidget.INSTANCE_CFG.getWidth(), + HudPowderWidget.INSTANCE_CFG.getHeight()) + ); } case FANCY -> { HudCommsWidget.INSTANCE_CFG.updateData(commissions, true); - yield IntIntPair.of( - HudCommsWidget.INSTANCE_CFG.getWidth(), - HudCommsWidget.INSTANCE_CFG.getHeight()); + yield Pair.of( + IntIntPair.of( + HudCommsWidget.INSTANCE_CFG.getWidth(), + HudCommsWidget.INSTANCE_CFG.getHeight()), + IntIntPair.of( + HudPowderWidget.INSTANCE_CFG.getWidth(), + HudPowderWidget.INSTANCE_CFG.getHeight()) + ); } - default -> IntIntPair.of(200, 20 * commissions.size()); + default -> Pair.of( + IntIntPair.of( + 200, + 20 * commissions.size()), + IntIntPair.of( + 200, + 40) + ); }; } - public static void render(HudCommsWidget hcw, DrawContext context, int hudX, int hudY, List commissions) { + public static void render(HudCommsWidget hcw, HudPowderWidget hpw, DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List commissions,int mithril, int gemStone) { switch (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.style) { - case SIMPLE -> renderSimple(hcw, context, hudX, hudY, commissions); - case FANCY -> renderFancy(hcw, context, hudX, hudY, commissions); - case CLASSIC -> renderClassic(context, hudX, hudY, commissions); + 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 CLASSIC -> renderClassic(context, comHudX, comHudY,powderHudX,powderHudY, commissions); } } - public static void renderClassic(DrawContext context, int hudX, int hudY, List commissions) { + public static void renderClassic(DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List commissions) { if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground) { - context.fill(hudX, hudY, hudX + 200, hudY + (20 * commissions.size()), 0x64000000); + context.fill(comHudX, comHudY, comHudX + 200, comHudY + (20 * commissions.size()), 0x64000000); + context.fill(powderHudX, powderHudY, powderHudX + 200, powderHudY + 40, 0x64000000); } + if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions) { + int y = 0; + for (Commission commission : commissions) { + float percentage; + if (!commission.progression().contains("DONE")) { + percentage = Float.parseFloat(commission.progression().substring(0, commission.progression().length() - 1)); + } else { + percentage = 100f; + } - int y = 0; - for (Commission commission : commissions) { - float percentage; - if (!commission.progression().contains("DONE")) { - percentage = Float.parseFloat(commission.progression().substring(0, commission.progression().length() - 1)); - } else { - percentage = 100f; + 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)))), + comHudX + 5, comHudY + y + 5, 0xFFFFFFFF); + y += 20; } - + } + if(SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledPowder) { + //render mithril powder then gemstone + context + .drawTextWithShadow(client.textRenderer, + Text.literal("Mithril: " + mithrilPowder) + .styled(style -> style.withColor(Formatting.AQUA)), + powderHudX + 5, powderHudY + 5, 0xFFFFFFFF); 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)))), - hudX + 5, hudY + y + 5, 0xFFFFFFFF); - y += 20; + Text.literal("Gemstone: " + gemStonePowder) + .styled(style -> style.withColor(Formatting.DARK_PURPLE)), + powderHudX + 5, powderHudY + 25, 0xFFFFFFFF); } } - public static void renderSimple(HudCommsWidget hcw, DrawContext context, int hudX, int hudY, List commissions) { - hcw.updateData(commissions, false); - hcw.update(); - hcw.setX(hudX); - hcw.setY(hudY); - hcw.render(context, - SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground); + public static void renderSimple(HudCommsWidget hcw, HudPowderWidget hpw, DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List commissions,int mithril, int gemStone) { + if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions) { + hcw.updateData(commissions, false); + hcw.update(); + hcw.setX(comHudX); + hcw.setY(comHudY); + hcw.render(context, + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground); + } + if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledPowder) { + hpw.update(); + hpw.setX(powderHudX); + hpw.setY(powderHudY); + hpw.render(context, + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground); + } } - public static void renderFancy(HudCommsWidget hcw, DrawContext context, int hudX, int hudY, List commissions) { - hcw.updateData(commissions, true); - hcw.update(); - hcw.setX(hudX); - hcw.setY(hudY); - hcw.render(context, - SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground); + public static void renderFancy(HudCommsWidget hcw, HudPowderWidget hpw, DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List commissions,int mithril, int gemStone) { + if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions) { + hcw.updateData(commissions, true); + hcw.update(); + hcw.setX(comHudX); + hcw.setY(comHudY); + hcw.render(context, + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground); + } + if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledPowder) { + hpw.update(); + hpw.setX(powderHudX); + hpw.setY(powderHudY); + hpw.render(context, + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground); + } } public static void update() { commissionList = new ArrayList<>(); - if (client.player == null || client.getNetworkHandler() == null || !SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabled) + if (client.player == null || client.getNetworkHandler() == null || !SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions) return; client.getNetworkHandler().getPlayerList().forEach(playerListEntry -> { 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); 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 new file mode 100644 index 00000000..345794d8 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/hud/HudPowderWidget.java @@ -0,0 +1,47 @@ +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; + +// this widget shows the status of the king's commissions. +// (dwarven mines and crystal hollows) +// USE ONLY WITH THE DWARVEN HUD! + +public class HudPowderWidget extends Widget { + + private static final MutableText TITLE = Text.literal("Powders").formatted(Formatting.DARK_AQUA, + Formatting.BOLD); + + + // disgusting hack to get around text renderer issues. + // the ctor eventually tries to get the font's height, which doesn't work + // when called before the client window is created (roughly). + // the rebdering god 2 from the fabricord explained that detail, thanks! + //coppied from the HodCommsWidget to be used in the same place + public static final HudPowderWidget INSTANCE = new HudPowderWidget(); + public static final HudPowderWidget INSTANCE_CFG = new HudPowderWidget(); + + // another repulsive hack to make this widget-like hud element work with the new widget class + // DON'T USE WITH THE WIDGET SYSTEM, ONLY USE FOR DWARVENHUD! + public HudPowderWidget() { + super(TITLE, Formatting.DARK_AQUA.getColorValue()); + } + + + @Override + public void updateContent() { + this.addSimpleIcoText(Ico.MITHRIL, "Mithril:", Formatting.AQUA, 46); + this.addSimpleIcoText(Ico.AMETHYST_SHARD, "Gemstone:", Formatting.DARK_PURPLE, 47); + } + +} diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 0a6ae442..c98d0c61 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -268,7 +268,8 @@ "text.autoconfig.skyblocker.option.locations.dwarvenMines.solveFetchur": "Solve Fetchur", "text.autoconfig.skyblocker.option.locations.dwarvenMines.solvePuzzler": "Solve Puzzler Puzzle", "text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud": "Dwarven HUD", - "text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.enabled": "Enabled", + "text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.enabledCommissions": "Enable Commissions", + "text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.enabledPowder": "Enable Powder", "text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.style": "Style for HUD", "text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.style.@Tooltip[0]": "Simple: Shows name and percentage.", "text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.style.@Tooltip[1]": "\nFancy: Shows name, percentage, progress bar and an icon.", -- cgit From 913f2d6d31e1648e02ff9b9daeb1020a0ea84727 Mon Sep 17 00:00:00 2001 From: olim Date: Wed, 31 Jan 2024 10:58:23 +0000 Subject: fixed text fixed the text for the config in dwarven mines category --- .../skyblocker/config/categories/DwarvenMinesCategory.java | 10 +++++----- src/main/resources/assets/skyblocker/lang/en_us.json | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'src/main/java/de') diff --git a/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java index 4bacc2b6..0dc48368 100644 --- a/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java +++ b/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java @@ -84,17 +84,17 @@ public class DwarvenMinesCategory { .build()) //crystal HUD .group(OptionGroup.createBuilder() - .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud")) //todo i do not know if i need to duplicate text + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud")) .collapsed(false) .option(Option.createBuilder() - .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.enabled")) + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.enabled")) .binding(defaults.locations.dwarvenMines.crystalsHud.enabled, () -> config.locations.dwarvenMines.crystalsHud.enabled, newValue -> config.locations.dwarvenMines.crystalsHud.enabled = newValue) .controller(ConfigUtils::createBooleanController) .build()) .option(ButtonOption.createBuilder() - .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.screen")) + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.screen")) .text(Text.translatable("text.skyblocker.open")) .action((screen, opt) -> MinecraftClient.getInstance().setScreen(new CrystalsHudConfigScreen(screen))) .build()) @@ -108,10 +108,10 @@ public class DwarvenMinesCategory { .build()) //crystals waypoints .group(OptionGroup.createBuilder() - .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints")) //todo i do not know if i need to duplicate text + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints")) .collapsed(false) .option(Option.createBuilder() - .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.enabled")) + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.enabled")) .binding(defaults.locations.dwarvenMines.crystalsWaypoints.enabled, () -> config.locations.dwarvenMines.crystalsWaypoints.enabled, newValue -> config.locations.dwarvenMines.crystalsWaypoints.enabled = newValue) diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index c98d0c61..4269441d 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -277,8 +277,11 @@ "text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.screen": "Dwarven HUD Config...", "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.showLocations": "Show Waypoints", "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.findInChat": "Find Waypoints In Chat", "text.autoconfig.skyblocker.option.locations.rift": "The Rift", -- cgit From 24f0a72bba4d224ff4270bbe3175e600f1389d27 Mon Sep 17 00:00:00 2001 From: olim Date: Wed, 31 Jan 2024 10:59:05 +0000 Subject: added location added King to way point locations and fixed color of Corleone. --- src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java | 6 ------ .../hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java | 5 +++-- .../java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java | 3 ++- 3 files changed, 5 insertions(+), 9 deletions(-) (limited to 'src/main/java/de') 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 6a9ac743..01b1e9ec 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java @@ -55,12 +55,6 @@ public class CrystalsHud { } public static void render( DrawContext context, int hudX, int hudY) { - - if (SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.enableBackground) { - context.fill(hudX, hudY, hudX + 62, hudY + 62, 0x64000000); - } - - //draw map texture context. drawTexture(MAP_TEXTURE,hudX,hudY,0,0,62,62,62,62); 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 4ca38a04..ed9ba8bf 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -51,8 +51,9 @@ public class CrystalsLocationsManager { "Khazad-dûm", CrystalsWaypoint.Category.KHAZADUM, "Fairy Grotto", CrystalsWaypoint.Category.FAIRYGROTTO, "Dragon's Lair", CrystalsWaypoint.Category.DRAGONSLAIR, - "Corleone", CrystalsWaypoint.Category.DRAGONSLAIR - ); + "Corleone", CrystalsWaypoint.Category.CORLEONE, + "King", CrystalsWaypoint.Category.KING + ); 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])"); 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 c33251d7..5445a68c 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java @@ -104,7 +104,8 @@ public class CrystalsWaypoint extends Waypoint { KHAZADUM("Khazad-dûm",Color.RED), FAIRYGROTTO("Fairy Grotto",Color.PINK), DRAGONSLAIR("Dragon's Lair",Color.BLACK), - CORLEONE("Corleone",Color.ORANGE), + CORLEONE("Corleone",Color.gray), + KING("King",Color.yellow), DEFAULT("Default",Color.BLACK); -- cgit From 89f38714edc7b0ab06dadf7119c4d4d762191a2f Mon Sep 17 00:00:00 2001 From: olim Date: Wed, 31 Jan 2024 14:35:54 +0000 Subject: map location size configurable and removed unused code removed code that was unused in the new functions. and added a config option for the locations on the crystals map as well as showing certain locations smaller to better fit their size --- .../hysky/skyblocker/config/SkyblockerConfig.java | 3 +++ .../config/categories/DwarvenMinesCategory.java | 10 ++++++++- .../skyblocker/skyblock/dwarven/CrystalsHud.java | 25 +++++++++++++--------- .../skyblock/dwarven/CrystalsLocationsManager.java | 5 +++-- .../skyblock/dwarven/CrystalsWaypoint.java | 20 ----------------- .../resources/assets/skyblocker/lang/en_us.json | 1 + 6 files changed, 31 insertions(+), 33 deletions(-) (limited to 'src/main/java/de') diff --git a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java index e84d2d85..ecf66407 100644 --- a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java @@ -916,6 +916,9 @@ public class SkyblockerConfig { @SerialEntry public boolean showLocations = true; + @SerialEntry + public int locationSize = 8; + @SerialEntry public int x = 10; diff --git a/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java index 0dc48368..a15424a7 100644 --- a/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java +++ b/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java @@ -9,6 +9,7 @@ import dev.isxander.yacl3.api.Option; import dev.isxander.yacl3.api.OptionDescription; import dev.isxander.yacl3.api.OptionGroup; import de.hysky.skyblocker.skyblock.dwarven.DwarvenHudConfigScreen; +import dev.isxander.yacl3.api.controller.IntegerSliderControllerBuilder; import net.minecraft.client.MinecraftClient; import net.minecraft.text.Text; @@ -82,7 +83,7 @@ public class DwarvenMinesCategory { .controller(ConfigUtils::createBooleanController) .build()) .build()) - //crystal HUD + //crystal HUD //todo add descriptions to features .group(OptionGroup.createBuilder() .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud")) .collapsed(false) @@ -105,6 +106,13 @@ public class DwarvenMinesCategory { newValue -> config.locations.dwarvenMines.crystalsHud.showLocations = newValue) .controller(ConfigUtils::createBooleanController) .build()) + .option(Option.createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.locationSize")) + .binding(defaults.locations.dwarvenMines.crystalsHud.locationSize, + () -> config.locations.dwarvenMines.crystalsHud.locationSize, + newValue -> config.locations.dwarvenMines.crystalsHud.locationSize = newValue) + .controller(opt -> IntegerSliderControllerBuilder.create(opt).range(4, 12).step(2)) + .build()) .build()) //crystals waypoints .group(OptionGroup.createBuilder() 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 01b1e9ec..e9dfd6ac 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java @@ -11,9 +11,7 @@ import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallba import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.texture.atlas.Sprite; import net.minecraft.util.Identifier; -import org.apache.commons.math3.analysis.UnivariateMatrixFunction; import java.awt.*; import java.util.Arrays; @@ -22,13 +20,16 @@ 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"); //todo is this the right place to store file + protected 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"); - public static boolean visable = false; + private static final String[] SMALL_LOCATIONS = new String[] {"Fairy Grotto","King","Corleone"}; + + public static boolean visible = false; + + - public static final int LOCATION_SIZE = 10; //todo possible config option @@ -42,7 +43,7 @@ public class CrystalsHud { if (!SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.enabled || client.options.playerListKey.isPressed() || client.player == null - || !visable) { + || !visible) { return; } render(context, SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.x, @@ -64,8 +65,12 @@ public class CrystalsHud { for (CrystalsWaypoint waypoint : ActiveWaypoints.values()){ Color waypointColor = waypoint.category.color; Pair renderPos = transformLocation(waypoint.pos.getX(),waypoint.pos.getZ()); - //fill square of size LOCATION_SIZE around the coordinates of the location - context.fill(hudX+renderPos.first()-LOCATION_SIZE/2,hudY+renderPos.second()-LOCATION_SIZE/2,hudX+renderPos.first()+LOCATION_SIZE/2,hudY+renderPos.second()+LOCATION_SIZE/2,waypointColor.getRGB()); + 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; + } + //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()); } } //draw player on map @@ -96,11 +101,11 @@ public class CrystalsHud { public static void update() { if (client.player == null || client.getNetworkHandler() == null || !SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.enabled) { - visable = false; + visible = false; return; } //get if the player is in the crystals - visable = Utils.isInCrystals(); + visible = Utils.isInCrystals(); } 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 ed9ba8bf..181a8750 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -25,6 +25,7 @@ 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.*; @@ -164,8 +165,8 @@ public class CrystalsLocationsManager { } public static void update() { - if (client.player == null || client.getNetworkHandler() == null || !SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.enabled) { - SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.ActiveWaypoints= new HashMap<>(); //todo dose not seem to be working + 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 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 5445a68c..09eeb419 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java @@ -31,13 +31,6 @@ import java.util.function.ToDoubleFunction; public class CrystalsWaypoint extends Waypoint { private static final Logger LOGGER = LoggerFactory.getLogger(CrystalsWaypoint.class); - public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( - Category.CODEC.fieldOf("category").forGetter(crystalsWaypoint -> crystalsWaypoint.category), - TextCodecs.CODEC.fieldOf("name").forGetter(crystalsWaypoint -> crystalsWaypoint.name), - BlockPos.CODEC.fieldOf("pos").forGetter(crystalsWaypoint -> crystalsWaypoint.pos) - ).apply(instance, CrystalsWaypoint::new)); - - private static final Supplier CONFIG = () -> SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints; static final Supplier TYPE_SUPPLIER = () -> CONFIG.get().waypointType; @@ -137,18 +130,5 @@ public class CrystalsWaypoint extends Waypoint { return name; } - static class CategoryArgumentType extends EnumArgumentType { - CategoryArgumentType() { - super(Category.CODEC, Category::values); - } - - static CategoryArgumentType category() { - return new CategoryArgumentType(); - } - - static Category getCategory(CommandContext context, String name) { - return context.getArgument(name, Category.class); - } - } } } diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 4269441d..b994ab63 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -280,6 +280,7 @@ "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.showLocations": "Show Waypoints", + "text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.showLocations.locationSize": "Location Size", "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.findInChat": "Find Waypoints In Chat", -- cgit From 465c46d1f3dde2474fc1595033e2eab4e7286433 Mon Sep 17 00:00:00 2001 From: olim Date: Wed, 31 Jan 2024 14:42:06 +0000 Subject: update waypoints updated waypoints to use the global waypoint option --- src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java | 3 +-- .../de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java | 10 +--------- 2 files changed, 2 insertions(+), 11 deletions(-) (limited to 'src/main/java/de') diff --git a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java index ecf66407..a07b0084 100644 --- a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java @@ -934,8 +934,7 @@ public class SkyblockerConfig { @SerialEntry public Map ActiveWaypoints = new HashMap<>() {}; - @SerialEntry - public Waypoint.Type waypointType = Waypoint.Type.WAYPOINT; //todo see if best option / give player a choice + } public enum DwarvenHudStyle { 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 09eeb419..39509c41 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java @@ -32,20 +32,12 @@ import java.util.function.ToDoubleFunction; public class CrystalsWaypoint extends Waypoint { private static final Logger LOGGER = LoggerFactory.getLogger(CrystalsWaypoint.class); - private static final Supplier CONFIG = () -> SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints; + private static final Supplier CONFIG = () -> SkyblockerConfigManager.get().general.waypoints; static final Supplier TYPE_SUPPLIER = () -> CONFIG.get().waypointType; final Category category; final Text name; private final Vec3d centerPos; - CrystalsWaypoint( JsonObject waypoint, String name, BlockPos pos) { - this(Category.get(waypoint), name, pos); - } - - CrystalsWaypoint(Category category, String name, BlockPos pos) { - this( category, Text.of(name), pos); - } - CrystalsWaypoint( Category category, Text name, BlockPos pos) { super(pos, TYPE_SUPPLIER, category.colorComponents); this.category = category; -- cgit From 7076875f3b9b513a569760f5890202e260fc6bd7 Mon Sep 17 00:00:00 2001 From: olim Date: Wed, 31 Jan 2024 15:23:53 +0000 Subject: comments and desriptions add more comments to new code and added Tooltips to the new options in the config menu --- .../config/categories/DwarvenMinesCategory.java | 8 +++++-- .../skyblocker/skyblock/dwarven/CrystalsHud.java | 26 +++++++++++++++++----- .../skyblock/dwarven/CrystalsLocationsManager.java | 6 ++--- .../skyblock/dwarven/CrystalsWaypoint.java | 4 +++- .../skyblocker/skyblock/dwarven/DwarvenHud.java | 16 ++++++++++++- .../resources/assets/skyblocker/lang/en_us.json | 4 ++++ 6 files changed, 52 insertions(+), 12 deletions(-) (limited to 'src/main/java/de') diff --git a/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java index a15424a7..62b0ebf9 100644 --- a/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java +++ b/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java @@ -83,7 +83,7 @@ public class DwarvenMinesCategory { .controller(ConfigUtils::createBooleanController) .build()) .build()) - //crystal HUD //todo add descriptions to features + //crystal HUD .group(OptionGroup.createBuilder() .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud")) .collapsed(false) @@ -101,13 +101,15 @@ public class DwarvenMinesCategory { .build()) .option(Option.createBuilder() .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.showLocations")) + .description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.showLocations.@Tooltip"))) .binding(defaults.locations.dwarvenMines.crystalsHud.showLocations, () -> config.locations.dwarvenMines.crystalsHud.showLocations, newValue -> config.locations.dwarvenMines.crystalsHud.showLocations = newValue) .controller(ConfigUtils::createBooleanController) .build()) .option(Option.createBuilder() - .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.locationSize")) + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.showLocations.locationSize")) + .description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.showLocations.locationSize.@Tooltip"))) .binding(defaults.locations.dwarvenMines.crystalsHud.locationSize, () -> config.locations.dwarvenMines.crystalsHud.locationSize, newValue -> config.locations.dwarvenMines.crystalsHud.locationSize = newValue) @@ -120,6 +122,7 @@ public class DwarvenMinesCategory { .collapsed(false) .option(Option.createBuilder() .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.enabled")) + .description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.enabled.@Tooltip"))) .binding(defaults.locations.dwarvenMines.crystalsWaypoints.enabled, () -> config.locations.dwarvenMines.crystalsWaypoints.enabled, newValue -> config.locations.dwarvenMines.crystalsWaypoints.enabled = newValue) @@ -127,6 +130,7 @@ public class DwarvenMinesCategory { .build()) .option(Option.createBuilder() .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.findInChat")) + .description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.findInChat.@Tooltip"))) .binding(defaults.locations.dwarvenMines.crystalsWaypoints.findInChat, () -> config.locations.dwarvenMines.crystalsWaypoints.findInChat, newValue -> config.locations.dwarvenMines.crystalsWaypoints.findInChat = newValue) 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 e9dfd6ac..9212d74f 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java @@ -2,6 +2,8 @@ package de.hysky.skyblocker.skyblock.dwarven; import de.hysky.skyblocker.SkyblockerMod; import de.hysky.skyblocker.config.SkyblockerConfigManager; +import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager; +import de.hysky.skyblocker.skyblock.dungeon.secrets.Room; import de.hysky.skyblocker.utils.Utils; import de.hysky.skyblocker.utils.scheduler.Scheduler; import it.unimi.dsi.fastutil.Pair; @@ -29,10 +31,6 @@ public class CrystalsHud { public static boolean visible = false; - - - - public static void init() { ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(ClientCommandManager.literal("skyblocker") .then(ClientCommandManager.literal("hud") @@ -55,6 +53,14 @@ public class CrystalsHud { return IntIntPair.of(62, 62); } + + /** + * Renders the map to the players UI. renders the background image ({@link CrystalsHud#MAP_TEXTURE}) of the map then if enabled special locations on the map. then finally the player to the map. + * + * @param context DrawContext to draw map to + * @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) { //draw map texture context. @@ -89,6 +95,13 @@ public class CrystalsHud { //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. + * + * @param x the world X coordinate + * @param z the world Z coordinate + * @return the pair of values for x and y + */ private 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); @@ -98,7 +111,10 @@ public class CrystalsHud { 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) { visible = false; 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 181a8750..d7deed25 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -43,7 +43,9 @@ import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.lit public class CrystalsLocationsManager { public 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( "Jungle Temple", CrystalsWaypoint.Category.JUNGLETEMPLE, "Mines Of Divan", CrystalsWaypoint.Category.MINESOFDIVAN, @@ -94,8 +96,6 @@ public class CrystalsLocationsManager { } client.player.sendMessage(getLocationInputText(location), false); } - - } private static Boolean checkInCrystals(BlockPos pos){ //checks if a location is inside crystal hollows bounds 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 39509c41..3ae56c47 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java @@ -80,7 +80,9 @@ 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), 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 e7ffe362..fb055b87 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java @@ -67,7 +67,12 @@ public class DwarvenHud { }); } - public static Pair getDimForConfig(List commissions) { //todo add powder + /** + * Gets the dimensions (width, height) for the commissions hud and the powder hud + * @param commissions what commissions to get the dimensions for + * @return a {@link Pair} of {@link IntIntPair} with the first pair being for the commissions hud and the second pair being for the powder hud + */ + public static Pair getDimForConfig(List commissions) { return switch (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.style) { case SIMPLE -> { HudCommsWidget.INSTANCE_CFG.updateData(commissions, false); @@ -111,6 +116,15 @@ public class DwarvenHud { } } + /** + * Renders hud to window without using the widget rendering + * @param context DrawContext to draw the hud to + * @param comHudX X coordinate of the commissions hud + * @param comHudY Y coordinate of the commissions hud + * @param powderHudX X coordinate of the powder hud + * @param powderHudY Y coordinate of the powder hud + * @param commissions the commissions to render to the commissions hud + */ public static void renderClassic(DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List commissions) { if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground) { context.fill(comHudX, comHudY, comHudX + 200, comHudY + (20 * commissions.size()), 0x64000000); diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index b994ab63..8c3a2dc5 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -280,10 +280,14 @@ "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.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", + "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.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", "text.autoconfig.skyblocker.option.locations.rift": "The Rift", "text.autoconfig.skyblocker.option.locations.rift.mirrorverseWaypoints": "Enable Mirrorverse Waypoints", -- cgit From 43d683c782addcbadbe4988e493cc27c91810bc7 Mon Sep 17 00:00:00 2001 From: olim Date: Wed, 31 Jan 2024 15:46:34 +0000 Subject: add tests add tests for the maps location transformation function and the location manager valid location and LocaitonMessage functions --- .../skyblocker/skyblock/dwarven/CrystalsHud.java | 2 +- .../skyblock/dwarven/CrystalsLocationsManager.java | 4 +-- .../skyblock/dwarven/CrystalsHudTest.java | 19 +++++++++++++ .../dwarven/CrystalsLocationManagerTest.java | 31 ++++++++++++++++++++++ 4 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudTest.java create mode 100644 src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java (limited to 'src/main/java/de') 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 9212d74f..6b26d043 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java @@ -102,7 +102,7 @@ public class CrystalsHud { * @param z the world Z coordinate * @return the pair of values for x and y */ - private 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); 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 d7deed25..eb68ed9f 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -97,7 +97,7 @@ public class CrystalsLocationsManager { client.player.sendMessage(getLocationInputText(location), false); } } - private static Boolean checkInCrystals(BlockPos pos){ + protected static Boolean checkInCrystals(BlockPos pos){ //checks if a location is inside crystal hollows bounds return pos.getX() >= 202 && pos.getX() <= 823 && pos.getZ() >= 202 && pos.getZ() <= 823 @@ -114,7 +114,7 @@ public class CrystalsLocationsManager { ) ); } - private static Text getSetLocationMessage(String location,BlockPos blockPos) { + protected static Text getSetLocationMessage(String location,BlockPos blockPos) { MutableText text = Text.empty(); text.append(Text.literal("Added waypoint for ")); Color locationColor = WAYPOINTLOCATIONS.get(location).color; diff --git a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudTest.java b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudTest.java new file mode 100644 index 00000000..3086a3e4 --- /dev/null +++ b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudTest.java @@ -0,0 +1,19 @@ +package de.hysky.skyblocker.skyblock.dwarven; + +import it.unimi.dsi.fastutil.Pair; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +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(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)); + } +} diff --git a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java new file mode 100644 index 00000000..592e5ecb --- /dev/null +++ b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java @@ -0,0 +1,31 @@ +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; + +public class CrystalsLocationManagerTest { + + @Test + void testLocationInCrystals(){ + Assertions.assertTrue(CrystalsLocationsManager.checkInCrystals(new BlockPos(512,70,512))); + + Assertions.assertTrue(CrystalsLocationsManager.checkInCrystals(new BlockPos(202,31,202))); + Assertions.assertTrue(CrystalsLocationsManager.checkInCrystals(new BlockPos(823,188,823))); + + Assertions.assertFalse(CrystalsLocationsManager.checkInCrystals(new BlockPos(201,31,202))); + Assertions.assertFalse(CrystalsLocationsManager.checkInCrystals(new BlockPos(202,30,202))); + Assertions.assertFalse(CrystalsLocationsManager.checkInCrystals(new BlockPos(202,31,201))); + + Assertions.assertFalse(CrystalsLocationsManager.checkInCrystals(new BlockPos(824,188,823))); + Assertions.assertFalse(CrystalsLocationsManager.checkInCrystals(new BlockPos(823,189,823))); + Assertions.assertFalse(CrystalsLocationsManager.checkInCrystals(new BlockPos(823,188,824))); + } + + @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."); + } +} -- 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') 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 0e8a0102298b67318cb3a533f74f042994edaabc Mon Sep 17 00:00:00 2001 From: olim Date: Thu, 1 Feb 2024 19:21:46 +0000 Subject: fixed regresion a line was removed that cleared they active way points in last commit. put this back --- .../java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java | 4 +--- .../skyblocker/skyblock/dwarven/CrystalsLocationsManager.java | 9 +++++---- 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src/main/java/de') 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 59d70405..0c3d40eb 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java @@ -2,8 +2,6 @@ package de.hysky.skyblocker.skyblock.dwarven; import de.hysky.skyblocker.SkyblockerMod; import de.hysky.skyblocker.config.SkyblockerConfigManager; -import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager; -import de.hysky.skyblocker.skyblock.dungeon.secrets.Room; import de.hysky.skyblocker.utils.Utils; import de.hysky.skyblocker.utils.scheduler.Scheduler; import it.unimi.dsi.fastutil.Pair; @@ -68,7 +66,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= CrystalsLocationsManager.ActiveWaypoints; + Map ActiveWaypoints= CrystalsLocationsManager.activeWaypoints; for (CrystalsWaypoint waypoint : ActiveWaypoints.values()){ Color waypointColor = waypoint.category.color; Pair renderPos = transformLocation(waypoint.pos.getX(),waypoint.pos.getZ()); 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 74730315..8101fae6 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -49,7 +49,7 @@ public class CrystalsLocationsManager { "Corleone", CrystalsWaypoint.Category.CORLEONE, "King", CrystalsWaypoint.Category.KING ); - protected static Map ActiveWaypoints = new HashMap<>() {}; + 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])"); @@ -142,12 +142,12 @@ 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); - ActiveWaypoints.put(waypointName.getString(),waypoint); + activeWaypoints.put(waypointName.getString(),waypoint); } public static void render(WorldRenderContext context) { if (SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.enabled ) { - for (CrystalsWaypoint crystalsWaypoint : ActiveWaypoints.values()) { + for (CrystalsWaypoint crystalsWaypoint : activeWaypoints.values()) { if (crystalsWaypoint.shouldRender()) { crystalsWaypoint.render(context); } @@ -157,12 +157,13 @@ public class CrystalsLocationsManager { public static void update() { if (client.player == null || client.getNetworkHandler() == null || !SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.enabled || !Utils.isInCrystals()) { + 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 - if (!location.equals("Unknown") && WAYPOINTLOCATIONS.containsKey(location) && !ActiveWaypoints.containsKey(location)){ + if (!location.equals("Unknown") && WAYPOINTLOCATIONS.containsKey(location) && !activeWaypoints.containsKey(location)){ //add waypoint at player location BlockPos playerLocation = client.player.getBlockPos(); addCustomWaypoint(Text.of(location),playerLocation); -- 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') 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 From e5017cf3b6bf1d072033ed79e7b73291d5584650 Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Fri, 2 Feb 2024 01:05:14 -0500 Subject: Add map scaling option Also fixed the last few formatting issues I saw --- .../hysky/skyblocker/config/SkyblockerConfig.java | 6 ++--- .../config/categories/DwarvenMinesCategory.java | 8 +++++++ .../skyblocker/skyblock/dwarven/CrystalsHud.java | 26 +++++++++++++++++----- .../skyblock/dwarven/CrystalsHudConfigScreen.java | 14 ++++++++---- .../skyblock/dwarven/CrystalsLocationsManager.java | 4 ++-- .../skyblock/dwarven/CrystalsWaypoint.java | 1 - .../resources/assets/skyblocker/lang/en_us.json | 1 + 7 files changed, 44 insertions(+), 16 deletions(-) (limited to 'src/main/java/de') diff --git a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java index 5ca9604c..4acb8064 100644 --- a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java @@ -1,7 +1,6 @@ package de.hysky.skyblocker.config; import de.hysky.skyblocker.SkyblockerMod; -import de.hysky.skyblocker.skyblock.dwarven.CrystalsWaypoint; import de.hysky.skyblocker.skyblock.item.CustomArmorTrims; import de.hysky.skyblocker.utils.chat.ChatFilterResult; import de.hysky.skyblocker.utils.waypoint.Waypoint; @@ -15,9 +14,7 @@ import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; public class SkyblockerConfig { @SerialEntry @@ -925,6 +922,9 @@ public class SkyblockerConfig { @SerialEntry public int y = 130; + + @SerialEntry + public float mapScaling = 1f; } public static class CrystalsWaypoints { diff --git a/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java index 62b0ebf9..97b48bc4 100644 --- a/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java +++ b/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java @@ -9,6 +9,7 @@ import dev.isxander.yacl3.api.Option; import dev.isxander.yacl3.api.OptionDescription; import dev.isxander.yacl3.api.OptionGroup; import de.hysky.skyblocker.skyblock.dwarven.DwarvenHudConfigScreen; +import dev.isxander.yacl3.api.controller.FloatFieldControllerBuilder; import dev.isxander.yacl3.api.controller.IntegerSliderControllerBuilder; import net.minecraft.client.MinecraftClient; import net.minecraft.text.Text; @@ -99,6 +100,13 @@ public class DwarvenMinesCategory { .text(Text.translatable("text.skyblocker.open")) .action((screen, opt) -> MinecraftClient.getInstance().setScreen(new CrystalsHudConfigScreen(screen))) .build()) + .option(Option.createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.mapScaling")) + .binding(defaults.locations.dwarvenMines.crystalsHud.mapScaling, + () -> config.locations.dwarvenMines.crystalsHud.mapScaling, + newValue -> config.locations.dwarvenMines.crystalsHud.mapScaling = newValue) + .controller(FloatFieldControllerBuilder::create) + .build()) .option(Option.createBuilder() .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.showLocations")) .description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.showLocations.@Tooltip"))) 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 171f13ea..2a1ce63a 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java @@ -11,6 +11,7 @@ import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallba import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; @@ -20,7 +21,7 @@ import java.util.Map; public class CrystalsHud { private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); - private static final Identifier MAP_TEXTURE = new Identifier(SkyblockerMod.NAMESPACE, "textures/gui/crystals_map.png"); + protected 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 = { "Fairy Grotto", "King", "Corleone" }; @@ -43,8 +44,9 @@ public class CrystalsHud { }); } - protected static IntIntPair getDimForConfig() { - return IntIntPair.of(62, 62); + protected static IntIntPair getDimensionsForConfig() { + int size = (int) (62 * SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.mapScaling); + return IntIntPair.of(size, size); } @@ -55,9 +57,20 @@ public class CrystalsHud { * @param hudX Top left X coordinate of the map * @param hudY Top left Y coordinate of the map */ - protected static void render(DrawContext context, int hudX, int hudY) { + private static void render(DrawContext context, int hudX, int hudY) { + float scale = SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.mapScaling; + int size = (int) (62 * scale); + + //make sure the map renders infront of some stuff - improve this in the future with better layering (1.20.5?) + MatrixStack matrices = context.getMatrices(); + matrices.push(); + matrices.translate(0f, 0f, 200f); + //draw map texture - context.drawTexture(MAP_TEXTURE, hudX, hudY, 0, 0, 62, 62, 62, 62); + context.drawTexture(MAP_TEXTURE, hudX, hudY, 0, 0, size, size, size, size); + + //scale the rest of the stuff - this isn't applied to the map texture because doing so causes it to render with an "offset" + matrices.scale(scale, scale, 0f); //if enabled add waypoint locations to map if (SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.showLocations) { @@ -89,7 +102,8 @@ public class CrystalsHud { //draw marker on map 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) + //todo add direction (can not work out how to rotate) + matrices.pop(); } /** 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 e30d6390..b4e423e9 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudConfigScreen.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudConfigScreen.java @@ -28,14 +28,14 @@ public class CrystalsHudConfigScreen extends Screen { public void render(DrawContext context, int mouseX, int mouseY, float delta) { super.render(context, mouseX, mouseY, delta); renderBackground(context, mouseX, mouseY, delta); - CrystalsHud.render( context, hudX, hudY); + renderHUDMap(context, hudX, hudY); 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 = CrystalsHud.getDimForConfig(); - if (RenderHelper.pointIsInArea(mouseX, mouseY, hudX, hudY, hudX + 200, hudY + 40) && button == 0) { + IntIntPair dims = CrystalsHud.getDimensionsForConfig(); + if (RenderHelper.pointIsInArea(mouseX, mouseY, hudX, hudY, hudX + dims.leftInt(), hudY + dims.rightInt()) && 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); } @@ -45,13 +45,19 @@ public class CrystalsHudConfigScreen extends Screen { @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { if (button == 1) { - IntIntPair dims = CrystalsHud.getDimForConfig(); + IntIntPair dims = CrystalsHud.getDimensionsForConfig(); hudX = this.width / 2 - dims.leftInt(); hudY = this.height / 2 - dims.rightInt(); } return super.mouseClicked(mouseX, mouseY, button); } + private void renderHUDMap(DrawContext context, int x, int y) { + float scaling = SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.mapScaling; + int size = (int) (62 * scaling); + context.drawTexture(CrystalsHud.MAP_TEXTURE, x, y, 0, 0, size, size, size, size); + } + @Override public void close() { SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.x = hudX; 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 5b196f8e..1cbbb32e 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -169,7 +169,7 @@ public class CrystalsLocationsManager { private static void addCustomWaypoint( Text waypointName, BlockPos pos) { CrystalsWaypoint.Category category = WAYPOINT_LOCATIONS.get(waypointName.getString()); CrystalsWaypoint waypoint = new CrystalsWaypoint(category, waypointName, pos); - activeWaypoints.put(waypointName.getString(),waypoint); + activeWaypoints.put(waypointName.getString(), waypoint); } public static void render(WorldRenderContext context) { @@ -183,7 +183,7 @@ public class CrystalsLocationsManager { } private static void reset() { - activeWaypoints.clear(); + activeWaypoints.clear(); } public static void update() { 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 ad85e763..423a8cbd 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java @@ -25,7 +25,6 @@ import java.util.function.ToDoubleFunction; public class CrystalsWaypoint extends Waypoint { private static final Logger LOGGER = LoggerFactory.getLogger(CrystalsWaypoint.class); - private static final Supplier CONFIG = () -> SkyblockerConfigManager.get().general.waypoints; private static final Supplier TYPE_SUPPLIER = () -> CONFIG.get().waypointType; final Category category; diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 936ac1fa..f17f109e 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -279,6 +279,7 @@ "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": "Crystal Hollows Map Placement Config...", + "text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.mapScaling": "Map Scaling", "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", -- cgit From 94541a6f53b3b6f2b3f9cc830c728f62c4d63c1a Mon Sep 17 00:00:00 2001 From: olim Date: Fri, 2 Feb 2024 10:43:54 +0000 Subject: fixed scaling the scaling was also scaling the hudX and hudY for the player icon and location boxes offsetting them. (the map can also be scaled the same now) --- .../de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/main/java/de') 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 2a1ce63a..e490041c 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java @@ -59,18 +59,16 @@ public class CrystalsHud { */ private static void render(DrawContext context, int hudX, int hudY) { float scale = SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.mapScaling; - int size = (int) (62 * scale); //make sure the map renders infront of some stuff - improve this in the future with better layering (1.20.5?) + //and set position and scale MatrixStack matrices = context.getMatrices(); matrices.push(); - matrices.translate(0f, 0f, 200f); + matrices.translate(hudX, hudY, 200f); + matrices.scale(scale, scale, 0f); //draw map texture - context.drawTexture(MAP_TEXTURE, hudX, hudY, 0, 0, size, size, size, size); - - //scale the rest of the stuff - this isn't applied to the map texture because doing so causes it to render with an "offset" - matrices.scale(scale, scale, 0f); + context.drawTexture(MAP_TEXTURE, 0, 0, 0, 0, 62, 62, 62, 62); //if enabled add waypoint locations to map if (SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.showLocations) { @@ -86,7 +84,7 @@ public class CrystalsHud { } //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(renderPos.first() - locationSize / 2, renderPos.second() - locationSize / 2, renderPos.first() + locationSize / 2, renderPos.second() + locationSize / 2, waypointColor.getRGB()); } } @@ -100,7 +98,7 @@ public class CrystalsHud { 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, renderPos.first() - 2, renderPos.second() - 2, 58, 2, 4, 4, 128, 128); //todo add direction (can not work out how to rotate) matrices.pop(); -- cgit From 7b8bb6d5225895925712ebb76130718e7357b055 Mon Sep 17 00:00:00 2001 From: olim Date: Fri, 2 Feb 2024 13:15:16 +0000 Subject: fixed displaying everywere fixed bug introduced by Refactor (setting commission list to a new array only if updating its values in the update function). by adding check for is in Dwarven mines or crystal hollow on the render conditions. instead of if the list is empty or not --- src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java | 4 ++-- src/main/java/de/hysky/skyblocker/utils/Utils.java | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'src/main/java/de') 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 3eef66d7..4446c1a7 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java @@ -58,7 +58,7 @@ public class DwarvenHud { if ((!SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions && !SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledPowder) || client.options.playerListKey.isPressed() || client.player == null - || commissionList.isEmpty()) { + || (!Utils.isInDwarvenMines() && !Utils.isInCrystalHollows())) { return; } @@ -203,7 +203,7 @@ public class DwarvenHud { public static void update() { if (client.player == null || client.getNetworkHandler() == null || !SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions || (!Utils.isInCrystalHollows() - && !Utils.getLocationRaw().equals("mining_3"))) + && !Utils.isInDwarvenMines())) return; commissionList = new ArrayList<>(); diff --git a/src/main/java/de/hysky/skyblocker/utils/Utils.java b/src/main/java/de/hysky/skyblocker/utils/Utils.java index 066bc19b..b0c5bf45 100644 --- a/src/main/java/de/hysky/skyblocker/utils/Utils.java +++ b/src/main/java/de/hysky/skyblocker/utils/Utils.java @@ -37,6 +37,7 @@ public class Utils { private static final String ALTERNATE_HYPIXEL_ADDRESS = System.getProperty("skyblocker.alternateHypixelAddress", ""); private static final String DUNGEONS_LOCATION = "dungeon"; private static final String CRYSTAL_HOLLOWS_LOCATION = "crystal_hollows"; + private static final String DWARVEN_MINES_LOCATION = "mining_3"; private static final String PROFILE_PREFIX = "Profile: "; private static boolean isOnHypixel = false; @@ -92,6 +93,10 @@ public class Utils { return getLocationRaw().equals(CRYSTAL_HOLLOWS_LOCATION) || FabricLoader.getInstance().isDevelopmentEnvironment(); } + public static boolean isInDwarvenMines() { + return getLocationRaw().equals(DWARVEN_MINES_LOCATION) || FabricLoader.getInstance().isDevelopmentEnvironment(); + } + public static boolean isInTheRift() { return getLocationRaw().equals(TheRift.LOCATION); } -- cgit From a04118ff1f1962d7b0e034fa415730153fb1274b Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Sat, 3 Feb 2024 02:22:16 -0500 Subject: Tweak waypoint colours --- .../skyblock/dwarven/CrystalsLocationsManager.java | 2 +- .../skyblocker/skyblock/dwarven/CrystalsWaypoint.java | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src/main/java/de') 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 1cbbb32e..36220da9 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -50,7 +50,7 @@ public class CrystalsLocationsManager { "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, + "Khazad-dûm", CrystalsWaypoint.Category.KHAZAD_DUM, "Fairy Grotto", CrystalsWaypoint.Category.FAIRY_GROTTO, "Dragon's Lair", CrystalsWaypoint.Category.DRAGONS_LAIR, "Corleone", CrystalsWaypoint.Category.CORLEONE, 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 423a8cbd..38a3d741 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java @@ -11,6 +11,7 @@ import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; import net.minecraft.client.MinecraftClient; import net.minecraft.entity.Entity; import net.minecraft.text.Text; +import net.minecraft.util.DyeColor; import net.minecraft.util.Formatting; import net.minecraft.util.StringIdentifiable; import net.minecraft.util.math.BlockPos; @@ -76,15 +77,15 @@ 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), + JUNGLE_TEMPLE("Jungle Temple", new Color(DyeColor.PURPLE.getSignColor())), + MINES_OF_DIVAN("Mines of Divan", Color.GREEN), + GOBLIN_QUEENS_DEN("Goblin Queen's Den", new Color(DyeColor.ORANGE.getSignColor())), + LOST_PRECURSOR_CITY("Lost Precursor City", Color.CYAN), + KHAZAD_DUM("Khazad-dûm", Color.YELLOW), FAIRY_GROTTO("Fairy Grotto", Color.PINK), DRAGONS_LAIR("Dragon's Lair", Color.BLACK), - CORLEONE("Corleone", Color.gray), - KING("King", Color.yellow), + CORLEONE("Corleone", Color.WHITE), + KING("King", Color.RED), DEFAULT("Default", Color.BLACK); -- cgit From 9702d67ccf15f2bbb2c6a841efde5b71edb08395 Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Sat, 3 Feb 2024 05:29:50 -0500 Subject: Improve Map Player Marker It will now show you what way you're looking. --- .../skyblocker/skyblock/dwarven/CrystalsHud.java | 31 +++++++++++++++------- .../skyblock/dwarven/CrystalsHudTest.java | 13 ++++----- .../dwarven/CrystalsLocationManagerTest.java | 4 +-- 3 files changed, 30 insertions(+), 18 deletions(-) (limited to 'src/main/java/de') 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 e490041c..d1303675 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java @@ -4,7 +4,6 @@ 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 it.unimi.dsi.fastutil.Pair; import it.unimi.dsi.fastutil.ints.IntIntPair; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; @@ -14,6 +13,7 @@ import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.RotationAxis; import java.awt.*; import java.util.Arrays; @@ -39,7 +39,7 @@ public class CrystalsHud { || !visible) { return; } - render(context, SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.x, + render(context, tickDelta, SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.x, SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.y); }); } @@ -54,10 +54,11 @@ public class CrystalsHud { * Renders the map to the players UI. renders the background image ({@link CrystalsHud#MAP_TEXTURE}) of the map then if enabled special locations on the map. then finally the player to the map. * * @param context DrawContext to draw map to + * @param tickDelta For interpolating the player's yaw for map marker * @param hudX Top left X coordinate of the map * @param hudY Top left Y coordinate of the map */ - private static void render(DrawContext context, int hudX, int hudY) { + private static void render(DrawContext context, float tickDelta, int hudX, int hudY) { float scale = SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.mapScaling; //make sure the map renders infront of some stuff - improve this in the future with better layering (1.20.5?) @@ -76,15 +77,15 @@ public class CrystalsHud { 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; + IntIntPair 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; } //fill square of size locationSize around the coordinates of the location - context.fill(renderPos.first() - locationSize / 2, renderPos.second() - locationSize / 2, renderPos.first() + locationSize / 2, renderPos.second() + locationSize / 2, waypointColor.getRGB()); + context.fill(renderPos.firstInt() - locationSize / 2, renderPos.secondInt() - locationSize / 2, renderPos.firstInt() + locationSize / 2, renderPos.secondInt() + locationSize / 2, waypointColor.getRGB()); } } @@ -96,9 +97,19 @@ public class CrystalsHud { //get player location double playerX = CLIENT.player.getX(); double playerZ = CLIENT.player.getZ(); - Pair renderPos = transformLocation(playerX,playerZ); + float playerRotation = CLIENT.player.getYaw(); //TODO make the transitions more rough? + IntIntPair renderPos = transformLocation(playerX,playerZ); + + int renderX = renderPos.firstInt() - 2; + int renderY = renderPos.secondInt() - 3; + + //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); + //draw marker on map - context.drawTexture(MAP_ICON, renderPos.first() - 2, renderPos.second() - 2, 58, 2, 4, 4, 128, 128); + context.drawTexture(MAP_ICON, 0, 0, 2, 0, 5, 7, 128, 128); //todo add direction (can not work out how to rotate) matrices.pop(); @@ -111,14 +122,14 @@ 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 IntIntPair 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); + return IntIntPair.of(transformedX,transformedY); } /** 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 fbe9e548..edb478d8 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudTest.java @@ -1,6 +1,7 @@ package de.hysky.skyblocker.skyblock.dwarven; -import it.unimi.dsi.fastutil.Pair; +import it.unimi.dsi.fastutil.ints.IntIntPair; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -8,12 +9,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), IntIntPair.of(0, 0)); + Assertions.assertEquals(CrystalsHud.transformLocation(823, 823), IntIntPair.of(62, 62)); - Assertions.assertEquals(CrystalsHud.transformLocation(512.5, 512.5), Pair.of(31, 31)); + Assertions.assertEquals(CrystalsHud.transformLocation(512.5, 512.5), IntIntPair.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), IntIntPair.of(0, 0)); + Assertions.assertEquals(CrystalsHud.transformLocation(1000, 1000), IntIntPair.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 3649afb5..4ce61880 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java @@ -26,7 +26,7 @@ public class CrystalsLocationManagerTest { @Test void testSetLocationMessage() { - 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."); + 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 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/java/de') 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 From 075775e2c2f8fdd01b048721b0bd2d88aefe2464 Mon Sep 17 00:00:00 2001 From: olim Date: Sat, 3 Feb 2024 12:56:16 +0000 Subject: Fixed rotation of Map Player Marker make it so it rotates around the centre of the player marker and re add the flip (+180) so marker is facing correct direction. --- src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/main/java/de') 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 35f26c0e..ee6d4307 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(yaw2Cardinal(playerRotation)), 2, 3, 0); + matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(yaw2Cardinal(playerRotation)), 2.5f, 3.5f, 0); //draw marker on map context.drawTexture(MAP_ICON, 0, 0, 2, 0, 5, 7, 128, 128); @@ -139,6 +139,7 @@ public class CrystalsHud { * Based off code from {@link net.minecraft.client.render.MapRenderer} */ private static float yaw2Cardinal(float yaw) { + yaw += + 180; //flip direction byte clipped = (byte)((yaw += yaw < 0.0 ? -8.0 : 8.0) * 16.0 / 360.0); return (clipped * 360f) / 16f; -- cgit From c7d93136da9134ed2db556e8459e40620d16c1dd Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Sat, 3 Feb 2024 22:59:13 -0500 Subject: Fix final few code formatting things --- .../de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java | 12 ++++++------ .../skyblock/dwarven/CrystalsLocationsManager.java | 2 +- .../hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java | 12 +++--------- 3 files changed, 10 insertions(+), 16 deletions(-) (limited to 'src/main/java/de') 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 ee6d4307..77f5fe38 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java @@ -73,11 +73,11 @@ public class CrystalsHud { //if enabled add waypoint locations to map if (SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.showLocations) { - Map ActiveWaypoints= CrystalsLocationsManager.activeWaypoints; + Map ActiveWaypoints = CrystalsLocationsManager.activeWaypoints; for (CrystalsWaypoint waypoint : ActiveWaypoints.values()) { Color waypointColor = waypoint.category.color; - IntIntPair renderPos = transformLocation(waypoint.pos.getX(),waypoint.pos.getZ()); + IntIntPair 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 @@ -124,12 +124,12 @@ public class CrystalsHud { */ protected static IntIntPair 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); + 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 IntIntPair.of(transformedX,transformedY); + return IntIntPair.of(transformedX, transformedY); } /** @@ -140,7 +140,7 @@ public class CrystalsHud { */ private static float yaw2Cardinal(float yaw) { yaw += + 180; //flip direction - byte clipped = (byte)((yaw += yaw < 0.0 ? -8.0 : 8.0) * 16.0 / 360.0); + byte clipped = (byte) ((yaw += yaw < 0.0 ? -8.0 : 8.0) * 16.0 / 360.0); return (clipped * 360f) / 16f; } 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 36220da9..24b031f8 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -119,7 +119,7 @@ public class CrystalsLocationsManager { .then(literal("crystalWaypoints") .then(argument("pos", BlockPosArgumentType.blockPos()) .then(argument("place", StringArgumentType.greedyString()) - .executes(context -> addWaypointFromCommand(context.getSource(), getString(context, "place"),context.getArgument("pos", PosArgument.class))) + .executes(context -> addWaypointFromCommand(context.getSource(), getString(context, "place"), context.getArgument("pos", PosArgument.class))) ) ) ) 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 38a3d741..ab971ec4 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java @@ -32,7 +32,7 @@ public class CrystalsWaypoint extends Waypoint { final Text name; private final Vec3d centerPos; - CrystalsWaypoint( Category category, Text name, BlockPos pos) { + CrystalsWaypoint(Category category, Text name, BlockPos pos) { super(pos, TYPE_SUPPLIER, category.colorComponents); this.category = category; this.name = name; @@ -64,7 +64,6 @@ public class CrystalsWaypoint extends Waypoint { public void render(WorldRenderContext context) { super.render(context); - Vec3d posUp = centerPos.add(0, 1, 0); RenderHelper.renderText(context, name, posUp, true); double distance = context.camera().getPos().distanceTo(centerPos); @@ -72,7 +71,6 @@ 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} */ @@ -89,18 +87,15 @@ public class CrystalsWaypoint extends Waypoint { DEFAULT("Default", Color.BLACK); - public final Color color; private static final Codec CODEC = StringIdentifiable.createCodec(Category::values); + public final Color color; private final String name; - private final float[] colorComponents; Category(String name,Color color) { this.name = name; this.color = color; - colorComponents = color.getColorComponents(null); - - + this.colorComponents = color.getColorComponents(null); } static Category get(JsonObject waypointJson) { @@ -116,6 +111,5 @@ public class CrystalsWaypoint extends Waypoint { public String asString() { return name; } - } } -- cgit From 94b0e8ebbd86c941950cf862ae4aa99d2466c511 Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Sat, 3 Feb 2024 23:09:03 -0500 Subject: Refactor to use Vector2i for pos coordinates Using a vector meant for X and Y values makes much more sense. --- .../skyblocker/skyblock/dwarven/CrystalsHud.java | 19 +++++++++++-------- .../skyblocker/skyblock/dwarven/CrystalsHudTest.java | 13 ++++++------- 2 files changed, 17 insertions(+), 15 deletions(-) (limited to 'src/main/java/de') 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 77f5fe38..116787d0 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java @@ -19,6 +19,9 @@ import java.awt.*; import java.util.Arrays; import java.util.Map; +import org.joml.Vector2i; +import org.joml.Vector2ic; + public class CrystalsHud { private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); protected static final Identifier MAP_TEXTURE = new Identifier(SkyblockerMod.NAMESPACE, "textures/gui/crystals_map.png"); @@ -77,7 +80,7 @@ public class CrystalsHud { for (CrystalsWaypoint waypoint : ActiveWaypoints.values()) { Color waypointColor = waypoint.category.color; - IntIntPair renderPos = transformLocation(waypoint.pos.getX(), waypoint.pos.getZ()); + Vector2ic 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 @@ -85,7 +88,7 @@ public class CrystalsHud { } //fill square of size locationSize around the coordinates of the location - context.fill(renderPos.firstInt() - locationSize / 2, renderPos.secondInt() - locationSize / 2, renderPos.firstInt() + locationSize / 2, renderPos.secondInt() + locationSize / 2, waypointColor.getRGB()); + context.fill(renderPos.x() - locationSize / 2, renderPos.y() - locationSize / 2, renderPos.x() + locationSize / 2, renderPos.y() + locationSize / 2, waypointColor.getRGB()); } } @@ -98,10 +101,10 @@ public class CrystalsHud { double playerX = CLIENT.player.getX(); double playerZ = CLIENT.player.getZ(); float playerRotation = CLIENT.player.getYaw(); //TODO make the transitions more rough? - IntIntPair renderPos = transformLocation(playerX,playerZ); + Vector2ic renderPos = transformLocation(playerX, playerZ); - int renderX = renderPos.firstInt() - 2; - int renderY = renderPos.secondInt() - 3; + int renderX = renderPos.x() - 2; + int renderY = renderPos.y() - 3; //position, scale and rotate the player marker matrices.translate(renderX, renderY, 0f); @@ -120,16 +123,16 @@ public class CrystalsHud { * * @param x the world X coordinate * @param z the world Z coordinate - * @return the pair of values for x and y + * @return a vector representing the x and y values */ - protected static IntIntPair transformLocation(double x, double z) { + protected static Vector2ic 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 IntIntPair.of(transformedX, transformedY); + return new Vector2i(transformedX, transformedY); } /** 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 edb478d8..2a3afe9c 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHudTest.java @@ -1,7 +1,6 @@ package de.hysky.skyblocker.skyblock.dwarven; -import it.unimi.dsi.fastutil.ints.IntIntPair; - +import org.joml.Vector2i; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -9,12 +8,12 @@ public class CrystalsHudTest { @Test void testLocationTransformation() { - Assertions.assertEquals(CrystalsHud.transformLocation(202, 202), IntIntPair.of(0, 0)); - Assertions.assertEquals(CrystalsHud.transformLocation(823, 823), IntIntPair.of(62, 62)); + Assertions.assertEquals(CrystalsHud.transformLocation(202, 202), new Vector2i(0, 0)); + Assertions.assertEquals(CrystalsHud.transformLocation(823, 823), new Vector2i(62, 62)); - Assertions.assertEquals(CrystalsHud.transformLocation(512.5, 512.5), IntIntPair.of(31, 31)); + Assertions.assertEquals(CrystalsHud.transformLocation(512.5, 512.5), new Vector2i(31, 31)); - Assertions.assertEquals(CrystalsHud.transformLocation(-50, -50), IntIntPair.of(0, 0)); - Assertions.assertEquals(CrystalsHud.transformLocation(1000, 1000), IntIntPair.of(62, 62)); + Assertions.assertEquals(CrystalsHud.transformLocation(-50, -50), new Vector2i(0, 0)); + Assertions.assertEquals(CrystalsHud.transformLocation(1000, 1000), new Vector2i(62, 62)); } } -- cgit From bd57b6038aff74629025926f7ef99ee3652c0faa Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Sun, 4 Feb 2024 02:02:01 -0500 Subject: Cleanup locations enum & add Odawa and Key Guardian locations --- .../skyblocker/skyblock/dwarven/CrystalsHud.java | 2 +- .../skyblock/dwarven/CrystalsLocationsManager.java | 14 +++---------- .../skyblock/dwarven/CrystalsWaypoint.java | 23 +++------------------- 3 files changed, 7 insertions(+), 32 deletions(-) (limited to 'src/main/java/de') 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 116787d0..447453cc 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java @@ -26,7 +26,7 @@ public class CrystalsHud { private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); protected 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 = { "Fairy Grotto", "King", "Corleone" }; + private static final String[] SMALL_LOCATIONS = { "Fairy Grotto", "King", "Corleone", "Odawa", "Key Guardian" }; public static boolean visible = false; 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 24b031f8..0a4e4518 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -29,8 +29,10 @@ import java.awt.*; import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; import org.slf4j.Logger; @@ -45,17 +47,7 @@ public class CrystalsLocationsManager { /** * A look-up table to convert between location names and waypoint in the {@link CrystalsWaypoint.Category} values. */ - protected static final Map WAYPOINT_LOCATIONS = Map.of( - "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.KHAZAD_DUM, - "Fairy Grotto", CrystalsWaypoint.Category.FAIRY_GROTTO, - "Dragon's Lair", CrystalsWaypoint.Category.DRAGONS_LAIR, - "Corleone", CrystalsWaypoint.Category.CORLEONE, - "King", CrystalsWaypoint.Category.KING - ); + protected static final Map WAYPOINT_LOCATIONS = Arrays.stream(CrystalsWaypoint.Category.values()).collect(Collectors.toMap(CrystalsWaypoint.Category::toString, Function.identity())); 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<>(); 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 ab971ec4..4c65aefb 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java @@ -1,8 +1,5 @@ package de.hysky.skyblocker.skyblock.dwarven; -import com.google.gson.JsonObject; -import com.mojang.serialization.Codec; -import com.mojang.serialization.JsonOps; import de.hysky.skyblocker.config.SkyblockerConfig; import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.utils.render.RenderHelper; @@ -13,11 +10,8 @@ import net.minecraft.entity.Entity; import net.minecraft.text.Text; import net.minecraft.util.DyeColor; import net.minecraft.util.Formatting; -import net.minecraft.util.StringIdentifiable; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.awt.*; import java.util.function.Predicate; @@ -25,7 +19,6 @@ import java.util.function.Supplier; import java.util.function.ToDoubleFunction; public class CrystalsWaypoint extends Waypoint { - private static final Logger LOGGER = LoggerFactory.getLogger(CrystalsWaypoint.class); private static final Supplier CONFIG = () -> SkyblockerConfigManager.get().general.waypoints; private static final Supplier TYPE_SUPPLIER = () -> CONFIG.get().waypointType; final Category category; @@ -74,7 +67,7 @@ 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 { + enum Category { JUNGLE_TEMPLE("Jungle Temple", new Color(DyeColor.PURPLE.getSignColor())), MINES_OF_DIVAN("Mines of Divan", Color.GREEN), GOBLIN_QUEENS_DEN("Goblin Queen's Den", new Color(DyeColor.ORANGE.getSignColor())), @@ -84,10 +77,9 @@ public class CrystalsWaypoint extends Waypoint { DRAGONS_LAIR("Dragon's Lair", Color.BLACK), CORLEONE("Corleone", Color.WHITE), KING("King", Color.RED), - DEFAULT("Default", Color.BLACK); + ODAWA("Odawa", Color.MAGENTA), + KEY_GUARDIAN("Key Guardian", Color.LIGHT_GRAY); - - private static final Codec CODEC = StringIdentifiable.createCodec(Category::values); public final Color color; private final String name; private final float[] colorComponents; @@ -98,18 +90,9 @@ public class CrystalsWaypoint extends Waypoint { this.colorComponents = color.getColorComponents(null); } - static Category get(JsonObject waypointJson) { - return CODEC.parse(JsonOps.INSTANCE, waypointJson.get("category")).resultOrPartial(LOGGER::error).orElse(Category.DEFAULT); - } - @Override public String toString() { return name; } - - @Override - public String asString() { - return name; - } } } -- cgit From 71467890a61eb4e05793b1856f6303787216f2ec Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Sun, 4 Feb 2024 12:36:35 -0500 Subject: Change King to King Yolkar --- src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java | 2 +- .../java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main/java/de') 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 447453cc..7b15c61e 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java @@ -26,7 +26,7 @@ public class CrystalsHud { private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); protected 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 = { "Fairy Grotto", "King", "Corleone", "Odawa", "Key Guardian" }; + private static final String[] SMALL_LOCATIONS = { "Fairy Grotto", "King Yolkar", "Corleone", "Odawa", "Key Guardian" }; public static boolean visible = false; 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 4c65aefb..fbb43083 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java @@ -76,7 +76,7 @@ public class CrystalsWaypoint extends Waypoint { FAIRY_GROTTO("Fairy Grotto", Color.PINK), DRAGONS_LAIR("Dragon's Lair", Color.BLACK), CORLEONE("Corleone", Color.WHITE), - KING("King", Color.RED), + KING_YOLKAR("King Yolkar", Color.RED), ODAWA("Odawa", Color.MAGENTA), KEY_GUARDIAN("Key Guardian", Color.LIGHT_GRAY); -- cgit