From ee300d371a670e5483f5bf983e43eff20f64e90d Mon Sep 17 00:00:00 2001 From: olim Date: Sun, 16 Jun 2024 21:35:39 +0100 Subject: replace crystal waypoints with mining lebels replace the use of crystal waypoints with mining labels so they can be read from the hole of the hollows --- .../skyblocker/skyblock/dwarven/CrystalsHud.java | 16 ++-- .../skyblock/dwarven/CrystalsLocationsManager.java | 28 +++---- .../skyblock/dwarven/CrystalsWaypoint.java | 98 ---------------------- .../skyblocker/skyblock/dwarven/MetalDetector.java | 13 ++- .../skyblock/dwarven/MiningLocationLabel.java | 61 ++++++++++++++ 5 files changed, 92 insertions(+), 124 deletions(-) delete mode 100644 src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java (limited to 'src/main/java/de/hysky/skyblocker') 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 7f4dbdbf..01d83b88 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java @@ -72,19 +72,19 @@ public class CrystalsHud { //if enabled add waypoint locations to map if (SkyblockerConfigManager.get().mining.crystalsHud.showLocations) { - Map ActiveWaypoints = CrystalsLocationsManager.activeWaypoints; + Map ActiveWaypoints = CrystalsLocationsManager.activeWaypoints; - for (CrystalsWaypoint waypoint : ActiveWaypoints.values()) { - Color waypointColor = waypoint.category.color; - Vector2ic renderPos = transformLocation(waypoint.pos.getX(), waypoint.pos.getZ()); + for (MiningLocationLabel waypoint : ActiveWaypoints.values()) { + int waypointColor = waypoint.category().getColor(); + Vector2ic renderPos = transformLocation(waypoint.centerPos().getX(), waypoint.centerPos().getZ()); int locationSize = SkyblockerConfigManager.get().mining.crystalsHud.locationSize; - if (SMALL_LOCATIONS.contains(waypoint.name.getString())) {//if small location half the location size + if (SMALL_LOCATIONS.contains(waypoint.category().getName())) {//if small location half the location size locationSize /= 2; } //fill square of size locationSize around the coordinates of the location - context.fill(renderPos.x() - locationSize / 2, renderPos.y() - locationSize / 2, renderPos.x() + locationSize / 2, renderPos.y() + locationSize / 2, waypointColor.getRGB()); + context.fill(renderPos.x() - locationSize / 2, renderPos.y() - locationSize / 2, renderPos.x() + locationSize / 2, renderPos.y() + locationSize / 2, waypointColor); } } @@ -92,7 +92,7 @@ public class CrystalsHud { if (CLIENT.player == null || CLIENT.getNetworkHandler() == null) { return; } - + //get player location double playerX = CLIENT.player.getX(); double playerZ = CLIENT.player.getZ(); @@ -109,8 +109,6 @@ public class CrystalsHud { //draw marker on map context.drawTexture(MAP_ICON, 0, 0, 2, 0, 5, 7, 8, 8); - - //todo add direction (can not work out how to rotate) matrices.pop(); } 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 83167c18..9bed7d50 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.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; import org.slf4j.Logger; import java.awt.*; @@ -52,12 +53,12 @@ public class CrystalsLocationsManager { private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); /** - * A look-up table to convert between location names and waypoint in the {@link CrystalsWaypoint.Category} values. + * A look-up table to convert between location names and waypoint in the {@link MiningLocationLabel.CrystalHollowsLocationsCategory} values. */ - private static final Map WAYPOINT_LOCATIONS = Arrays.stream(CrystalsWaypoint.Category.values()).collect(Collectors.toMap(CrystalsWaypoint.Category::toString, Function.identity())); + private static final Map WAYPOINT_LOCATIONS = Arrays.stream(MiningLocationLabel.CrystalHollowsLocationsCategory.values()).collect(Collectors.toMap(MiningLocationLabel.CrystalHollowsLocationsCategory::getName, 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<>(); + protected static Map activeWaypoints = new HashMap<>(); public static void init() { // Crystal Hollows Waypoints @@ -141,8 +142,8 @@ public class CrystalsLocationsManager { protected static Text getSetLocationMessage(String location, BlockPos blockPos) { MutableText text = Constants.PREFIX.get(); text.append(Text.literal("Added waypoint for ")); - Color locationColor = WAYPOINT_LOCATIONS.get(location).color; - text.append(Text.literal(location).withColor(locationColor.getRGB())); + int locationColor = WAYPOINT_LOCATIONS.get(location).getColor(); + text.append(Text.literal(location).withColor(locationColor)); text.append(Text.literal(" at : " + blockPos.getX() + " " + blockPos.getY() + " " + blockPos.getZ() + ".")); return text; @@ -152,8 +153,8 @@ public class CrystalsLocationsManager { 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)))); + int locationColor = WAYPOINT_LOCATIONS.get(waypointLocation).getColor(); + text.append(Text.literal("[" + waypointLocation + "]").withColor(locationColor).styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/skyblocker crystalWaypoints " + location + " " + waypointLocation)))); } return text; @@ -178,7 +179,7 @@ public class CrystalsLocationsManager { public static int shareWaypoint(String place) { if (activeWaypoints.containsKey(place)) { - BlockPos pos = activeWaypoints.get(place).pos; + Vec3d pos = activeWaypoints.get(place).centerPos(); MessageScheduler.INSTANCE.sendMessageAfterCooldown(Constants.PREFIX.get().getString() + " " + place + ": " + pos.getX() + ", " + pos.getY() + ", " + pos.getZ()); } else { //send fail message @@ -193,17 +194,16 @@ public class CrystalsLocationsManager { private static void addCustomWaypoint(String waypointName, BlockPos pos) { - CrystalsWaypoint.Category category = WAYPOINT_LOCATIONS.get(waypointName); - CrystalsWaypoint waypoint = new CrystalsWaypoint(category, Text.literal(waypointName), pos); + MiningLocationLabel.CrystalHollowsLocationsCategory category = WAYPOINT_LOCATIONS.get(waypointName); + MiningLocationLabel waypoint = new MiningLocationLabel(category, pos); activeWaypoints.put(waypointName, waypoint); } public static void render(WorldRenderContext context) { if (SkyblockerConfigManager.get().mining.crystalsWaypoints.enabled) { - for (CrystalsWaypoint crystalsWaypoint : activeWaypoints.values()) { - if (crystalsWaypoint.shouldRender()) { - crystalsWaypoint.render(context); - } + for (MiningLocationLabel crystalsWaypoint : activeWaypoints.values()) { + crystalsWaypoint.render(context); + } } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java deleted file mode 100644 index dc40f82c..00000000 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java +++ /dev/null @@ -1,98 +0,0 @@ -package de.hysky.skyblocker.skyblock.dwarven; - -import de.hysky.skyblocker.config.SkyblockerConfigManager; -import de.hysky.skyblocker.config.configs.UIAndVisualsConfig; -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.entity.Entity; -import net.minecraft.text.Text; -import net.minecraft.util.DyeColor; -import net.minecraft.util.Formatting; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3d; - -import java.awt.*; -import java.util.function.Predicate; -import java.util.function.Supplier; -import java.util.function.ToDoubleFunction; - -public class CrystalsWaypoint extends Waypoint { - private static final Supplier CONFIG = () -> SkyblockerConfigManager.get().uiAndVisuals.waypoints; - private static final Supplier TYPE_SUPPLIER = () -> CONFIG.get().waypointType; - final Category category; - final Text name; - private final Vec3d centerPos; - - 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) { - 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 for the different waypoints used int the crystals hud each with a {@link Category#name} and associated {@link Category#color} - */ - 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())), - 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.WHITE), - KING_YOLKAR("King Yolkar", Color.RED), - ODAWA("Odawa", Color.MAGENTA), - KEY_GUARDIAN("Key Guardian", Color.LIGHT_GRAY); - - public final Color color; - private final String name; - private final float[] colorComponents; - - Category(String name, Color color) { - this.name = name; - this.color = color; - this.colorComponents = color.getColorComponents(null); - } - - @Override - public String toString() { - return name; - } - } -} diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MetalDetector.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MetalDetector.java index 294b2c3d..9de636cc 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MetalDetector.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MetalDetector.java @@ -4,6 +4,7 @@ import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.utils.Constants; import de.hysky.skyblocker.utils.Utils; import de.hysky.skyblocker.utils.render.RenderHelper; +import de.hysky.skyblocker.utils.waypoint.Waypoint; 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; @@ -17,6 +18,7 @@ import net.minecraft.util.math.Box; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3i; +import java.awt.*; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -26,7 +28,7 @@ import java.util.regex.Pattern; public class MetalDetector { private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); - private static final float[] LIGHT_GRAY = { 192 / 255f, 192 / 255f, 192 / 255f }; + private static final float[] LIGHT_GRAY = {192 / 255f, 192 / 255f, 192 / 255f}; private static final Pattern TREASURE_PATTERN = Pattern.compile("(§3§lTREASURE: §b)(\\d+\\.?\\d?)m"); private static final Pattern KEEPER_PATTERN = Pattern.compile("Keeper of (\\w+)"); private static final Map keeperOffsets = Map.of( @@ -242,15 +244,20 @@ public class MetalDetector { //only one location render just that and guiding line to it if (possibleBlocks.size() == 1) { Vec3i block = possibleBlocks.getFirst().add(0, -1, 0); //the block you are taken to is one block above the chest - CrystalsWaypoint waypoint = new CrystalsWaypoint(CrystalsWaypoint.Category.CORLEONE, Text.translatable("skyblocker.dwarvenMines.metalDetectorHelper.treasure"), new BlockPos(block.getX(), block.getY(), block.getZ())); + Waypoint waypoint = new Waypoint(new BlockPos(block.getX(), block.getY(), block.getZ()), SkyblockerConfigManager.get().uiAndVisuals.waypoints.waypointType, Color.yellow.getColorComponents(null)); + MiningLocationLabel label = new MiningLocationLabel(MiningLocationLabel.CrystalHollowsOtherCategory.TREASURE, new Vec3d(block.getX() + 0.5, block.getY() + 1, block.getZ() + 0.5)); waypoint.render(context); + label.render(context); RenderHelper.renderLineFromCursor(context, Vec3d.ofCenter(block), LIGHT_GRAY, 1f, 5f); return; } for (Vec3i block : possibleBlocks) { - CrystalsWaypoint waypoint = new CrystalsWaypoint(CrystalsWaypoint.Category.CORLEONE, Text.translatable("skyblocker.dwarvenMines.metalDetectorHelper.possible"), new BlockPos(block.getX(), block.getY(), block.getZ())); + + Waypoint waypoint = new Waypoint(new BlockPos(block.getX(), block.getY(), block.getZ()), SkyblockerConfigManager.get().uiAndVisuals.waypoints.waypointType, Color.white.getColorComponents(null)); + MiningLocationLabel label = new MiningLocationLabel(MiningLocationLabel.CrystalHollowsOtherCategory.POSSIBLE_TREASURE, new Vec3d(block.getX() + 0.5, block.getY() + 1, block.getZ() + 0.5)); waypoint.render(context); + label.render(context); } } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java index 1f373b55..6cf5edcc 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java @@ -6,10 +6,13 @@ import de.hysky.skyblocker.utils.render.Renderable; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; import net.minecraft.client.MinecraftClient; import net.minecraft.text.Text; +import net.minecraft.util.DyeColor; import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; +import java.awt.*; + public record MiningLocationLabel(Category category, Vec3d centerPos) implements Renderable { public MiningLocationLabel(Category category, BlockPos pos) { this(category, pos.toCenterPos()); @@ -154,4 +157,62 @@ public record MiningLocationLabel(Category category, Vec3d centerPos) implements return color; } } + + /** + * enum for the different waypoints used int the crystals hud each with a {@link CrystalHollowsLocationsCategory#name} and associated {@link CrystalHollowsLocationsCategory#color} + */ + enum CrystalHollowsLocationsCategory implements 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())), + 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.WHITE), + KING_YOLKAR("King Yolkar", Color.RED), + ODAWA("Odawa", Color.MAGENTA), + KEY_GUARDIAN("Key Guardian", Color.LIGHT_GRAY); + + public final Color color; + private final String name; + + CrystalHollowsLocationsCategory(String name, Color color) { + this.name = name; + this.color = color; + } + + @Override + public String getName() { + return name; + } + + @Override + public int getColor() { + return this.color.getRGB(); + } + } + + enum CrystalHollowsOtherCategory implements Category { + TREASURE(Text.translatable("skyblocker.dwarvenMines.metalDetectorHelper.treasure") , Color.YELLOW), + POSSIBLE_TREASURE(Text.translatable("skyblocker.dwarvenMines.metalDetectorHelper.possible"), Color.WHITE); + + public final Color color; + private final String name; + + CrystalHollowsOtherCategory(Text name, Color color) { + this.name = name.getString(); + this.color = color; + } + + @Override + public String getName() { + return name; + } + + @Override + public int getColor() { + return this.color.getRGB(); + } + } } -- cgit From 42503766d848ca814f44537882b8a291ea63d496 Mon Sep 17 00:00:00 2001 From: olim Date: Sun, 16 Jun 2024 22:12:37 +0100 Subject: improve cword parssing take more location formats and partial matches for names --- .../skyblock/dwarven/CrystalsLocationsManager.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') 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 9bed7d50..91f6de3d 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -56,7 +56,7 @@ public class CrystalsLocationsManager { * A look-up table to convert between location names and waypoint in the {@link MiningLocationLabel.CrystalHollowsLocationsCategory} values. */ private static final Map WAYPOINT_LOCATIONS = Arrays.stream(MiningLocationLabel.CrystalHollowsLocationsCategory.values()).collect(Collectors.toMap(MiningLocationLabel.CrystalHollowsLocationsCategory::getName, 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])"); + 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<>(); @@ -73,7 +73,7 @@ public class CrystalsLocationsManager { } private static void extractLocationFromMessage(Text message, Boolean overlay) { - if (!SkyblockerConfigManager.get().mining.crystalsWaypoints.findInChat || !Utils.isInCrystalHollows()) { + if (!SkyblockerConfigManager.get().mining.crystalsWaypoints.findInChat || !Utils.isInCrystalHollows() || overlay) { return; } @@ -83,10 +83,8 @@ public class CrystalsLocationsManager { 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]); - + BlockPos blockPos = new BlockPos(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3))); + String location = blockPos.getX() + " " + blockPos.getY() + " " + blockPos.getZ(); //if position is not in the hollows do not add it if (!checkInCrystals(blockPos)) { return; @@ -94,7 +92,7 @@ public class CrystalsLocationsManager { //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 + if (Arrays.stream(waypointLocation.toLowerCase().split(" ")).anyMatch(word -> value.toLowerCase().contains(word)) ) { //check if contains a word of location //all data found to create waypoint addCustomWaypoint(waypointLocation, blockPos); return; -- cgit From cfb861de647e551a19096483a5d60fd10d676a63 Mon Sep 17 00:00:00 2001 From: olim Date: Mon, 17 Jun 2024 11:07:45 +0100 Subject: use named way-point for metal detector --- .../skyblocker/skyblock/dwarven/MetalDetector.java | 10 +++------- .../skyblock/dwarven/MiningLocationLabel.java | 22 ---------------------- 2 files changed, 3 insertions(+), 29 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MetalDetector.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MetalDetector.java index 9de636cc..ae45ff0b 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MetalDetector.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MetalDetector.java @@ -4,6 +4,7 @@ import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.utils.Constants; import de.hysky.skyblocker.utils.Utils; import de.hysky.skyblocker.utils.render.RenderHelper; +import de.hysky.skyblocker.utils.waypoint.NamedWaypoint; import de.hysky.skyblocker.utils.waypoint.Waypoint; import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; @@ -244,20 +245,15 @@ public class MetalDetector { //only one location render just that and guiding line to it if (possibleBlocks.size() == 1) { Vec3i block = possibleBlocks.getFirst().add(0, -1, 0); //the block you are taken to is one block above the chest - Waypoint waypoint = new Waypoint(new BlockPos(block.getX(), block.getY(), block.getZ()), SkyblockerConfigManager.get().uiAndVisuals.waypoints.waypointType, Color.yellow.getColorComponents(null)); - MiningLocationLabel label = new MiningLocationLabel(MiningLocationLabel.CrystalHollowsOtherCategory.TREASURE, new Vec3d(block.getX() + 0.5, block.getY() + 1, block.getZ() + 0.5)); + NamedWaypoint waypoint = new NamedWaypoint(new BlockPos(block.getX(), block.getY(), block.getZ()), Text.translatable("skyblocker.dwarvenMines.metalDetectorHelper.treasure").getString(), Color.yellow.getColorComponents(null)); waypoint.render(context); - label.render(context); RenderHelper.renderLineFromCursor(context, Vec3d.ofCenter(block), LIGHT_GRAY, 1f, 5f); return; } for (Vec3i block : possibleBlocks) { - - Waypoint waypoint = new Waypoint(new BlockPos(block.getX(), block.getY(), block.getZ()), SkyblockerConfigManager.get().uiAndVisuals.waypoints.waypointType, Color.white.getColorComponents(null)); - MiningLocationLabel label = new MiningLocationLabel(MiningLocationLabel.CrystalHollowsOtherCategory.POSSIBLE_TREASURE, new Vec3d(block.getX() + 0.5, block.getY() + 1, block.getZ() + 0.5)); + NamedWaypoint waypoint = new NamedWaypoint(new BlockPos(block.getX(), block.getY(), block.getZ()), Text.translatable("skyblocker.dwarvenMines.metalDetectorHelper.possible").getString(), Color.white.getColorComponents(null)); waypoint.render(context); - label.render(context); } } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java index 6cf5edcc..30f33aa2 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java @@ -193,26 +193,4 @@ public record MiningLocationLabel(Category category, Vec3d centerPos) implements } } - enum CrystalHollowsOtherCategory implements Category { - TREASURE(Text.translatable("skyblocker.dwarvenMines.metalDetectorHelper.treasure") , Color.YELLOW), - POSSIBLE_TREASURE(Text.translatable("skyblocker.dwarvenMines.metalDetectorHelper.possible"), Color.WHITE); - - public final Color color; - private final String name; - - CrystalHollowsOtherCategory(Text name, Color color) { - this.name = name.getString(); - this.color = color; - } - - @Override - public String getName() { - return name; - } - - @Override - public int getColor() { - return this.color.getRGB(); - } - } } -- cgit From 7b2efe7c86908ad87df36f296d057b70e7be1427 Mon Sep 17 00:00:00 2001 From: olim Date: Mon, 17 Jun 2024 17:42:13 +0100 Subject: add scanning for location chat scan for messages to improve locations and auto add King. also fix bugs just introduced --- .../skyblock/dwarven/CrystalsLocationsManager.java | 26 +++++++++++------- .../skyblock/dwarven/MiningLocationLabel.java | 31 +++++++++++++--------- 2 files changed, 36 insertions(+), 21 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') 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 91f6de3d..aa72007a 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -28,10 +28,10 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import org.slf4j.Logger; -import java.awt.*; import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -56,7 +56,7 @@ public class CrystalsLocationsManager { * A look-up table to convert between location names and waypoint in the {@link MiningLocationLabel.CrystalHollowsLocationsCategory} values. */ private static final Map WAYPOINT_LOCATIONS = Arrays.stream(MiningLocationLabel.CrystalHollowsLocationsCategory.values()).collect(Collectors.toMap(MiningLocationLabel.CrystalHollowsLocationsCategory::getName, 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])"); + private static final Pattern TEXT_CWORDS_PATTERN = Pattern.compile("([0-9][0-9][0-9])\\D*([0-9][0-9][0-9]?)\\D*([0-9][0-9][0-9])"); protected static Map activeWaypoints = new HashMap<>(); @@ -73,14 +73,13 @@ public class CrystalsLocationsManager { } private static void extractLocationFromMessage(Text message, Boolean overlay) { - if (!SkyblockerConfigManager.get().mining.crystalsWaypoints.findInChat || !Utils.isInCrystalHollows() || overlay) { + String text = Formatting.strip(message.getString()); + if (!SkyblockerConfigManager.get().mining.crystalsWaypoints.findInChat || !Utils.isInCrystalHollows() || overlay || text == null) { return; } - try { //get the message text - String value = message.getString(); - Matcher matcher = TEXT_CWORDS_PATTERN.matcher(value); + Matcher matcher = TEXT_CWORDS_PATTERN.matcher(text); //if there are coordinates in the message try to get them and what they are talking about if (matcher.find()) { BlockPos blockPos = new BlockPos(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3))); @@ -92,7 +91,7 @@ public class CrystalsLocationsManager { //see if there is a name of a location to add to this for (String waypointLocation : WAYPOINT_LOCATIONS.keySet()) { - if (Arrays.stream(waypointLocation.toLowerCase().split(" ")).anyMatch(word -> value.toLowerCase().contains(word)) ) { //check if contains a word of location + if (Arrays.stream(waypointLocation.toLowerCase().split(" ")).anyMatch(word -> text.toLowerCase().contains(word))) { //check if contains a word of location //all data found to create waypoint addCustomWaypoint(waypointLocation, blockPos); return; @@ -109,6 +108,16 @@ public class CrystalsLocationsManager { } catch (Exception e) { LOGGER.error("[Skyblocker Crystals Locations Manager] Encountered an exception while extracing a location from a chat message!", e); } + + //move waypoint to be more accurate based on locational chat messages + if (CLIENT.player != null) { + for (MiningLocationLabel.CrystalHollowsLocationsCategory waypointLocation : WAYPOINT_LOCATIONS.values()) { + String waypointLinkedMessage = waypointLocation.getLinkedMessage(); + if (waypointLinkedMessage != null && text.contains(waypointLinkedMessage)) { + addCustomWaypoint(waypointLocation.getName(), CLIENT.player.getBlockPos()); + } + } + } } protected static Boolean checkInCrystals(BlockPos pos) { @@ -178,7 +187,7 @@ public class CrystalsLocationsManager { public static int shareWaypoint(String place) { if (activeWaypoints.containsKey(place)) { Vec3d pos = activeWaypoints.get(place).centerPos(); - MessageScheduler.INSTANCE.sendMessageAfterCooldown(Constants.PREFIX.get().getString() + " " + place + ": " + pos.getX() + ", " + pos.getY() + ", " + pos.getZ()); + MessageScheduler.INSTANCE.sendMessageAfterCooldown(Constants.PREFIX.get().getString() + " " + place + ": " + (int) pos.getX() + ", " + (int) pos.getY() + ", " + (int) pos.getZ()); } else { //send fail message if (CLIENT.player == null || CLIENT.getNetworkHandler() == null) { @@ -201,7 +210,6 @@ public class CrystalsLocationsManager { if (SkyblockerConfigManager.get().mining.crystalsWaypoints.enabled) { for (MiningLocationLabel crystalsWaypoint : activeWaypoints.values()) { crystalsWaypoint.render(context); - } } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java index 30f33aa2..0fc0c64f 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java @@ -27,6 +27,7 @@ public record MiningLocationLabel(Category category, Vec3d centerPos) implements /** * Renders the name and distance to the label scaled so can be seen at a distance + * * @param context render context */ @Override @@ -162,24 +163,26 @@ public record MiningLocationLabel(Category category, Vec3d centerPos) implements * enum for the different waypoints used int the crystals hud each with a {@link CrystalHollowsLocationsCategory#name} and associated {@link CrystalHollowsLocationsCategory#color} */ enum CrystalHollowsLocationsCategory implements 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())), - 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.WHITE), - KING_YOLKAR("King Yolkar", Color.RED), - ODAWA("Odawa", Color.MAGENTA), - KEY_GUARDIAN("Key Guardian", Color.LIGHT_GRAY); + JUNGLE_TEMPLE("Jungle Temple", new Color(DyeColor.PURPLE.getSignColor()), "[NPC] Kalhuiki Door Guardian:"), + MINES_OF_DIVAN("Mines of Divan", Color.GREEN, " Jade Crystal"), + GOBLIN_QUEENS_DEN("Goblin Queen's Den", new Color(DyeColor.ORANGE.getSignColor()), " Amber Crystal"), + LOST_PRECURSOR_CITY("Lost Precursor City", Color.CYAN, " Sapphire Crystal"), + KHAZAD_DUM("Khazad-dûm", Color.YELLOW, " Topaz Crystal"), + FAIRY_GROTTO("Fairy Grotto", Color.PINK, null), + DRAGONS_LAIR("Dragon's Lair", Color.BLACK, null), + CORLEONE("Corleone", Color.WHITE, null), + KING_YOLKAR("King Yolkar", Color.RED, "[NPC] King Yolkar:"), + ODAWA("Odawa", Color.MAGENTA, "[NPC] Odawa:"), + KEY_GUARDIAN("Key Guardian", Color.LIGHT_GRAY, null); public final Color color; private final String name; + private final String linkedMessage; - CrystalHollowsLocationsCategory(String name, Color color) { + CrystalHollowsLocationsCategory(String name, Color color, String linkedMessage) { this.name = name; this.color = color; + this.linkedMessage = linkedMessage; } @Override @@ -191,6 +194,10 @@ public record MiningLocationLabel(Category category, Vec3d centerPos) implements public int getColor() { return this.color.getRGB(); } + + public String getLinkedMessage() { + return this.linkedMessage; + } } } -- cgit From 8fa21f0ec183da2e626cbe0ad2f95226308c9b9a Mon Sep 17 00:00:00 2001 From: olim Date: Wed, 19 Jun 2024 13:39:56 +0100 Subject: add wishing compass solver --- .../java/de/hysky/skyblocker/SkyblockerMod.java | 1 + .../mixins/ClientPlayNetworkHandlerMixin.java | 2 + .../skyblocker/mixins/PlayerListHudMixin.java | 6 + .../skyblock/dwarven/MiningLocationLabel.java | 1 + .../skyblock/dwarven/WishingCompassSolver.java | 357 +++++++++++++++++++++ .../skyblock/dwarven/WishingCompassSolverTest.java | 41 +++ 6 files changed, 408 insertions(+) create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java create mode 100644 src/test/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolverTest.java (limited to 'src/main/java/de/hysky/skyblocker') diff --git a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java index 8dd1419d..5cc96b42 100644 --- a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java +++ b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java @@ -136,6 +136,7 @@ public class SkyblockerMod implements ClientModInitializer { FarmingHud.init(); LowerSensitivity.init(); CrystalsLocationsManager.init(); + WishingCompassSolver.init(); MetalDetector.init(); ChatMessageListener.init(); Shortcuts.init(); diff --git a/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java b/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java index 7bbbac81..c0cd8b7b 100644 --- a/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java @@ -9,6 +9,7 @@ import de.hysky.skyblocker.skyblock.chocolatefactory.EggFinder; import de.hysky.skyblocker.skyblock.crimson.dojo.DojoManager; import de.hysky.skyblocker.skyblock.dungeon.DungeonScore; import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager; +import de.hysky.skyblocker.skyblock.dwarven.WishingCompassSolver; import de.hysky.skyblocker.skyblock.end.BeaconHighlighter; import de.hysky.skyblocker.skyblock.end.EnderNodes; import de.hysky.skyblocker.skyblock.end.TheEnd; @@ -100,6 +101,7 @@ public abstract class ClientPlayNetworkHandlerMixin { MythologicalRitual.onParticle(packet); DojoManager.onParticle(packet); EnderNodes.onParticle(packet); + WishingCompassSolver.onParticle(packet); } @ModifyExpressionValue(method = "onEntityStatus", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/play/EntityStatusS2CPacket;getEntity(Lnet/minecraft/world/World;)Lnet/minecraft/entity/Entity;")) diff --git a/src/main/java/de/hysky/skyblocker/mixins/PlayerListHudMixin.java b/src/main/java/de/hysky/skyblocker/mixins/PlayerListHudMixin.java index a96a7727..038d4e4f 100644 --- a/src/main/java/de/hysky/skyblocker/mixins/PlayerListHudMixin.java +++ b/src/main/java/de/hysky/skyblocker/mixins/PlayerListHudMixin.java @@ -12,6 +12,7 @@ import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.hud.PlayerListHud; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.text.Text; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -54,4 +55,9 @@ public class PlayerListHudMixin { } } + @Inject(at = @At("HEAD"), method = "setFooter") + public void skblocker$updateFooter(@Nullable Text footer, CallbackInfo info) { + PlayerListMgr.updateFooter(footer); + } + } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java index 0fc0c64f..964b6cce 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java @@ -163,6 +163,7 @@ public record MiningLocationLabel(Category category, Vec3d centerPos) implements * enum for the different waypoints used int the crystals hud each with a {@link CrystalHollowsLocationsCategory#name} and associated {@link CrystalHollowsLocationsCategory#color} */ enum CrystalHollowsLocationsCategory implements Category { + UNKNOWN("Unknown", Color.WHITE, null), //used when a location is known but what's at the location is not known JUNGLE_TEMPLE("Jungle Temple", new Color(DyeColor.PURPLE.getSignColor()), "[NPC] Kalhuiki Door Guardian:"), MINES_OF_DIVAN("Mines of Divan", Color.GREEN, " Jade Crystal"), GOBLIN_QUEENS_DEN("Goblin Queen's Den", new Color(DyeColor.ORANGE.getSignColor()), " Amber Crystal"), diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java new file mode 100644 index 00000000..48ceeb74 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java @@ -0,0 +1,357 @@ +package de.hysky.skyblocker.skyblock.dwarven; + +import de.hysky.skyblocker.skyblock.tabhud.util.PlayerListMgr; +import de.hysky.skyblocker.utils.Constants; +import de.hysky.skyblocker.utils.Utils; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; +import net.fabricmc.fabric.api.event.player.UseBlockCallback; +import net.fabricmc.fabric.api.event.player.UseItemCallback; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.PlayerListEntry; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.network.packet.s2c.play.ParticleS2CPacket; +import net.minecraft.particle.ParticleTypes; +import net.minecraft.text.Text; +import net.minecraft.util.*; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.Box; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Stream; + +public class WishingCompassSolver { + private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); + + enum SolverStates { + NOT_STARTED, + PROCESSING_FIRST_USE, + WAITING_FOR_SECOND, + PROCESSING_SECOND_USE, + } + + enum ZONE { + CRYSTAL_NUCLEUS, + JUNGLE, + MITHRIL_DEPOSITS, + GOBLIN_HOLDOUT, + PRECURSOR_REMNANTS, + MAGMA_FIELDS, + } + + private static final HashMap ZONE_BOUNDING_BOXES = Util.make(new HashMap<>(), map -> { + map.put(ZONE.CRYSTAL_NUCLEUS, new Box(462, 63, 461, 564, 181, 565)); + map.put(ZONE.JUNGLE, new Box(201, 63, 201, 513, 189, 513)); + map.put(ZONE.MITHRIL_DEPOSITS, new Box(512, 63, 201, 824, 189, 513)); + map.put(ZONE.GOBLIN_HOLDOUT, new Box(201, 63, 512, 513, 189, 824)); + map.put(ZONE.PRECURSOR_REMNANTS, new Box(512, 63, 512, 824, 189, 824)); + map.put(ZONE.MAGMA_FIELDS, new Box(201, 30, 201, 824, 64, 824)); + }); + private static final Vec3d JUNGLE_TEMPLE_DOOR_OFFSET = new Vec3d(-57, 36, -21); + /** + * how many particles to use to get direction of a line + */ + private static final long PARTICLES_PER_LINE = 25; + /** + * the amount of milliseconds to wait for the next particle until assumed failed + */ + private static final long PARTICLES_MAX_DELAY = 500; + /** + * the distance the player has to be from where they used the first compass to where they use the second + */ + private static final long DISTANCE_BETWEEN_USES = 32; + + private static SolverStates currentState = SolverStates.NOT_STARTED; + private static Vec3d startPosOne = Vec3d.ZERO; + private static Vec3d startPosTwo = Vec3d.ZERO; + private static Vec3d directionOne = Vec3d.ZERO; + private static Vec3d directionTwo = Vec3d.ZERO; + private static long particleUsedCountOne = 0; + private static long particleUsedCountTwo = 0; + private static long particleLastUpdate = System.currentTimeMillis(); + + + public static void init() { + UseItemCallback.EVENT.register(WishingCompassSolver::onItemInteract); + UseBlockCallback.EVENT.register(WishingCompassSolver::onBlockInteract); + ClientPlayConnectionEvents.JOIN.register((_handler, _sender, _client) -> reset()); + } + + private static void reset() { + currentState = SolverStates.NOT_STARTED; + startPosOne = Vec3d.ZERO; + startPosTwo = Vec3d.ZERO; + directionOne = Vec3d.ZERO; + directionTwo = Vec3d.ZERO; + particleUsedCountOne = 0; + particleUsedCountTwo = 0; + particleLastUpdate = System.currentTimeMillis(); + } + + private static boolean isKingsScentPresent() { + String footer = PlayerListMgr.getFooter(); + if (footer == null) { + return false; + } + return footer.contains("King's Scent I"); + } + + private static boolean isKeyInInventory() { + if (CLIENT.player == null) { + return false; + } + for (ItemStack item : CLIENT.player.getInventory().main) { + if (item != null && Objects.equals(item.getSkyblockId(), "JUNGLE_KEY")) { + return true; + } + } + return false; + } + + private static ZONE getZoneOfLocation(Vec3d location) { + for (Map.Entry zone : ZONE_BOUNDING_BOXES.entrySet()) { + if (zone.getValue().contains(location)) { + return zone.getKey(); + } + } + + //default to nucleus if somehow not in another zone + return ZONE.CRYSTAL_NUCLEUS; + } + + private static Boolean isZoneComplete(ZONE zone) { + if (CLIENT.getNetworkHandler() == null || CLIENT.player == null) { + return false; + } + //creates cleaned stream of all the entry's in tab list + Stream playerListStream = CLIENT.getNetworkHandler().getPlayerList().stream(); + Stream displayNameStream = playerListStream.map(PlayerListEntry::getDisplayName).filter(Objects::nonNull).map(Text::getString).map(String::strip); + + //make sure the data is in tab and if not tell the user + if (displayNameStream.noneMatch(entry -> entry.equals("Crystals:"))) { + CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.literal("Enable crystals in /tab so the compass can know what has been found")), false); + return false; + } + + //return if the crystal for a zone is found + playerListStream = CLIENT.getNetworkHandler().getPlayerList().stream(); + displayNameStream = playerListStream.map(PlayerListEntry::getDisplayName).filter(Objects::nonNull).map(Text::getString).map(String::strip); + return switch (zone) { + case JUNGLE -> displayNameStream.noneMatch(entry -> entry.equals("Amethyst: ✖ Not Found")); + case MITHRIL_DEPOSITS -> displayNameStream.noneMatch(entry -> entry.equals("Jade: ✖ Not Found")); + case GOBLIN_HOLDOUT -> displayNameStream.noneMatch(entry -> entry.equals("Amber: ✖ Not Found")); + case PRECURSOR_REMNANTS -> displayNameStream.noneMatch(entry -> entry.equals("Sapphire: ✖ Not Found")); + case MAGMA_FIELDS -> displayNameStream.noneMatch(entry -> entry.equals("Topaz: ✖ Not Found")); + default -> false; + }; + } + + private static MiningLocationLabel.CrystalHollowsLocationsCategory getTargetLocation(ZONE startingZone) { + //if the zone is complete return null + if (isZoneComplete(startingZone)) { + return MiningLocationLabel.CrystalHollowsLocationsCategory.UNKNOWN; + } + return switch (startingZone) { + case JUNGLE -> + isKeyInInventory() ? MiningLocationLabel.CrystalHollowsLocationsCategory.JUNGLE_TEMPLE : MiningLocationLabel.CrystalHollowsLocationsCategory.ODAWA; + case MITHRIL_DEPOSITS -> MiningLocationLabel.CrystalHollowsLocationsCategory.MINES_OF_DIVAN; + case GOBLIN_HOLDOUT -> + isKingsScentPresent() ? MiningLocationLabel.CrystalHollowsLocationsCategory.GOBLIN_QUEENS_DEN : MiningLocationLabel.CrystalHollowsLocationsCategory.KING_YOLKAR; + case PRECURSOR_REMNANTS -> MiningLocationLabel.CrystalHollowsLocationsCategory.LOST_PRECURSOR_CITY; + case MAGMA_FIELDS -> MiningLocationLabel.CrystalHollowsLocationsCategory.KHAZAD_DUM; + default -> MiningLocationLabel.CrystalHollowsLocationsCategory.UNKNOWN; + }; + } + + + public static void onParticle(ParticleS2CPacket packet) { + if (!Utils.isInCrystalHollows() || !ParticleTypes.HAPPY_VILLAGER.equals(packet.getParameters().getType())) { + return; + } + //get location of particle + Vec3d particlePos = new Vec3d(packet.getX(), packet.getY(), packet.getZ()); + //update particle used time + particleLastUpdate = System.currentTimeMillis(); + + switch (currentState) { + case PROCESSING_FIRST_USE -> { + Vec3d particleDirection = particlePos.subtract(startPosOne).normalize(); + //move direction to fit with particle + directionOne = directionOne.add(particleDirection.multiply((double) 1 / PARTICLES_PER_LINE)); + particleUsedCountOne += 1; + //if used enough particle go to next state + if (particleUsedCountOne >= PARTICLES_PER_LINE) { + currentState = SolverStates.WAITING_FOR_SECOND; + if (CLIENT.player != null) { + CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.literal("Wishing compass used. Move to another location and use another compass to triangulate target").formatted(Formatting.GREEN)), false); + } + } + } + case PROCESSING_SECOND_USE -> { + Vec3d particleDirection = particlePos.subtract(startPosTwo).normalize(); + //move direction to fit with particle + directionTwo = directionTwo.add(particleDirection.multiply((double) 1 / PARTICLES_PER_LINE)); + particleUsedCountTwo += 1; + //if used enough particle go to next state + if (particleUsedCountTwo >= PARTICLES_PER_LINE) { + processSolution(); + } + } + } + } + + private static void processSolution() { + if (CLIENT.player == null) { + reset(); + return; + } + Vec3d targetLocation = solve(startPosOne, startPosTwo, directionOne, directionTwo); + if (targetLocation == null) { + CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.literal("Something went wrong. lines do not cross. please try again").formatted(Formatting.RED)), false); + } else { + //send message to player with location and name + MiningLocationLabel.CrystalHollowsLocationsCategory location = getTargetLocation(getZoneOfLocation(startPosOne)); + //offset the jungle location to its doors + if (location == MiningLocationLabel.CrystalHollowsLocationsCategory.JUNGLE_TEMPLE) { + targetLocation = targetLocation.add(JUNGLE_TEMPLE_DOOR_OFFSET); + } + + CLIENT.player.sendMessage(Constants.PREFIX.get() + .append(Text.literal("Wishing compass solver found ").formatted(Formatting.GREEN)) + .append(Text.literal(location.getName()).withColor(location.getColor())) + .append(Text.literal(": " + (int) targetLocation.getX() + " " + (int) targetLocation.getY() + " " + (int) targetLocation.getZ())), + false); + } + + //reset ready for another go + reset(); + } + + /** + * using the stating locations and line direction solve for where the location must be + */ + protected static Vec3d solve(Vec3d startPosOne, Vec3d startPosTwo, Vec3d directionOne, Vec3d directionTwo) { + Vec3d crossProduct = directionOne.crossProduct(directionTwo); + if (crossProduct.equals(Vec3d.ZERO)) { + //lines are parallel or coincident + return null; + } + // Calculate the difference vector between startPosTwo and startPosOne + Vec3d diff = startPosTwo.subtract(startPosOne); + // projecting 'diff' onto the plane defined by 'directionTwo' and 'crossProduct'. then scaling by the inverse squared length of 'crossProduct' + double intersectionScalar = diff.dotProduct(directionTwo.crossProduct(crossProduct)) / crossProduct.lengthSquared(); + // if intersectionScalar is a negative number the lines are meeting in the opposite direction and giving incorrect cords + if (intersectionScalar < 0) { + return null; + } + //get final target location + return startPosOne.add(directionOne.multiply(intersectionScalar)); + } + + private static ActionResult onBlockInteract(PlayerEntity playerEntity, World world, Hand hand, BlockHitResult blockHitResult) { + if (CLIENT.player == null) { + return null; + } + ItemStack stack = CLIENT.player.getStackInHand(hand); + //make sure the user is in the crystal hollows and holding the wishing compass + if (!Utils.isInCrystalHollows() || !Objects.equals(stack.getSkyblockId(), "WISHING_COMPASS")) { + return ActionResult.PASS; + } + if (useCompass()) { + return ActionResult.FAIL; + } + + return ActionResult.PASS; + } + + private static TypedActionResult onItemInteract(PlayerEntity playerEntity, World world, Hand hand) { + if (CLIENT.player == null) { + return null; + } + ItemStack stack = CLIENT.player.getStackInHand(hand); + //make sure the user is in the crystal hollows and holding the wishing compass + if (!Utils.isInCrystalHollows() || !Objects.equals(stack.getSkyblockId(), "WISHING_COMPASS")) { + return TypedActionResult.pass(stack); + } + if (useCompass()) { + return TypedActionResult.fail(stack); + } + + return TypedActionResult.pass(stack); + } + + /** + * Computes what to do next when a compass is used. + * + * @return if the use event should be canceled + */ + private static boolean useCompass() { + if (CLIENT.player == null) { + return true; + } + Vec3d playerPos = CLIENT.player.getEyePos(); + ZONE currentZone = getZoneOfLocation(playerPos); + + switch (currentState) { + case NOT_STARTED -> { + //do not start if the player is in nucleus as this does not work well + if (currentZone == ZONE.CRYSTAL_NUCLEUS) { + CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.literal("Use compass outside of nucleus for better results")), false); + return true; + } + startNewState(SolverStates.PROCESSING_FIRST_USE); + } + + case WAITING_FOR_SECOND -> { + //only continue if the player is far enough away from the first position to get a better reading + if (startPosOne.distanceTo(playerPos) < DISTANCE_BETWEEN_USES) { + CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.literal("Move further away from the first use before using again")), false); + return true; + } else { + //make sure the player is in the same zone as they used to first or restart + if (currentZone != getZoneOfLocation(startPosOne)) { + CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.literal("Changed zone. Restarting...")), false); + startNewState(SolverStates.PROCESSING_FIRST_USE); + } else { + startNewState(SolverStates.PROCESSING_SECOND_USE); + } + } + } + + case PROCESSING_FIRST_USE, PROCESSING_SECOND_USE -> { + //if still looking for particles for line tell the user to wait + //else tell the use something went wrong and its starting again + if (System.currentTimeMillis() - particleLastUpdate < PARTICLES_MAX_DELAY) { + CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.literal("Wait a little before using another wishing compass").formatted(Formatting.RED)), false); + return true; + } else { + CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.literal("Could not detect last use. Restarting...").formatted(Formatting.RED)), false); + startNewState(SolverStates.PROCESSING_FIRST_USE); + } + } + } + + return false; + } + + private static void startNewState(SolverStates newState) { + if (CLIENT.player == null) { + return; + } + Vec3d playerPos = CLIENT.player.getEyePos(); + + if (newState == SolverStates.PROCESSING_FIRST_USE) { + currentState = SolverStates.PROCESSING_FIRST_USE; + startPosOne = playerPos; + particleLastUpdate = System.currentTimeMillis(); + } else if (newState == SolverStates.PROCESSING_SECOND_USE) { + currentState = SolverStates.PROCESSING_SECOND_USE; + startPosTwo = playerPos; + particleLastUpdate = System.currentTimeMillis(); + } + } +} diff --git a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolverTest.java b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolverTest.java new file mode 100644 index 00000000..c5a6ba19 --- /dev/null +++ b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolverTest.java @@ -0,0 +1,41 @@ +package de.hysky.skyblocker.skyblock.dwarven; + +import net.minecraft.util.math.Vec3d; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class WishingCompassSolverTest { + + @Test + void test2dSolve() { + Vec3d startPosOne = new Vec3d(100, 0, 0); + Vec3d startPosTwo = new Vec3d(0, 0, 100); + Vec3d directionOne = new Vec3d(-1, 0, 0); + Vec3d directionTwo = new Vec3d(0, 0, -1); + Assertions.assertEquals(WishingCompassSolver.solve(startPosOne, startPosTwo, directionOne, directionTwo), new Vec3d(0, 0, 0)); + + startPosOne = new Vec3d(100, 0, 100); + startPosTwo = new Vec3d(50, 0, 100); + directionOne = new Vec3d(-1, 0, -1); + directionTwo = new Vec3d(-0.5, 0, -1); + Assertions.assertEquals(WishingCompassSolver.solve(startPosOne, startPosTwo, directionOne, directionTwo), new Vec3d(0, 0, 0)); + } + + @Test + void test3dSolve() { + Vec3d startPosOne = new Vec3d(100, 100, 0); + Vec3d startPosTwo = new Vec3d(0, -100, 100); + Vec3d directionOne = new Vec3d(-1, -1, 0); + Vec3d directionTwo = new Vec3d(0, 1, -1); + Assertions.assertEquals(WishingCompassSolver.solve(startPosOne, startPosTwo, directionOne, directionTwo), new Vec3d(0, 0, 0)); + } + + @Test + void testParallelSolve() { + Vec3d startPosOne = new Vec3d(100, 0, 0); + Vec3d startPosTwo = new Vec3d(50, 0, 0); + Vec3d directionOne = new Vec3d(-1, 0, 0); + Vec3d directionTwo = new Vec3d(-1, 0, 0); + Assertions.assertNull(WishingCompassSolver.solve(startPosOne, startPosTwo, directionOne, directionTwo)); + } +} -- cgit From b3aa88019789eeec86627afd7e25e2edcd1dd675 Mon Sep 17 00:00:00 2001 From: olim Date: Wed, 19 Jun 2024 20:14:36 +0100 Subject: clean up some unwanted cwords being passed --- .../skyblock/dwarven/CrystalsLocationsManager.java | 50 ++++++++++++---------- .../skyblock/dwarven/WishingCompassSolver.java | 4 ++ 2 files changed, 32 insertions(+), 22 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') 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 aa72007a..0a3d6641 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -78,33 +78,39 @@ public class CrystalsLocationsManager { return; } try { - //get the message text - Matcher matcher = TEXT_CWORDS_PATTERN.matcher(text); - //if there are coordinates in the message try to get them and what they are talking about - if (matcher.find()) { - BlockPos blockPos = new BlockPos(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3))); - String location = blockPos.getX() + " " + blockPos.getY() + " " + blockPos.getZ(); - //if position is not in the hollows do not add it - if (!checkInCrystals(blockPos)) { - return; - } + //make sure that it is only reading user messages and not from skyblocker + if (text.contains(":") && !text.startsWith(Constants.PREFIX.get().getString())) { + String userMessage = text.split(":",2)[1]; + + //get the message text + Matcher matcher = TEXT_CWORDS_PATTERN.matcher(userMessage); + //if there are coordinates in the message try to get them and what they are talking about + if (matcher.find()) { + BlockPos blockPos = new BlockPos(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3))); + String location = blockPos.getX() + " " + blockPos.getY() + " " + blockPos.getZ(); + //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 (Arrays.stream(waypointLocation.toLowerCase().split(" ")).anyMatch(word -> userMessage.toLowerCase().contains(word))) { //check if contains a word of location + //all data found to create waypoint + addCustomWaypoint(waypointLocation, blockPos); + return; + } + } - //see if there is a name of a location to add to this - for (String waypointLocation : WAYPOINT_LOCATIONS.keySet()) { - if (Arrays.stream(waypointLocation.toLowerCase().split(" ")).anyMatch(word -> text.toLowerCase().contains(word))) { //check if contains a word of location - //all data found to create waypoint - addCustomWaypoint(waypointLocation, blockPos); + //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; } - } - //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); } - - 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); } @@ -200,7 +206,7 @@ public class CrystalsLocationsManager { } - private static void addCustomWaypoint(String waypointName, BlockPos pos) { + protected static void addCustomWaypoint(String waypointName, BlockPos pos) { MiningLocationLabel.CrystalHollowsLocationsCategory category = WAYPOINT_LOCATIONS.get(waypointName); MiningLocationLabel waypoint = new MiningLocationLabel(category, pos); activeWaypoints.put(waypointName, waypoint); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java index 48ceeb74..930bdad8 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java @@ -15,6 +15,7 @@ import net.minecraft.particle.ParticleTypes; import net.minecraft.text.Text; import net.minecraft.util.*; import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; @@ -225,6 +226,9 @@ public class WishingCompassSolver { .append(Text.literal(location.getName()).withColor(location.getColor())) .append(Text.literal(": " + (int) targetLocation.getX() + " " + (int) targetLocation.getY() + " " + (int) targetLocation.getZ())), false); + + //add waypoint + CrystalsLocationsManager.addCustomWaypoint(location.getName(), BlockPos.ofFloored(targetLocation)); } //reset ready for another go -- cgit From e30367c9b7b2370850e839e994d3c0bf95b3b9ad Mon Sep 17 00:00:00 2001 From: olim Date: Wed, 19 Jun 2024 20:47:38 +0100 Subject: add remove command and consistence add command to remove way-point and consistence for the add and share --- .../skyblock/dwarven/CrystalsLocationsManager.java | 39 +++++++++++++++++----- .../resources/assets/skyblocker/lang/en_us.json | 4 +++ 2 files changed, 35 insertions(+), 8 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') 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 0a3d6641..dd50e71e 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -80,7 +80,7 @@ public class CrystalsLocationsManager { try { //make sure that it is only reading user messages and not from skyblocker if (text.contains(":") && !text.startsWith(Constants.PREFIX.get().getString())) { - String userMessage = text.split(":",2)[1]; + String userMessage = text.split(":", 2)[1]; //get the message text Matcher matcher = TEXT_CWORDS_PATTERN.matcher(userMessage); @@ -136,16 +136,23 @@ public class CrystalsLocationsManager { private static void registerWaypointLocationCommands(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { dispatcher.register(literal(SkyblockerMod.NAMESPACE) .then(literal("crystalWaypoints") - .then(argument("pos", ClientBlockPosArgumentType.blockPos()) + .then(literal("add") + .then(argument("pos", BlockPosArgumentType.blockPos()) + .then(argument("place", StringArgumentType.greedyString()) + .suggests((context, builder) -> suggestMatching(WAYPOINT_LOCATIONS.keySet(), builder)) + .executes(context -> addWaypointFromCommand(context.getSource(), getString(context, "place"), context.getArgument("pos", ClientPosArgument.class))) + ) + )) + .then(literal("share") .then(argument("place", StringArgumentType.greedyString()) .suggests((context, builder) -> suggestMatching(WAYPOINT_LOCATIONS.keySet(), builder)) - .executes(context -> addWaypointFromCommand(context.getSource(), getString(context, "place"), context.getArgument("pos", ClientPosArgument.class))) + .executes(context -> shareWaypoint(getString(context, "place"))) ) ) - .then(literal("share") + .then(literal("remove") .then(argument("place", StringArgumentType.greedyString()) .suggests((context, builder) -> suggestMatching(WAYPOINT_LOCATIONS.keySet(), builder)) - .executes(context -> shareWaypoint(getString(context, "place"))) + .executes(context -> removeWaypoint(getString(context, "place"))) ) ) ) @@ -154,10 +161,11 @@ public class CrystalsLocationsManager { protected static Text getSetLocationMessage(String location, BlockPos blockPos) { MutableText text = Constants.PREFIX.get(); - text.append(Text.literal("Added waypoint for ")); + text.append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.addedWaypoint")); int locationColor = WAYPOINT_LOCATIONS.get(location).getColor(); text.append(Text.literal(location).withColor(locationColor)); - text.append(Text.literal(" at : " + blockPos.getX() + " " + blockPos.getY() + " " + blockPos.getZ() + ".")); + text.append(Text.literal(" ").append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.addedWaypoint.at"))); + text.append(Text.literal(" : " + blockPos.getX() + " " + blockPos.getY() + " " + blockPos.getZ() + ".")); return text; } @@ -167,7 +175,7 @@ public class CrystalsLocationsManager { for (String waypointLocation : WAYPOINT_LOCATIONS.keySet()) { int locationColor = WAYPOINT_LOCATIONS.get(waypointLocation).getColor(); - text.append(Text.literal("[" + waypointLocation + "]").withColor(locationColor).styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/skyblocker crystalWaypoints " + location + " " + waypointLocation)))); + text.append(Text.literal("[" + waypointLocation + "]").withColor(locationColor).styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/skyblocker crystalWaypoints add" + waypointLocation + " " + location)))); } return text; @@ -205,6 +213,21 @@ public class CrystalsLocationsManager { return Command.SINGLE_SUCCESS; } + public static int removeWaypoint(String place) { + if (CLIENT.player == null || CLIENT.getNetworkHandler() == null) { + return 0; + } + if (activeWaypoints.containsKey(place)) { + CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.removeSuccess").formatted(Formatting.GREEN)).append(Text.literal(place).withColor(WAYPOINT_LOCATIONS.get(place).getColor())), false); + activeWaypoints.remove(place); + } else { + //send fail message + CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.removeFail").formatted(Formatting.RED)), false); + } + + return Command.SINGLE_SUCCESS; + } + protected static void addCustomWaypoint(String waypointName, BlockPos pos) { MiningLocationLabel.CrystalHollowsLocationsCategory category = WAYPOINT_LOCATIONS.get(waypointName); diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index b7096424..8bdc5965 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -473,7 +473,11 @@ "skyblocker.config.mining.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. ", "skyblocker.config.mining.crystalsWaypoints.findInChat": "Find Waypoints In Chat", "skyblocker.config.mining.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", + "skyblocker.config.mining.crystalsWaypoints.addedWaypoint": "Added waypoint for ", + "skyblocker.config.mining.crystalsWaypoints.addedWaypoint.at": "at", "skyblocker.config.mining.crystalsWaypoints.shareFail": "Can only share waypoints you have found.", + "skyblocker.config.mining.crystalsWaypoints.removeSuccess": "Removed waypoint for ", + "skyblocker.config.mining.crystalsWaypoints.removeFail": "Can only remove waypoints you have found.", "skyblocker.config.mining.dwarvenHud": "Dwarven HUD", "skyblocker.config.mining.dwarvenHud.enabledCommissions": "Enable Commissions", -- cgit From c22843b1d2b34afe240df12d6129c980a0f6680c Mon Sep 17 00:00:00 2001 From: olim Date: Thu, 20 Jun 2024 00:42:52 +0100 Subject: add options to config and translations add option for wishing compass to config and translations for text in it. add separate scale for crystal waypoints and commissions --- .../config/categories/MiningCategory.java | 32 ++++++++++++++++------ .../skyblocker/config/configs/MiningConfig.java | 6 ++++ .../skyblock/dwarven/CrystalsLocationsManager.java | 2 +- .../skyblock/dwarven/MiningLocationLabel.java | 5 +++- .../skyblock/dwarven/WishingCompassSolver.java | 23 ++++++++-------- .../resources/assets/skyblocker/lang/en_us.json | 13 +++++++++ 6 files changed, 60 insertions(+), 21 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') diff --git a/src/main/java/de/hysky/skyblocker/config/categories/MiningCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/MiningCategory.java index 4e11d869..9828474b 100644 --- a/src/main/java/de/hysky/skyblocker/config/categories/MiningCategory.java +++ b/src/main/java/de/hysky/skyblocker/config/categories/MiningCategory.java @@ -166,6 +166,14 @@ public class MiningCategory { newValue -> config.mining.crystalsWaypoints.enabled = newValue) .controller(ConfigUtils::createBooleanController) .build()) + .option(Option.createBuilder() + .name(Text.translatable("skyblocker.config.mining.crystalsWaypoints.textScale")) + .description(OptionDescription.of(Text.translatable("skyblocker.config.mining.crystalsWaypoints.textScale.@Tooltip"))) + .binding(defaults.mining.crystalsWaypoints.textScale, + () -> config.mining.crystalsWaypoints.textScale, + newValue -> config.mining.crystalsWaypoints.textScale = newValue) + .controller(FloatFieldControllerBuilder::create) + .build()) .option(Option.createBuilder() .name(Text.translatable("skyblocker.config.mining.crystalsWaypoints.findInChat")) .description(OptionDescription.of(Text.translatable("skyblocker.config.mining.crystalsWaypoints.findInChat.@Tooltip"))) @@ -174,6 +182,14 @@ public class MiningCategory { newValue -> config.mining.crystalsWaypoints.findInChat = newValue) .controller(ConfigUtils::createBooleanController) .build()) + .option(Option.createBuilder() + .name(Text.translatable("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver")) + .description(OptionDescription.of(Text.translatable("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.@Tooltip"))) + .binding(defaults.mining.crystalsWaypoints.WishingCompassSolver, + () -> config.mining.crystalsWaypoints.WishingCompassSolver, + newValue -> config.mining.crystalsWaypoints.WishingCompassSolver = newValue) + .controller(ConfigUtils::createBooleanController) + .build()) .build()) @@ -193,14 +209,6 @@ public class MiningCategory { newValue -> config.mining.commissionWaypoints.mode = newValue) .controller(ConfigUtils::createEnumCyclingListController) .build()) - .option(Option.createBuilder() - .name(Text.translatable("skyblocker.config.mining.commissionWaypoints.useColor")) - .description(OptionDescription.of(Text.translatable("skyblocker.config.mining.commissionWaypoints.useColor.@Tooltip"))) - .binding(defaults.mining.commissionWaypoints.useColor, - () -> config.mining.commissionWaypoints.useColor, - newValue -> config.mining.commissionWaypoints.useColor = newValue) - .controller(ConfigUtils::createBooleanController) - .build()) .option(Option.createBuilder() .name(Text.translatable("skyblocker.config.mining.commissionWaypoints.textScale")) .description(OptionDescription.of(Text.translatable("skyblocker.config.mining.commissionWaypoints.textScale.@Tooltip"))) @@ -209,6 +217,14 @@ public class MiningCategory { newValue -> config.mining.commissionWaypoints.textScale = newValue) .controller(FloatFieldControllerBuilder::create) .build()) + .option(Option.createBuilder() + .name(Text.translatable("skyblocker.config.mining.commissionWaypoints.useColor")) + .description(OptionDescription.of(Text.translatable("skyblocker.config.mining.commissionWaypoints.useColor.@Tooltip"))) + .binding(defaults.mining.commissionWaypoints.useColor, + () -> config.mining.commissionWaypoints.useColor, + newValue -> config.mining.commissionWaypoints.useColor = newValue) + .controller(ConfigUtils::createBooleanController) + .build()) .option(Option.createBuilder() .name(Text.translatable("skyblocker.config.mining.commissionWaypoints.showBaseCamp")) .description(OptionDescription.of(Text.translatable("skyblocker.config.mining.commissionWaypoints.showBaseCamp.@Tooltip"))) diff --git a/src/main/java/de/hysky/skyblocker/config/configs/MiningConfig.java b/src/main/java/de/hysky/skyblocker/config/configs/MiningConfig.java index d71f57b6..7c74af80 100644 --- a/src/main/java/de/hysky/skyblocker/config/configs/MiningConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/configs/MiningConfig.java @@ -93,8 +93,14 @@ public class MiningConfig { @SerialEntry public boolean enabled = true; + @SerialEntry + public float textScale = 1; + @SerialEntry public boolean findInChat = true; + + @SerialEntry + public boolean WishingCompassSolver = true; } public static class CommissionWaypoints { 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 dd50e71e..3895d92d 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -116,7 +116,7 @@ public class CrystalsLocationsManager { } //move waypoint to be more accurate based on locational chat messages - if (CLIENT.player != null) { + if (CLIENT.player != null && SkyblockerConfigManager.get().mining.crystalsWaypoints.enabled) { for (MiningLocationLabel.CrystalHollowsLocationsCategory waypointLocation : WAYPOINT_LOCATIONS.values()) { String waypointLinkedMessage = waypointLocation.getLinkedMessage(); if (waypointLinkedMessage != null && text.contains(waypointLinkedMessage)) { diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java index 964b6cce..2c3409c5 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java @@ -1,6 +1,7 @@ package de.hysky.skyblocker.skyblock.dwarven; import de.hysky.skyblocker.config.SkyblockerConfigManager; +import de.hysky.skyblocker.utils.Utils; import de.hysky.skyblocker.utils.render.RenderHelper; import de.hysky.skyblocker.utils.render.Renderable; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; @@ -34,7 +35,9 @@ public record MiningLocationLabel(Category category, Vec3d centerPos) implements public void render(WorldRenderContext context) { Vec3d posUp = centerPos.add(0, 1, 0); double distance = context.camera().getPos().distanceTo(centerPos); - float scale = (float) (SkyblockerConfigManager.get().mining.commissionWaypoints.textScale * (distance / 10)); + //set scale config based on if in crystals or not + float textScale = Utils.isInCrystalHollows() ? SkyblockerConfigManager.get().mining.crystalsWaypoints.textScale : SkyblockerConfigManager.get().mining.commissionWaypoints.textScale; + float scale = (float) (textScale * (distance / 10)); RenderHelper.renderText(context, getName(), posUp, scale, true); RenderHelper.renderText(context, Text.literal(Math.round(distance) + "m").formatted(Formatting.YELLOW), posUp, scale, MinecraftClient.getInstance().textRenderer.fontHeight + 1, true); } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java index 930bdad8..7ba2e05a 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java @@ -1,5 +1,6 @@ package de.hysky.skyblocker.skyblock.dwarven; +import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.skyblock.tabhud.util.PlayerListMgr; import de.hysky.skyblocker.utils.Constants; import de.hysky.skyblocker.utils.Utils; @@ -134,7 +135,7 @@ public class WishingCompassSolver { //make sure the data is in tab and if not tell the user if (displayNameStream.noneMatch(entry -> entry.equals("Crystals:"))) { - CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.literal("Enable crystals in /tab so the compass can know what has been found")), false); + CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.literal("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.enableTabMessage")), false); return false; } @@ -188,7 +189,7 @@ public class WishingCompassSolver { if (particleUsedCountOne >= PARTICLES_PER_LINE) { currentState = SolverStates.WAITING_FOR_SECOND; if (CLIENT.player != null) { - CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.literal("Wishing compass used. Move to another location and use another compass to triangulate target").formatted(Formatting.GREEN)), false); + CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.wishingCompassUsedMessage").formatted(Formatting.GREEN)), false); } } } @@ -212,7 +213,7 @@ public class WishingCompassSolver { } Vec3d targetLocation = solve(startPosOne, startPosTwo, directionOne, directionTwo); if (targetLocation == null) { - CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.literal("Something went wrong. lines do not cross. please try again").formatted(Formatting.RED)), false); + CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.somethingWentWrongMessage").formatted(Formatting.RED)), false); } else { //send message to player with location and name MiningLocationLabel.CrystalHollowsLocationsCategory location = getTargetLocation(getZoneOfLocation(startPosOne)); @@ -222,7 +223,7 @@ public class WishingCompassSolver { } CLIENT.player.sendMessage(Constants.PREFIX.get() - .append(Text.literal("Wishing compass solver found ").formatted(Formatting.GREEN)) + .append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.foundMessage").formatted(Formatting.GREEN)) .append(Text.literal(location.getName()).withColor(location.getColor())) .append(Text.literal(": " + (int) targetLocation.getX() + " " + (int) targetLocation.getY() + " " + (int) targetLocation.getZ())), false); @@ -262,7 +263,7 @@ public class WishingCompassSolver { } ItemStack stack = CLIENT.player.getStackInHand(hand); //make sure the user is in the crystal hollows and holding the wishing compass - if (!Utils.isInCrystalHollows() || !Objects.equals(stack.getSkyblockId(), "WISHING_COMPASS")) { + if (!Utils.isInCrystalHollows() || !SkyblockerConfigManager.get().mining.crystalsWaypoints.WishingCompassSolver || !Objects.equals(stack.getSkyblockId(), "WISHING_COMPASS")) { return ActionResult.PASS; } if (useCompass()) { @@ -278,7 +279,7 @@ public class WishingCompassSolver { } ItemStack stack = CLIENT.player.getStackInHand(hand); //make sure the user is in the crystal hollows and holding the wishing compass - if (!Utils.isInCrystalHollows() || !Objects.equals(stack.getSkyblockId(), "WISHING_COMPASS")) { + if (!Utils.isInCrystalHollows() || !SkyblockerConfigManager.get().mining.crystalsWaypoints.WishingCompassSolver || !Objects.equals(stack.getSkyblockId(), "WISHING_COMPASS")) { return TypedActionResult.pass(stack); } if (useCompass()) { @@ -304,7 +305,7 @@ public class WishingCompassSolver { case NOT_STARTED -> { //do not start if the player is in nucleus as this does not work well if (currentZone == ZONE.CRYSTAL_NUCLEUS) { - CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.literal("Use compass outside of nucleus for better results")), false); + CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.useOutsideNucleusMessage")), false); return true; } startNewState(SolverStates.PROCESSING_FIRST_USE); @@ -313,12 +314,12 @@ public class WishingCompassSolver { case WAITING_FOR_SECOND -> { //only continue if the player is far enough away from the first position to get a better reading if (startPosOne.distanceTo(playerPos) < DISTANCE_BETWEEN_USES) { - CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.literal("Move further away from the first use before using again")), false); + CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.moveFurtherMessage")), false); return true; } else { //make sure the player is in the same zone as they used to first or restart if (currentZone != getZoneOfLocation(startPosOne)) { - CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.literal("Changed zone. Restarting...")), false); + CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.changingZoneMessage")), false); startNewState(SolverStates.PROCESSING_FIRST_USE); } else { startNewState(SolverStates.PROCESSING_SECOND_USE); @@ -330,10 +331,10 @@ public class WishingCompassSolver { //if still looking for particles for line tell the user to wait //else tell the use something went wrong and its starting again if (System.currentTimeMillis() - particleLastUpdate < PARTICLES_MAX_DELAY) { - CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.literal("Wait a little before using another wishing compass").formatted(Formatting.RED)), false); + CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.waitLongerMessage").formatted(Formatting.RED)), false); return true; } else { - CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.literal("Could not detect last use. Restarting...").formatted(Formatting.RED)), false); + CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.couldNotDetectLastUseMessage").formatted(Formatting.RED)), false); startNewState(SolverStates.PROCESSING_FIRST_USE); } } diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 8bdc5965..964e0a44 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -471,6 +471,8 @@ "skyblocker.config.mining.crystalsWaypoints": "Crystal Hollows Waypoints", "skyblocker.config.mining.crystalsWaypoints.enabled": "Enabled Waypoints", "skyblocker.config.mining.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. ", + "skyblocker.config.mining.crystalsWaypoints.textScale": "Text Scale", + "skyblocker.config.mining.crystalsWaypoints.textScale.@Tooltip": "Scale the size of the commission labels.", "skyblocker.config.mining.crystalsWaypoints.findInChat": "Find Waypoints In Chat", "skyblocker.config.mining.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", "skyblocker.config.mining.crystalsWaypoints.addedWaypoint": "Added waypoint for ", @@ -478,6 +480,17 @@ "skyblocker.config.mining.crystalsWaypoints.shareFail": "Can only share waypoints you have found.", "skyblocker.config.mining.crystalsWaypoints.removeSuccess": "Removed waypoint for ", "skyblocker.config.mining.crystalsWaypoints.removeFail": "Can only remove waypoints you have found.", + "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver": "Wishing Compass Solver", + "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.@Tooltip": "Works out and adds a waypoint to where a wishing compass points to", + "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.enableTabMessage": "Enable crystals in /tab so the compass can know what has been found", + "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.wishingCompassUsedMessage": "Wishing compass used. Move to another location and use another compass to triangulate target", + "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.somethingWentWrongMessage": "Something went wrong. lines do not cross. please try again", + "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.foundMessage": "Wishing compass solver found ", + "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.useOutsideNucleusMessage": "Use compass outside of nucleus for better results", + "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.moveFurtherMessage": "Move further away from the first use before using again", + "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.changingZoneMessage": "Changed zone. Restarting...", + "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.waitLongerMessage": "Wait a little before using another wishing compass", + "": "Could not detect last use. Restarting...", "skyblocker.config.mining.dwarvenHud": "Dwarven HUD", "skyblocker.config.mining.dwarvenHud.enabledCommissions": "Enable Commissions", -- cgit From 72c7a10e3e30b2502e7142d59a07b9aaecd5bedb Mon Sep 17 00:00:00 2001 From: olim Date: Thu, 20 Jun 2024 14:39:42 +0100 Subject: remove unknown waypoint when actual found close --- .../hysky/skyblocker/skyblock/dwarven/CrystalsHud.java | 2 +- .../skyblock/dwarven/CrystalsLocationsManager.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'src/main/java/de/hysky/skyblocker') 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 01d83b88..dae5885a 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java @@ -23,7 +23,7 @@ public class CrystalsHud { private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); protected static final Identifier MAP_TEXTURE = Identifier.of(SkyblockerMod.NAMESPACE, "textures/gui/crystals_map.png"); private static final Identifier MAP_ICON = Identifier.ofVanilla("textures/map/decorations/player.png"); - private static final List SMALL_LOCATIONS = List.of("Fairy Grotto", "King Yolkar", "Corleone", "Odawa", "Key Guardian"); + private static final List SMALL_LOCATIONS = List.of("Fairy Grotto", "King Yolkar", "Corleone", "Odawa", "Key Guardian", "Unknown"); 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 3895d92d..4c01ed4e 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -57,6 +57,7 @@ public class CrystalsLocationsManager { */ private static final Map WAYPOINT_LOCATIONS = Arrays.stream(MiningLocationLabel.CrystalHollowsLocationsCategory.values()).collect(Collectors.toMap(MiningLocationLabel.CrystalHollowsLocationsCategory::getName, Function.identity())); private static final Pattern TEXT_CWORDS_PATTERN = Pattern.compile("([0-9][0-9][0-9])\\D*([0-9][0-9][0-9]?)\\D*([0-9][0-9][0-9])"); + private static final int REMOVE_UNKNOWN_DISTANCE = 50; protected static Map activeWaypoints = new HashMap<>(); @@ -230,11 +231,27 @@ public class CrystalsLocationsManager { protected static void addCustomWaypoint(String waypointName, BlockPos pos) { + removeUnknownNear(pos); MiningLocationLabel.CrystalHollowsLocationsCategory category = WAYPOINT_LOCATIONS.get(waypointName); MiningLocationLabel waypoint = new MiningLocationLabel(category, pos); activeWaypoints.put(waypointName, waypoint); } + /** + * Removes unknown waypoint from active waypoints if it's close to a location + * @param location center location + */ + private static void removeUnknownNear(BlockPos location) { + String name = MiningLocationLabel.CrystalHollowsLocationsCategory.UNKNOWN.getName(); + MiningLocationLabel unknownWaypoint = activeWaypoints.getOrDefault(name, null); + if (unknownWaypoint != null) { + double distance = unknownWaypoint.centerPos().distanceTo(location.toCenterPos()); + if (distance < REMOVE_UNKNOWN_DISTANCE) { + activeWaypoints.remove(name); + } + } + } + public static void render(WorldRenderContext context) { if (SkyblockerConfigManager.get().mining.crystalsWaypoints.enabled) { for (MiningLocationLabel crystalsWaypoint : activeWaypoints.values()) { -- cgit From d03d158f8ca40572560f78285e646d4bb3b28d8e Mon Sep 17 00:00:00 2001 From: olim Date: Thu, 20 Jun 2024 15:18:55 +0100 Subject: make sure the location guess is sensible make sure its within 100 blocks of the players zone --- .../skyblocker/skyblock/dwarven/WishingCompassSolver.java | 15 ++++++++++++++- src/main/resources/assets/skyblocker/lang/en_us.json | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java index 7ba2e05a..ce1fdf55 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java @@ -169,6 +169,15 @@ public class WishingCompassSolver { }; } + /** + * Verify that a location could be correct and not to far out of zone. This is a problem when areas sometimes do not exist and is not a perfect solution + * @param startingZone zone player is searching in + * @param pos location where the area should be + * @return corrected location + */ + private static Boolean verifyLocation(ZONE startingZone, Vec3d pos) { + return ZONE_BOUNDING_BOXES.get(startingZone).expand(100, 0, 100).contains(pos); + } public static void onParticle(ParticleS2CPacket packet) { if (!Utils.isInCrystalHollows() || !ParticleTypes.HAPPY_VILLAGER.equals(packet.getParameters().getType())) { @@ -216,7 +225,11 @@ public class WishingCompassSolver { CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.somethingWentWrongMessage").formatted(Formatting.RED)), false); } else { //send message to player with location and name - MiningLocationLabel.CrystalHollowsLocationsCategory location = getTargetLocation(getZoneOfLocation(startPosOne)); + ZONE playerZone = getZoneOfLocation(startPosOne); + MiningLocationLabel.CrystalHollowsLocationsCategory location = getTargetLocation(playerZone); + if (!verifyLocation(playerZone, targetLocation)) { + location = MiningLocationLabel.CrystalHollowsLocationsCategory.UNKNOWN; + } //offset the jungle location to its doors if (location == MiningLocationLabel.CrystalHollowsLocationsCategory.JUNGLE_TEMPLE) { targetLocation = targetLocation.add(JUNGLE_TEMPLE_DOOR_OFFSET); diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 964e0a44..ce799fce 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -490,7 +490,7 @@ "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.moveFurtherMessage": "Move further away from the first use before using again", "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.changingZoneMessage": "Changed zone. Restarting...", "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.waitLongerMessage": "Wait a little before using another wishing compass", - "": "Could not detect last use. Restarting...", + "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.couldNotDetectLastUseMessage": "Could not detect last use. Restarting...", "skyblocker.config.mining.dwarvenHud": "Dwarven HUD", "skyblocker.config.mining.dwarvenHud.enabledCommissions": "Enable Commissions", -- cgit From 9af3163bb47a79e843c60b33f75ab7b515eaadfa Mon Sep 17 00:00:00 2001 From: olim Date: Thu, 20 Jun 2024 15:31:03 +0100 Subject: only use chat to verify messages once --- .../skyblock/dwarven/CrystalsLocationsManager.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') 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 4c01ed4e..d6debae5 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -28,10 +28,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import org.slf4j.Logger; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -60,6 +57,7 @@ public class CrystalsLocationsManager { private static final int REMOVE_UNKNOWN_DISTANCE = 50; protected static Map activeWaypoints = new HashMap<>(); + protected static List verifiedWaypoints = new ArrayList<>(); public static void init() { // Crystal Hollows Waypoints @@ -116,12 +114,14 @@ public class CrystalsLocationsManager { LOGGER.error("[Skyblocker Crystals Locations Manager] Encountered an exception while extracing a location from a chat message!", e); } - //move waypoint to be more accurate based on locational chat messages + //move waypoint to be more accurate based on locational chat messages if not already verifed if (CLIENT.player != null && SkyblockerConfigManager.get().mining.crystalsWaypoints.enabled) { for (MiningLocationLabel.CrystalHollowsLocationsCategory waypointLocation : WAYPOINT_LOCATIONS.values()) { String waypointLinkedMessage = waypointLocation.getLinkedMessage(); - if (waypointLinkedMessage != null && text.contains(waypointLinkedMessage)) { + String waypointName = waypointLocation.getName(); + if (waypointLinkedMessage != null && text.contains(waypointLinkedMessage) && !verifiedWaypoints.contains(waypointName)) { addCustomWaypoint(waypointLocation.getName(), CLIENT.player.getBlockPos()); + verifiedWaypoints.add(waypointName); } } } @@ -221,6 +221,7 @@ public class CrystalsLocationsManager { if (activeWaypoints.containsKey(place)) { CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.removeSuccess").formatted(Formatting.GREEN)).append(Text.literal(place).withColor(WAYPOINT_LOCATIONS.get(place).getColor())), false); activeWaypoints.remove(place); + verifiedWaypoints.remove(place); } else { //send fail message CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.removeFail").formatted(Formatting.RED)), false); @@ -262,6 +263,7 @@ public class CrystalsLocationsManager { private static void reset() { activeWaypoints.clear(); + verifiedWaypoints.clear(); } public static void update() { -- cgit From d5df86992795ac29a19ef8450e60ef5e7ee942f0 Mon Sep 17 00:00:00 2001 From: olim Date: Thu, 20 Jun 2024 15:45:06 +0100 Subject: fix command and increase accuracy fix clickable command text and use more particles for wishing compass making it a lot more accurate --- .../hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java | 2 +- .../de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') 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 d6debae5..f9fafc2a 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -176,7 +176,7 @@ public class CrystalsLocationsManager { for (String waypointLocation : WAYPOINT_LOCATIONS.keySet()) { int locationColor = WAYPOINT_LOCATIONS.get(waypointLocation).getColor(); - text.append(Text.literal("[" + waypointLocation + "]").withColor(locationColor).styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/skyblocker crystalWaypoints add" + waypointLocation + " " + location)))); + text.append(Text.literal("[" + waypointLocation + "]").withColor(locationColor).styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/skyblocker crystalWaypoints add " + location + " " + waypointLocation)))); } return text; diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java index ce1fdf55..338012e7 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java @@ -57,7 +57,7 @@ public class WishingCompassSolver { /** * how many particles to use to get direction of a line */ - private static final long PARTICLES_PER_LINE = 25; + private static final long PARTICLES_PER_LINE = 50; /** * the amount of milliseconds to wait for the next particle until assumed failed */ @@ -65,7 +65,7 @@ public class WishingCompassSolver { /** * the distance the player has to be from where they used the first compass to where they use the second */ - private static final long DISTANCE_BETWEEN_USES = 32; + private static final long DISTANCE_BETWEEN_USES = 8; private static SolverStates currentState = SolverStates.NOT_STARTED; private static Vec3d startPosOne = Vec3d.ZERO; -- cgit From 4f39561b850f7ceeb3d341aaf9c12a163742129f Mon Sep 17 00:00:00 2001 From: olim Date: Thu, 20 Jun 2024 17:24:54 +0100 Subject: fix bug --- .../java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/de/hysky/skyblocker') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java index 338012e7..eea71e62 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java @@ -135,7 +135,7 @@ public class WishingCompassSolver { //make sure the data is in tab and if not tell the user if (displayNameStream.noneMatch(entry -> entry.equals("Crystals:"))) { - CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.literal("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.enableTabMessage")), false); + CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.enableTabMessage")), false); return false; } -- cgit From 9cb1628090f7ddbfa29b4e54df45276f20f0adc1 Mon Sep 17 00:00:00 2001 From: olim Date: Thu, 20 Jun 2024 22:13:47 +0100 Subject: fix small bugs in compass --- .../skyblock/dwarven/WishingCompassSolver.java | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java index eea71e62..1befa57a 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java @@ -57,11 +57,15 @@ public class WishingCompassSolver { /** * how many particles to use to get direction of a line */ - private static final long PARTICLES_PER_LINE = 50; + private static final long PARTICLES_PER_LINE = 25; /** * the amount of milliseconds to wait for the next particle until assumed failed */ private static final long PARTICLES_MAX_DELAY = 500; + /** + * The maximum distance a particle can be from the last to be considered part of the line + */ + private static final double PARTICLES_MAX_DISTANCE = 0.9; /** * the distance the player has to be from where they used the first compass to where they use the second */ @@ -75,6 +79,7 @@ public class WishingCompassSolver { private static long particleUsedCountOne = 0; private static long particleUsedCountTwo = 0; private static long particleLastUpdate = System.currentTimeMillis(); + private static Vec3d particleLastPos = Vec3d.ZERO; public static void init() { @@ -92,6 +97,7 @@ public class WishingCompassSolver { particleUsedCountOne = 0; particleUsedCountTwo = 0; particleLastUpdate = System.currentTimeMillis(); + Vec3d particleLastPos = Vec3d.ZERO; } private static boolean isKingsScentPresent() { @@ -187,6 +193,11 @@ public class WishingCompassSolver { Vec3d particlePos = new Vec3d(packet.getX(), packet.getY(), packet.getZ()); //update particle used time particleLastUpdate = System.currentTimeMillis(); + //ignore particle not in the line + if (particlePos.distanceTo(particleLastPos) > PARTICLES_MAX_DISTANCE) { + return; + } + particleLastPos = particlePos; switch (currentState) { case PROCESSING_FIRST_USE -> { @@ -333,6 +344,7 @@ public class WishingCompassSolver { //make sure the player is in the same zone as they used to first or restart if (currentZone != getZoneOfLocation(startPosOne)) { CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.changingZoneMessage")), false); + reset(); startNewState(SolverStates.PROCESSING_FIRST_USE); } else { startNewState(SolverStates.PROCESSING_SECOND_USE); @@ -348,6 +360,7 @@ public class WishingCompassSolver { return true; } else { CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.couldNotDetectLastUseMessage").formatted(Formatting.RED)), false); + reset(); startNewState(SolverStates.PROCESSING_FIRST_USE); } } @@ -360,16 +373,19 @@ public class WishingCompassSolver { if (CLIENT.player == null) { return; } - Vec3d playerPos = CLIENT.player.getEyePos(); + //get where eye pos independent of if player is crouching + Vec3d playerPos = CLIENT.player.getPos().add(0, 1.62, 0); if (newState == SolverStates.PROCESSING_FIRST_USE) { currentState = SolverStates.PROCESSING_FIRST_USE; startPosOne = playerPos; particleLastUpdate = System.currentTimeMillis(); + particleLastPos = playerPos; } else if (newState == SolverStates.PROCESSING_SECOND_USE) { currentState = SolverStates.PROCESSING_SECOND_USE; startPosTwo = playerPos; particleLastUpdate = System.currentTimeMillis(); + particleLastPos = playerPos; } } } -- cgit From c79afcac08a92cb6515f7275e56dd99cb0430403 Mon Sep 17 00:00:00 2001 From: olim Date: Fri, 21 Jun 2024 15:00:28 +0100 Subject: use built in intersection method --- .../skyblock/dwarven/WishingCompassSolver.java | 29 ++++++++++++---------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java index 1befa57a..3c56c370 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java @@ -20,6 +20,8 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; +import org.apache.commons.math3.geometry.euclidean.threed.Line; +import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; import java.util.HashMap; import java.util.Map; @@ -264,21 +266,22 @@ public class WishingCompassSolver { * using the stating locations and line direction solve for where the location must be */ protected static Vec3d solve(Vec3d startPosOne, Vec3d startPosTwo, Vec3d directionOne, Vec3d directionTwo) { - Vec3d crossProduct = directionOne.crossProduct(directionTwo); - if (crossProduct.equals(Vec3d.ZERO)) { - //lines are parallel or coincident + //convert format to get lines for the intersection solving + Vector3D lineOneStart = new Vector3D(startPosOne.x, startPosOne.y, startPosOne.z); + Vector3D lineOneEnd = new Vector3D(directionOne.x, directionOne.y, directionOne.z).add(lineOneStart); + Vector3D lineTwoStart = new Vector3D(startPosTwo.x, startPosTwo.y, startPosTwo.z); + Vector3D lineTwoEnd = new Vector3D(directionTwo.x, directionTwo.y, directionTwo.z).add(lineTwoStart); + Line line = new Line(lineOneStart, lineOneEnd, 1); + Line lineTwo = new Line(lineTwoStart, lineTwoEnd, 1); + Vector3D intersection = line.intersection(lineTwo); + + //return final target location + if (intersection == null) { return null; } - // Calculate the difference vector between startPosTwo and startPosOne - Vec3d diff = startPosTwo.subtract(startPosOne); - // projecting 'diff' onto the plane defined by 'directionTwo' and 'crossProduct'. then scaling by the inverse squared length of 'crossProduct' - double intersectionScalar = diff.dotProduct(directionTwo.crossProduct(crossProduct)) / crossProduct.lengthSquared(); - // if intersectionScalar is a negative number the lines are meeting in the opposite direction and giving incorrect cords - if (intersectionScalar < 0) { - return null; - } - //get final target location - return startPosOne.add(directionOne.multiply(intersectionScalar)); + return new Vec3d(intersection.getX(), intersection.getY(), intersection.getZ()); + + } private static ActionResult onBlockInteract(PlayerEntity playerEntity, World world, Hand hand, BlockHitResult blockHitResult) { -- cgit From 97bc7cdd63b01474b46f7962a9b7ac4113958c1b Mon Sep 17 00:00:00 2001 From: olim Date: Fri, 21 Jun 2024 15:07:16 +0100 Subject: fix when parallel for some reason the library function returns 0 instead of null if parallel --- .../java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/de/hysky/skyblocker') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java index 3c56c370..566af8e7 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java @@ -276,7 +276,7 @@ public class WishingCompassSolver { Vector3D intersection = line.intersection(lineTwo); //return final target location - if (intersection == null) { + if (intersection == null || intersection.equals(new Vector3D(0, 0, 0))) { return null; } return new Vec3d(intersection.getX(), intersection.getY(), intersection.getZ()); -- cgit From 8c14a57681e0fabb113b51e4c066c2b4ddf8ab03 Mon Sep 17 00:00:00 2001 From: olim Date: Wed, 26 Jun 2024 12:05:44 +0100 Subject: fix issues fix issues. and remove unnecessary square root --- src/main/java/de/hysky/skyblocker/mixins/PlayerListHudMixin.java | 2 -- .../hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') diff --git a/src/main/java/de/hysky/skyblocker/mixins/PlayerListHudMixin.java b/src/main/java/de/hysky/skyblocker/mixins/PlayerListHudMixin.java index 038d4e4f..2c7fde47 100644 --- a/src/main/java/de/hysky/skyblocker/mixins/PlayerListHudMixin.java +++ b/src/main/java/de/hysky/skyblocker/mixins/PlayerListHudMixin.java @@ -43,8 +43,6 @@ public class PlayerListHudMixin { w = (int) (w / scale); h = (int) (h / scale); - PlayerListMgr.updateFooter(footer); - try { ScreenMaster.render(context, w,h); // Screen screen = Screen.getCorrect(w, h, footer); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java index 566af8e7..f028e3e7 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java @@ -69,9 +69,9 @@ public class WishingCompassSolver { */ private static final double PARTICLES_MAX_DISTANCE = 0.9; /** - * the distance the player has to be from where they used the first compass to where they use the second + * the distance squared the player has to be from where they used the first compass to where they use the second */ - private static final long DISTANCE_BETWEEN_USES = 8; + private static final long DISTANCE_BETWEEN_USES = 64; private static SolverStates currentState = SolverStates.NOT_STARTED; private static Vec3d startPosOne = Vec3d.ZERO; @@ -340,7 +340,7 @@ public class WishingCompassSolver { case WAITING_FOR_SECOND -> { //only continue if the player is far enough away from the first position to get a better reading - if (startPosOne.distanceTo(playerPos) < DISTANCE_BETWEEN_USES) { + if (startPosOne.squaredDistanceTo(playerPos) < DISTANCE_BETWEEN_USES) { CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.moveFurtherMessage")), false); return true; } else { @@ -357,7 +357,7 @@ public class WishingCompassSolver { case PROCESSING_FIRST_USE, PROCESSING_SECOND_USE -> { //if still looking for particles for line tell the user to wait - //else tell the use something went wrong and its starting again + //else tell the user something went wrong and its starting again if (System.currentTimeMillis() - particleLastUpdate < PARTICLES_MAX_DELAY) { CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.waitLongerMessage").formatted(Formatting.RED)), false); return true; -- cgit From f486e1171a41e22d041f2c10c42d2831fd7b7311 Mon Sep 17 00:00:00 2001 From: olim Date: Mon, 1 Jul 2024 15:31:27 +0100 Subject: look for failed message in chat and reset with it --- .../skyblocker/skyblock/dwarven/WishingCompassSolver.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/main/java/de/hysky/skyblocker') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java index f028e3e7..84cd4803 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java @@ -4,6 +4,7 @@ import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.skyblock.tabhud.util.PlayerListMgr; import de.hysky.skyblocker.utils.Constants; import de.hysky.skyblocker.utils.Utils; +import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.fabricmc.fabric.api.event.player.UseBlockCallback; import net.fabricmc.fabric.api.event.player.UseItemCallback; @@ -87,9 +88,21 @@ public class WishingCompassSolver { public static void init() { UseItemCallback.EVENT.register(WishingCompassSolver::onItemInteract); UseBlockCallback.EVENT.register(WishingCompassSolver::onBlockInteract); + ClientReceiveMessageEvents.GAME.register(WishingCompassSolver::failMessageListener); ClientPlayConnectionEvents.JOIN.register((_handler, _sender, _client) -> reset()); } + /** + * When a filed message is sent in chat reset the wishing compass solver to start + * @param text message + * @param b overlay + */ + private static void failMessageListener(Text text, boolean b) { + if (Formatting.strip(text.getString()).equals("The Wishing Compass can't seem to locate anything!")) { + currentState = SolverStates.NOT_STARTED; + } + } + private static void reset() { currentState = SolverStates.NOT_STARTED; startPosOne = Vec3d.ZERO; -- cgit From 1bf1e29ff8d65c2930997fe9a7b81be611ddbf7f Mon Sep 17 00:00:00 2001 From: olim Date: Tue, 9 Jul 2024 15:44:37 +0100 Subject: adds location selection menu for share add and remove when the player just types add share and remove to commands without arguments bring up a menu in chat to select the location to use for that action --- .../skyblock/dwarven/CrystalsLocationsManager.java | 67 +++++++++++++++++++++- .../resources/assets/skyblocker/lang/en_us.json | 2 + 2 files changed, 66 insertions(+), 3 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') 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 f9fafc2a..4364d8bc 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -106,7 +106,7 @@ public class CrystalsLocationsManager { return; } - CLIENT.player.sendMessage(getLocationInputText(location), false); + CLIENT.player.sendMessage(getLocationMenu(location, false), false); } } @@ -138,6 +138,13 @@ public class CrystalsLocationsManager { dispatcher.register(literal(SkyblockerMod.NAMESPACE) .then(literal("crystalWaypoints") .then(literal("add") + .executes(context -> { + if (CLIENT.player == null) { + return 0; + } + CLIENT.player.sendMessage(getLocationMenu((int) CLIENT.player.getX() + " " + (int) CLIENT.player.getY() + " " + (int) CLIENT.player.getZ(), true), false); + return Command.SINGLE_SUCCESS; + }) .then(argument("pos", BlockPosArgumentType.blockPos()) .then(argument("place", StringArgumentType.greedyString()) .suggests((context, builder) -> suggestMatching(WAYPOINT_LOCATIONS.keySet(), builder)) @@ -145,12 +152,26 @@ public class CrystalsLocationsManager { ) )) .then(literal("share") + .executes(context -> { + if (CLIENT.player == null) { + return 0; + } + CLIENT.player.sendMessage(getPlacesMenu("share"), false); + return Command.SINGLE_SUCCESS; + }) .then(argument("place", StringArgumentType.greedyString()) .suggests((context, builder) -> suggestMatching(WAYPOINT_LOCATIONS.keySet(), builder)) .executes(context -> shareWaypoint(getString(context, "place"))) ) ) .then(literal("remove") + .executes(context -> { + if (CLIENT.player == null) { + return 0; + } + CLIENT.player.sendMessage(getPlacesMenu("remove"), false); + return Command.SINGLE_SUCCESS; + }) .then(argument("place", StringArgumentType.greedyString()) .suggests((context, builder) -> suggestMatching(WAYPOINT_LOCATIONS.keySet(), builder)) .executes(context -> removeWaypoint(getString(context, "place"))) @@ -171,10 +192,26 @@ public class CrystalsLocationsManager { return text; } - private static Text getLocationInputText(String location) { + /** + * Creates a formated text with a list of possible places to add a waypoint for + * + * @param location the location where the waypoint will be created + * @param excludeUnknown if the "Unknown" location should be available to add + * @return text for a message to send to the player + */ + private static Text getLocationMenu(String location, boolean excludeUnknown) { MutableText text = Constants.PREFIX.get(); + //if the user has all available waypoints active warn them instead of an empty list (excused unknown from check when disabled) + if (activeWaypoints.size() == WAYPOINT_LOCATIONS.size() || (excludeUnknown && WAYPOINT_LOCATIONS.size() - activeWaypoints.size() == 1 && !activeWaypoints.containsKey(MiningLocationLabel.CrystalHollowsLocationsCategory.UNKNOWN.getName()))) { + return text.append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.allActive").formatted(Formatting.RED)); + } + for (String waypointLocation : WAYPOINT_LOCATIONS.keySet()) { + //do not show option to add waypoints for existing locations or unknown if its disabled + if (activeWaypoints.containsKey(waypointLocation) || (excludeUnknown && Objects.equals(waypointLocation, MiningLocationLabel.CrystalHollowsLocationsCategory.UNKNOWN.getName()))) { + continue; + } int locationColor = WAYPOINT_LOCATIONS.get(waypointLocation).getColor(); text.append(Text.literal("[" + waypointLocation + "]").withColor(locationColor).styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/skyblocker crystalWaypoints add " + location + " " + waypointLocation)))); } @@ -182,6 +219,29 @@ public class CrystalsLocationsManager { return text; } + + /** + * Creates a formated text with a list of found places to remove / share a waypoint for + * + * @param action the action the command should perform (remove / share) + * @return text for a message to send to the player + */ + private static Text getPlacesMenu(String action) { + MutableText text = Constants.PREFIX.get(); + + //if the user has no active warn them instead of an empty list + if (activeWaypoints.isEmpty()) { + return text.append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.noActive").formatted(Formatting.RED)); + } + + for (String waypointLocation : activeWaypoints.keySet()) { + int locationColor = WAYPOINT_LOCATIONS.get(waypointLocation).getColor(); + text.append(Text.literal("[" + waypointLocation + "]").withColor(locationColor).styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/skyblocker crystalWaypoints " + action + " " + waypointLocation)))); + } + + return text; + } + public static int addWaypointFromCommand(FabricClientCommandSource source, String place, ClientPosArgument location) { BlockPos blockPos = location.toAbsoluteBlockPos(source); @@ -240,11 +300,12 @@ public class CrystalsLocationsManager { /** * Removes unknown waypoint from active waypoints if it's close to a location + * * @param location center location */ private static void removeUnknownNear(BlockPos location) { String name = MiningLocationLabel.CrystalHollowsLocationsCategory.UNKNOWN.getName(); - MiningLocationLabel unknownWaypoint = activeWaypoints.getOrDefault(name, null); + MiningLocationLabel unknownWaypoint = activeWaypoints.getOrDefault(name, null); if (unknownWaypoint != null) { double distance = unknownWaypoint.centerPos().distanceTo(location.toCenterPos()); if (distance < REMOVE_UNKNOWN_DISTANCE) { diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index ce799fce..f323641a 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -477,6 +477,8 @@ "skyblocker.config.mining.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", "skyblocker.config.mining.crystalsWaypoints.addedWaypoint": "Added waypoint for ", "skyblocker.config.mining.crystalsWaypoints.addedWaypoint.at": "at", + "skyblocker.config.mining.crystalsWaypoints.noActive": "You have no active waypoints to share or remove.", + "skyblocker.config.mining.crystalsWaypoints.allActive": "You have no more waypoints left to create.", "skyblocker.config.mining.crystalsWaypoints.shareFail": "Can only share waypoints you have found.", "skyblocker.config.mining.crystalsWaypoints.removeSuccess": "Removed waypoint for ", "skyblocker.config.mining.crystalsWaypoints.removeFail": "Can only remove waypoints you have found.", -- cgit From 5c20347f8a2a0bbad3f0c04264e52cb02b3057a7 Mon Sep 17 00:00:00 2001 From: olim Date: Wed, 10 Jul 2024 12:30:59 +0100 Subject: implement requested changes fix formatting of code in place to be correct --- .../de/hysky/skyblocker/config/categories/MiningCategory.java | 6 +++--- .../java/de/hysky/skyblocker/config/configs/MiningConfig.java | 2 +- .../java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java | 8 +++----- .../skyblocker/skyblock/dwarven/CrystalsLocationsManager.java | 5 +++-- .../hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java | 7 +++++-- 5 files changed, 15 insertions(+), 13 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') diff --git a/src/main/java/de/hysky/skyblocker/config/categories/MiningCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/MiningCategory.java index 9828474b..796a6105 100644 --- a/src/main/java/de/hysky/skyblocker/config/categories/MiningCategory.java +++ b/src/main/java/de/hysky/skyblocker/config/categories/MiningCategory.java @@ -185,9 +185,9 @@ public class MiningCategory { .option(Option.createBuilder() .name(Text.translatable("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver")) .description(OptionDescription.of(Text.translatable("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.@Tooltip"))) - .binding(defaults.mining.crystalsWaypoints.WishingCompassSolver, - () -> config.mining.crystalsWaypoints.WishingCompassSolver, - newValue -> config.mining.crystalsWaypoints.WishingCompassSolver = newValue) + .binding(defaults.mining.crystalsWaypoints.wishingCompassSolver, + () -> config.mining.crystalsWaypoints.wishingCompassSolver, + newValue -> config.mining.crystalsWaypoints.wishingCompassSolver = newValue) .controller(ConfigUtils::createBooleanController) .build()) diff --git a/src/main/java/de/hysky/skyblocker/config/configs/MiningConfig.java b/src/main/java/de/hysky/skyblocker/config/configs/MiningConfig.java index 7c74af80..1347f158 100644 --- a/src/main/java/de/hysky/skyblocker/config/configs/MiningConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/configs/MiningConfig.java @@ -100,7 +100,7 @@ public class MiningConfig { public boolean findInChat = true; @SerialEntry - public boolean WishingCompassSolver = true; + public boolean wishingCompassSolver = true; } public static class CommissionWaypoints { 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 dae5885a..30bf6b03 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java @@ -54,8 +54,8 @@ 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 hudX Top left X coordinate of the map - * @param hudY Top left Y coordinate of the map + * @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) { float scale = SkyblockerConfigManager.get().mining.crystalsHud.mapScaling; @@ -72,7 +72,7 @@ public class CrystalsHud { //if enabled add waypoint locations to map if (SkyblockerConfigManager.get().mining.crystalsHud.showLocations) { - Map ActiveWaypoints = CrystalsLocationsManager.activeWaypoints; + Map ActiveWaypoints = CrystalsLocationsManager.activeWaypoints; for (MiningLocationLabel waypoint : ActiveWaypoints.values()) { int waypointColor = waypoint.category().getColor(); @@ -92,7 +92,6 @@ public class CrystalsHud { if (CLIENT.player == null || CLIENT.getNetworkHandler() == null) { return; } - //get player location double playerX = CLIENT.player.getX(); double playerZ = CLIENT.player.getZ(); @@ -144,7 +143,6 @@ public class CrystalsHud { /** * 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().mining.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 4364d8bc..ddf1fbd4 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -72,10 +72,11 @@ public class CrystalsLocationsManager { } private static void extractLocationFromMessage(Text message, Boolean overlay) { - String text = Formatting.strip(message.getString()); - if (!SkyblockerConfigManager.get().mining.crystalsWaypoints.findInChat || !Utils.isInCrystalHollows() || overlay || text == null) { + + if (!SkyblockerConfigManager.get().mining.crystalsWaypoints.findInChat || !Utils.isInCrystalHollows() || overlay) { return; } + String text = Formatting.strip(message.getString()); try { //make sure that it is only reading user messages and not from skyblocker if (text.contains(":") && !text.startsWith(Constants.PREFIX.get().getString())) { diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java index 84cd4803..7e7386f0 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java @@ -98,6 +98,9 @@ public class WishingCompassSolver { * @param b overlay */ private static void failMessageListener(Text text, boolean b) { + if (!Utils.isInCrystalHollows()){ + return; + } if (Formatting.strip(text.getString()).equals("The Wishing Compass can't seem to locate anything!")) { currentState = SolverStates.NOT_STARTED; } @@ -303,7 +306,7 @@ public class WishingCompassSolver { } ItemStack stack = CLIENT.player.getStackInHand(hand); //make sure the user is in the crystal hollows and holding the wishing compass - if (!Utils.isInCrystalHollows() || !SkyblockerConfigManager.get().mining.crystalsWaypoints.WishingCompassSolver || !Objects.equals(stack.getSkyblockId(), "WISHING_COMPASS")) { + if (!Utils.isInCrystalHollows() || !SkyblockerConfigManager.get().mining.crystalsWaypoints.wishingCompassSolver || !Objects.equals(stack.getSkyblockId(), "WISHING_COMPASS")) { return ActionResult.PASS; } if (useCompass()) { @@ -319,7 +322,7 @@ public class WishingCompassSolver { } ItemStack stack = CLIENT.player.getStackInHand(hand); //make sure the user is in the crystal hollows and holding the wishing compass - if (!Utils.isInCrystalHollows() || !SkyblockerConfigManager.get().mining.crystalsWaypoints.WishingCompassSolver || !Objects.equals(stack.getSkyblockId(), "WISHING_COMPASS")) { + if (!Utils.isInCrystalHollows() || !SkyblockerConfigManager.get().mining.crystalsWaypoints.wishingCompassSolver || !Objects.equals(stack.getSkyblockId(), "WISHING_COMPASS")) { return TypedActionResult.pass(stack); } if (useCompass()) { -- cgit From e308b09fd59b014e783e2ae6022f64f3962b123f Mon Sep 17 00:00:00 2001 From: olim Date: Wed, 10 Jul 2024 12:37:14 +0100 Subject: do not overwite esisting waypoints when incoming chat message with waypoint locations make sure the waypoint does not already exist in active waypoints, so waypoints can not get randomly moved --- .../hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/main/java/de/hysky/skyblocker') 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 ddf1fbd4..2a21776e 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,10 @@ public class CrystalsLocationsManager { for (String waypointLocation : WAYPOINT_LOCATIONS.keySet()) { if (Arrays.stream(waypointLocation.toLowerCase().split(" ")).anyMatch(word -> userMessage.toLowerCase().contains(word))) { //check if contains a word of location //all data found to create waypoint - addCustomWaypoint(waypointLocation, blockPos); + //make sure the waypoint does not already exist in active waypoints, so waypoints can not get randomly moved + if (!activeWaypoints.containsKey(waypointLocation)){ + addCustomWaypoint(waypointLocation, blockPos); + } return; } } -- cgit From dfe5c28dd6a50fc88973e95e60bcfd418daa1e90 Mon Sep 17 00:00:00 2001 From: Rime <81419447+Emirlol@users.noreply.github.com> Date: Sat, 13 Jul 2024 02:21:47 +0300 Subject: Fix regex and add tests for the regex --- .../skyblock/dwarven/CrystalsLocationsManager.java | 4 ++-- .../dwarven/CrystalsLocationManagerTest.java | 26 +++++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') 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 2a21776e..0e3b4d59 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -53,7 +53,8 @@ public class CrystalsLocationsManager { * A look-up table to convert between location names and waypoint in the {@link MiningLocationLabel.CrystalHollowsLocationsCategory} values. */ private static final Map WAYPOINT_LOCATIONS = Arrays.stream(MiningLocationLabel.CrystalHollowsLocationsCategory.values()).collect(Collectors.toMap(MiningLocationLabel.CrystalHollowsLocationsCategory::getName, Function.identity())); - private static final Pattern TEXT_CWORDS_PATTERN = Pattern.compile("([0-9][0-9][0-9])\\D*([0-9][0-9][0-9]?)\\D*([0-9][0-9][0-9])"); + //Package-private for testing + static final Pattern TEXT_CWORDS_PATTERN = Pattern.compile("\\Dx?(\\d{3})(?=[, ]),? ?y?(\\d{2,3})(?=[, ]),? ?z?(\\d{3})\\D?(?!\\d)"); private static final int REMOVE_UNKNOWN_DISTANCE = 50; protected static Map activeWaypoints = new HashMap<>(); @@ -72,7 +73,6 @@ public class CrystalsLocationsManager { } private static void extractLocationFromMessage(Text message, Boolean overlay) { - if (!SkyblockerConfigManager.get().mining.crystalsWaypoints.findInChat || !Utils.isInCrystalHollows() || overlay) { return; } 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 5d555742..11331fae 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java @@ -6,7 +6,31 @@ import org.junit.jupiter.api.Test; import de.hysky.skyblocker.utils.Constants; -public class CrystalsLocationManagerTest { +class CrystalsLocationManagerTest { + boolean matches(String text) { + return CrystalsLocationsManager.TEXT_CWORDS_PATTERN.matcher(text).find(); + } + + @Test + void testRegex() { + Assertions.assertTrue(matches("x123 y12 z123")); + Assertions.assertTrue(matches("x123, y12, z123")); + Assertions.assertTrue(matches("Player: 123 12 123")); //This and the ones below fail when specified in the same format as those above, as the regex check assumes that the message is sent somewhere in a message and that it isn't the whole message + Assertions.assertTrue(matches("Player: 123 123 123")); + Assertions.assertTrue(matches("Player: 123, 12, 123")); + Assertions.assertTrue(matches("Player: 123, 123, 123")); + Assertions.assertTrue(matches("Player: 123,12,123")); + Assertions.assertTrue(matches("Player: 123,123,123")); + + Assertions.assertFalse(matches("Player: 123 1234 123")); + Assertions.assertFalse(matches("Player: 1234 12 123")); + Assertions.assertFalse(matches("Player: 123 12 1234")); + Assertions.assertFalse(matches("Player: 12 12 123")); + Assertions.assertFalse(matches("Player: 123 1 123")); + Assertions.assertFalse(matches("Player: 123 12 12")); + Assertions.assertFalse(matches("Player: 12312123")); + Assertions.assertFalse(matches("Player: 123123123")); + } @Test void testLocationInCrystals() { -- cgit From 4563b3e5f188a3b49db2e9219bee1474856cde98 Mon Sep 17 00:00:00 2001 From: olim Date: Mon, 15 Jul 2024 12:35:49 +0100 Subject: implement requested changes --- .../skyblock/dwarven/CrystalsLocationsManager.java | 34 ++++++++++++++++++---- .../resources/assets/skyblocker/lang/en_us.json | 17 +++++++---- 2 files changed, 40 insertions(+), 11 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') 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 0e3b4d59..5ab9dedd 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -21,6 +21,7 @@ import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; import net.minecraft.client.MinecraftClient; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.text.ClickEvent; +import net.minecraft.text.HoverEvent; import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; @@ -98,7 +99,7 @@ public class CrystalsLocationsManager { if (Arrays.stream(waypointLocation.toLowerCase().split(" ")).anyMatch(word -> userMessage.toLowerCase().contains(word))) { //check if contains a word of location //all data found to create waypoint //make sure the waypoint does not already exist in active waypoints, so waypoints can not get randomly moved - if (!activeWaypoints.containsKey(waypointLocation)){ + if (!activeWaypoints.containsKey(waypointLocation)) { addCustomWaypoint(waypointLocation, blockPos); } return; @@ -131,7 +132,7 @@ public class CrystalsLocationsManager { } } - protected 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 @@ -200,7 +201,7 @@ public class CrystalsLocationsManager { * Creates a formated text with a list of possible places to add a waypoint for * * @param location the location where the waypoint will be created - * @param excludeUnknown if the "Unknown" location should be available to add + * @param excludeUnknown if the {@link de.hysky.skyblocker.skyblock.dwarven.MiningLocationLabel.CrystalHollowsLocationsCategory#UNKNOWN Unknown} location should be available to add * @return text for a message to send to the player */ private static Text getLocationMenu(String location, boolean excludeUnknown) { @@ -211,13 +212,23 @@ public class CrystalsLocationsManager { return text.append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.allActive").formatted(Formatting.RED)); } + //add starting message + text.append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.MarkLocation.start") + .append(Text.literal(" ("+location+") ").formatted(Formatting.GRAY)) + .append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.MarkLocation.end")) + ); + + //add possible locations to the message for (String waypointLocation : WAYPOINT_LOCATIONS.keySet()) { //do not show option to add waypoints for existing locations or unknown if its disabled if (activeWaypoints.containsKey(waypointLocation) || (excludeUnknown && Objects.equals(waypointLocation, MiningLocationLabel.CrystalHollowsLocationsCategory.UNKNOWN.getName()))) { continue; } int locationColor = WAYPOINT_LOCATIONS.get(waypointLocation).getColor(); - text.append(Text.literal("[" + waypointLocation + "]").withColor(locationColor).styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/skyblocker crystalWaypoints add " + location + " " + waypointLocation)))); + text.append(Text.literal("[" + waypointLocation + "]").withColor(locationColor).styled(style -> style + .withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/skyblocker crystalWaypoints add " + location + " " + waypointLocation)) + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("skyblocker.config.mining.crystalsWaypoints.getLocationHover.add").withColor(locationColor)))) + ); } return text; @@ -238,9 +249,22 @@ public class CrystalsLocationsManager { return text.append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.noActive").formatted(Formatting.RED)); } + //depending on the action load the correct prefix and hover message + String hoverMessage; + if (action.equals("remove")) { + text.append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.getLocationHover.remove").append(Text.literal(": "))); + hoverMessage = "skyblocker.config.mining.crystalsWaypoints.getLocationHover.remove"; + } else { + text.append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.getLocationHover.share").append(Text.literal(": "))); + hoverMessage = "skyblocker.config.mining.crystalsWaypoints.getLocationHover.share"; + } + for (String waypointLocation : activeWaypoints.keySet()) { int locationColor = WAYPOINT_LOCATIONS.get(waypointLocation).getColor(); - text.append(Text.literal("[" + waypointLocation + "]").withColor(locationColor).styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/skyblocker crystalWaypoints " + action + " " + waypointLocation)))); + text.append(Text.literal("[" + waypointLocation + "]").withColor(locationColor).styled(style -> style + .withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/skyblocker crystalWaypoints " + action + " " + waypointLocation)) + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable(hoverMessage).withColor(locationColor)))) + ); } return text; diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index f323641a..97add21b 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -479,20 +479,25 @@ "skyblocker.config.mining.crystalsWaypoints.addedWaypoint.at": "at", "skyblocker.config.mining.crystalsWaypoints.noActive": "You have no active waypoints to share or remove.", "skyblocker.config.mining.crystalsWaypoints.allActive": "You have no more waypoints left to create.", + "skyblocker.config.mining.crystalsWaypoints.MarkLocation.start": "Mark", + "skyblocker.config.mining.crystalsWaypoints.MarkLocation.end": "as: ", + "skyblocker.config.mining.crystalsWaypoints.getLocationHover.add": "Add Location", + "skyblocker.config.mining.crystalsWaypoints.getLocationHover.remove": "Remove Location", + "skyblocker.config.mining.crystalsWaypoints.getLocationHover.share": "Share Location", "skyblocker.config.mining.crystalsWaypoints.shareFail": "Can only share waypoints you have found.", "skyblocker.config.mining.crystalsWaypoints.removeSuccess": "Removed waypoint for ", "skyblocker.config.mining.crystalsWaypoints.removeFail": "Can only remove waypoints you have found.", "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver": "Wishing Compass Solver", - "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.@Tooltip": "Works out and adds a waypoint to where a wishing compass points to", - "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.enableTabMessage": "Enable crystals in /tab so the compass can know what has been found", - "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.wishingCompassUsedMessage": "Wishing compass used. Move to another location and use another compass to triangulate target", - "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.somethingWentWrongMessage": "Something went wrong. lines do not cross. please try again", + "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.@Tooltip": "Calculates and adds a waypoint at the location indicated by wishing compasses.", + "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.enableTabMessage": "Enable crystals in the /tab to allow the compass to identify discovered items", + "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.wishingCompassUsedMessage": "Wishing compass used. Move to another location and use a second compass to triangulate the target", + "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.somethingWentWrongMessage": "The lines did not intersect (Something went wrong) please try again.", "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.foundMessage": "Wishing compass solver found ", "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.useOutsideNucleusMessage": "Use compass outside of nucleus for better results", "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.moveFurtherMessage": "Move further away from the first use before using again", "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.changingZoneMessage": "Changed zone. Restarting...", - "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.waitLongerMessage": "Wait a little before using another wishing compass", - "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.couldNotDetectLastUseMessage": "Could not detect last use. Restarting...", + "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.waitLongerMessage": "Wait a moment before using another wishing compass", + "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.couldNotDetectLastUseMessage": "Unable to detect the last use. Restarting...", "skyblocker.config.mining.dwarvenHud": "Dwarven HUD", "skyblocker.config.mining.dwarvenHud.enabledCommissions": "Enable Commissions", -- cgit From b96d383530784af14f776b451381982939c16d36 Mon Sep 17 00:00:00 2001 From: olim Date: Mon, 15 Jul 2024 12:40:58 +0100 Subject: fix rebase --- .../de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/de/hysky/skyblocker') 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 5ab9dedd..ac8e413b 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -150,7 +150,7 @@ public class CrystalsLocationsManager { CLIENT.player.sendMessage(getLocationMenu((int) CLIENT.player.getX() + " " + (int) CLIENT.player.getY() + " " + (int) CLIENT.player.getZ(), true), false); return Command.SINGLE_SUCCESS; }) - .then(argument("pos", BlockPosArgumentType.blockPos()) + .then(argument("pos", ClientBlockPosArgumentType.blockPos()) .then(argument("place", StringArgumentType.greedyString()) .suggests((context, builder) -> suggestMatching(WAYPOINT_LOCATIONS.keySet(), builder)) .executes(context -> addWaypointFromCommand(context.getSource(), getString(context, "place"), context.getArgument("pos", ClientPosArgument.class))) -- cgit From d19a509eedcc87b249288cbc196f6d6422200fff Mon Sep 17 00:00:00 2001 From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> Date: Mon, 22 Jul 2024 23:27:03 +0800 Subject: Apply code review --- .../skyblocker/config/configs/MiningConfig.java | 4 +- .../skyblock/dwarven/CrystalsLocationsManager.java | 29 ++---- .../skyblock/dwarven/MiningLocationLabel.java | 1 + .../skyblock/dwarven/WishingCompassSolver.java | 115 +++++++++------------ .../skyblock/tabhud/util/PlayerListMgr.java | 71 ++++++++----- .../resources/assets/skyblocker/lang/en_us.json | 6 +- 6 files changed, 108 insertions(+), 118 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') diff --git a/src/main/java/de/hysky/skyblocker/config/configs/MiningConfig.java b/src/main/java/de/hysky/skyblocker/config/configs/MiningConfig.java index 1347f158..dcf70f24 100644 --- a/src/main/java/de/hysky/skyblocker/config/configs/MiningConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/configs/MiningConfig.java @@ -108,10 +108,10 @@ public class MiningConfig { public CommissionWaypointMode mode = CommissionWaypointMode.BOTH; @SerialEntry - public boolean useColor = true; + public float textScale = 1; @SerialEntry - public float textScale = 1; + public boolean useColor = true; @SerialEntry public boolean showBaseCamp = 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 ac8e413b..8ccafed2 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -187,14 +187,8 @@ public class CrystalsLocationsManager { } protected static Text getSetLocationMessage(String location, BlockPos blockPos) { - MutableText text = Constants.PREFIX.get(); - text.append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.addedWaypoint")); int locationColor = WAYPOINT_LOCATIONS.get(location).getColor(); - text.append(Text.literal(location).withColor(locationColor)); - text.append(Text.literal(" ").append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.addedWaypoint.at"))); - text.append(Text.literal(" : " + blockPos.getX() + " " + blockPos.getY() + " " + blockPos.getZ() + ".")); - - return text; + return Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.addedWaypoint", Text.literal(location).withColor(locationColor), blockPos.getX(), blockPos.getY(), blockPos.getZ())); } /** @@ -205,18 +199,14 @@ public class CrystalsLocationsManager { * @return text for a message to send to the player */ private static Text getLocationMenu(String location, boolean excludeUnknown) { - MutableText text = Constants.PREFIX.get(); //if the user has all available waypoints active warn them instead of an empty list (excused unknown from check when disabled) if (activeWaypoints.size() == WAYPOINT_LOCATIONS.size() || (excludeUnknown && WAYPOINT_LOCATIONS.size() - activeWaypoints.size() == 1 && !activeWaypoints.containsKey(MiningLocationLabel.CrystalHollowsLocationsCategory.UNKNOWN.getName()))) { - return text.append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.allActive").formatted(Formatting.RED)); + return Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.allActive").formatted(Formatting.RED)); } //add starting message - text.append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.MarkLocation.start") - .append(Text.literal(" ("+location+") ").formatted(Formatting.GRAY)) - .append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.MarkLocation.end")) - ); + MutableText text = Text.empty(); //add possible locations to the message for (String waypointLocation : WAYPOINT_LOCATIONS.keySet()) { @@ -231,10 +221,9 @@ public class CrystalsLocationsManager { ); } - return text; + return Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.markLocation", location, text)); } - /** * Creates a formated text with a list of found places to remove / share a waypoint for * @@ -250,20 +239,20 @@ public class CrystalsLocationsManager { } //depending on the action load the correct prefix and hover message - String hoverMessage; + MutableText hoverMessage; if (action.equals("remove")) { text.append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.getLocationHover.remove").append(Text.literal(": "))); - hoverMessage = "skyblocker.config.mining.crystalsWaypoints.getLocationHover.remove"; + hoverMessage = Text.translatable("skyblocker.config.mining.crystalsWaypoints.getLocationHover.remove"); } else { text.append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.getLocationHover.share").append(Text.literal(": "))); - hoverMessage = "skyblocker.config.mining.crystalsWaypoints.getLocationHover.share"; + hoverMessage = Text.translatable("skyblocker.config.mining.crystalsWaypoints.getLocationHover.share"); } - + for (String waypointLocation : activeWaypoints.keySet()) { int locationColor = WAYPOINT_LOCATIONS.get(waypointLocation).getColor(); text.append(Text.literal("[" + waypointLocation + "]").withColor(locationColor).styled(style -> style .withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/skyblocker crystalWaypoints " + action + " " + waypointLocation)) - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable(hoverMessage).withColor(locationColor)))) + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverMessage.withColor(locationColor)))) ); } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java index 2c3409c5..3817f6c7 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java @@ -14,6 +14,7 @@ import net.minecraft.util.math.Vec3d; import java.awt.*; +// TODO: Clean up into the waypoint system with a new `DistancedWaypoint` that extends `NamedWaypoint` for this and secret waypoints. public record MiningLocationLabel(Category category, Vec3d centerPos) implements Renderable { public MiningLocationLabel(Category category, BlockPos pos) { this(category, pos.toCenterPos()); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java index 7e7386f0..d513a38b 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java @@ -9,13 +9,15 @@ import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.fabricmc.fabric.api.event.player.UseBlockCallback; import net.fabricmc.fabric.api.event.player.UseItemCallback; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.PlayerListEntry; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.network.packet.s2c.play.ParticleS2CPacket; import net.minecraft.particle.ParticleTypes; import net.minecraft.text.Text; -import net.minecraft.util.*; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Formatting; +import net.minecraft.util.Hand; +import net.minecraft.util.TypedActionResult; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; @@ -24,45 +26,27 @@ import net.minecraft.world.World; import org.apache.commons.math3.geometry.euclidean.threed.Line; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; -import java.util.HashMap; import java.util.Map; import java.util.Objects; import java.util.stream.Stream; public class WishingCompassSolver { private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); - - enum SolverStates { - NOT_STARTED, - PROCESSING_FIRST_USE, - WAITING_FOR_SECOND, - PROCESSING_SECOND_USE, - } - - enum ZONE { - CRYSTAL_NUCLEUS, - JUNGLE, - MITHRIL_DEPOSITS, - GOBLIN_HOLDOUT, - PRECURSOR_REMNANTS, - MAGMA_FIELDS, - } - - private static final HashMap ZONE_BOUNDING_BOXES = Util.make(new HashMap<>(), map -> { - map.put(ZONE.CRYSTAL_NUCLEUS, new Box(462, 63, 461, 564, 181, 565)); - map.put(ZONE.JUNGLE, new Box(201, 63, 201, 513, 189, 513)); - map.put(ZONE.MITHRIL_DEPOSITS, new Box(512, 63, 201, 824, 189, 513)); - map.put(ZONE.GOBLIN_HOLDOUT, new Box(201, 63, 512, 513, 189, 824)); - map.put(ZONE.PRECURSOR_REMNANTS, new Box(512, 63, 512, 824, 189, 824)); - map.put(ZONE.MAGMA_FIELDS, new Box(201, 30, 201, 824, 64, 824)); - }); + private static final Map ZONE_BOUNDING_BOXES = Map.of( + Zone.CRYSTAL_NUCLEUS, new Box(462, 63, 461, 564, 181, 565), + Zone.JUNGLE, new Box(201, 63, 201, 513, 189, 513), + Zone.MITHRIL_DEPOSITS, new Box(512, 63, 201, 824, 189, 513), + Zone.GOBLIN_HOLDOUT, new Box(201, 63, 512, 513, 189, 824), + Zone.PRECURSOR_REMNANTS, new Box(512, 63, 512, 824, 189, 824), + Zone.MAGMA_FIELDS, new Box(201, 30, 201, 824, 64, 824) + ); private static final Vec3d JUNGLE_TEMPLE_DOOR_OFFSET = new Vec3d(-57, 36, -21); /** - * how many particles to use to get direction of a line + * The number of particles to use to get direction of a line */ private static final long PARTICLES_PER_LINE = 25; /** - * the amount of milliseconds to wait for the next particle until assumed failed + * The time in milliseconds to wait for the next particle until assumed failed */ private static final long PARTICLES_MAX_DELAY = 500; /** @@ -93,12 +77,12 @@ public class WishingCompassSolver { } /** - * When a filed message is sent in chat reset the wishing compass solver to start + * When a filed message is sent in chat, reset the wishing compass solver to start * @param text message * @param b overlay */ private static void failMessageListener(Text text, boolean b) { - if (!Utils.isInCrystalHollows()){ + if (!Utils.isInCrystalHollows()) { return; } if (Formatting.strip(text.getString()).equals("The Wishing Compass can't seem to locate anything!")) { @@ -115,7 +99,7 @@ public class WishingCompassSolver { particleUsedCountOne = 0; particleUsedCountTwo = 0; particleLastUpdate = System.currentTimeMillis(); - Vec3d particleLastPos = Vec3d.ZERO; + particleLastPos = Vec3d.ZERO; } private static boolean isKingsScentPresent() { @@ -127,45 +111,26 @@ public class WishingCompassSolver { } private static boolean isKeyInInventory() { - if (CLIENT.player == null) { - return false; - } - for (ItemStack item : CLIENT.player.getInventory().main) { - if (item != null && Objects.equals(item.getSkyblockId(), "JUNGLE_KEY")) { - return true; - } - } - return false; + return CLIENT.player != null && CLIENT.player.getInventory().main.stream().anyMatch(stack -> stack != null && Objects.equals(stack.getSkyblockId(), "JUNGLE_KEY")); } - private static ZONE getZoneOfLocation(Vec3d location) { - for (Map.Entry zone : ZONE_BOUNDING_BOXES.entrySet()) { - if (zone.getValue().contains(location)) { - return zone.getKey(); - } - } - - //default to nucleus if somehow not in another zone - return ZONE.CRYSTAL_NUCLEUS; + private static Zone getZoneOfLocation(Vec3d location) { + return ZONE_BOUNDING_BOXES.entrySet().stream().filter(zone -> zone.getValue().contains(location)).findFirst().map(Map.Entry::getKey).orElse(Zone.CRYSTAL_NUCLEUS); //default to nucleus if somehow not in another zone } - private static Boolean isZoneComplete(ZONE zone) { + private static Boolean isZoneComplete(Zone zone) { if (CLIENT.getNetworkHandler() == null || CLIENT.player == null) { return false; } - //creates cleaned stream of all the entry's in tab list - Stream playerListStream = CLIENT.getNetworkHandler().getPlayerList().stream(); - Stream displayNameStream = playerListStream.map(PlayerListEntry::getDisplayName).filter(Objects::nonNull).map(Text::getString).map(String::strip); //make sure the data is in tab and if not tell the user - if (displayNameStream.noneMatch(entry -> entry.equals("Crystals:"))) { + if (PlayerListMgr.getPlayerStringList().stream().noneMatch(entry -> entry.equals("Crystals:"))) { CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.enableTabMessage")), false); return false; } //return if the crystal for a zone is found - playerListStream = CLIENT.getNetworkHandler().getPlayerList().stream(); - displayNameStream = playerListStream.map(PlayerListEntry::getDisplayName).filter(Objects::nonNull).map(Text::getString).map(String::strip); + Stream displayNameStream = PlayerListMgr.getPlayerStringList().stream(); return switch (zone) { case JUNGLE -> displayNameStream.noneMatch(entry -> entry.equals("Amethyst: ✖ Not Found")); case MITHRIL_DEPOSITS -> displayNameStream.noneMatch(entry -> entry.equals("Jade: ✖ Not Found")); @@ -176,17 +141,15 @@ public class WishingCompassSolver { }; } - private static MiningLocationLabel.CrystalHollowsLocationsCategory getTargetLocation(ZONE startingZone) { + private static MiningLocationLabel.CrystalHollowsLocationsCategory getTargetLocation(Zone startingZone) { //if the zone is complete return null if (isZoneComplete(startingZone)) { return MiningLocationLabel.CrystalHollowsLocationsCategory.UNKNOWN; } return switch (startingZone) { - case JUNGLE -> - isKeyInInventory() ? MiningLocationLabel.CrystalHollowsLocationsCategory.JUNGLE_TEMPLE : MiningLocationLabel.CrystalHollowsLocationsCategory.ODAWA; + case JUNGLE -> isKeyInInventory() ? MiningLocationLabel.CrystalHollowsLocationsCategory.JUNGLE_TEMPLE : MiningLocationLabel.CrystalHollowsLocationsCategory.ODAWA; case MITHRIL_DEPOSITS -> MiningLocationLabel.CrystalHollowsLocationsCategory.MINES_OF_DIVAN; - case GOBLIN_HOLDOUT -> - isKingsScentPresent() ? MiningLocationLabel.CrystalHollowsLocationsCategory.GOBLIN_QUEENS_DEN : MiningLocationLabel.CrystalHollowsLocationsCategory.KING_YOLKAR; + case GOBLIN_HOLDOUT -> isKingsScentPresent() ? MiningLocationLabel.CrystalHollowsLocationsCategory.GOBLIN_QUEENS_DEN : MiningLocationLabel.CrystalHollowsLocationsCategory.KING_YOLKAR; case PRECURSOR_REMNANTS -> MiningLocationLabel.CrystalHollowsLocationsCategory.LOST_PRECURSOR_CITY; case MAGMA_FIELDS -> MiningLocationLabel.CrystalHollowsLocationsCategory.KHAZAD_DUM; default -> MiningLocationLabel.CrystalHollowsLocationsCategory.UNKNOWN; @@ -194,12 +157,12 @@ public class WishingCompassSolver { } /** - * Verify that a location could be correct and not to far out of zone. This is a problem when areas sometimes do not exist and is not a perfect solution + * Verifies that a location could be correct and not to far out of zone. This is a problem when areas sometimes do not exist and is not a perfect solution * @param startingZone zone player is searching in * @param pos location where the area should be * @return corrected location */ - private static Boolean verifyLocation(ZONE startingZone, Vec3d pos) { + private static Boolean verifyLocation(Zone startingZone, Vec3d pos) { return ZONE_BOUNDING_BOXES.get(startingZone).expand(100, 0, 100).contains(pos); } @@ -254,7 +217,7 @@ public class WishingCompassSolver { CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.somethingWentWrongMessage").formatted(Formatting.RED)), false); } else { //send message to player with location and name - ZONE playerZone = getZoneOfLocation(startPosOne); + Zone playerZone = getZoneOfLocation(startPosOne); MiningLocationLabel.CrystalHollowsLocationsCategory location = getTargetLocation(playerZone); if (!verifyLocation(playerZone, targetLocation)) { location = MiningLocationLabel.CrystalHollowsLocationsCategory.UNKNOWN; @@ -342,12 +305,12 @@ public class WishingCompassSolver { return true; } Vec3d playerPos = CLIENT.player.getEyePos(); - ZONE currentZone = getZoneOfLocation(playerPos); + Zone currentZone = getZoneOfLocation(playerPos); switch (currentState) { case NOT_STARTED -> { //do not start if the player is in nucleus as this does not work well - if (currentZone == ZONE.CRYSTAL_NUCLEUS) { + if (currentZone == Zone.CRYSTAL_NUCLEUS) { CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.useOutsideNucleusMessage")), false); return true; } @@ -407,4 +370,20 @@ public class WishingCompassSolver { particleLastPos = playerPos; } } + + private enum SolverStates { + NOT_STARTED, + PROCESSING_FIRST_USE, + WAITING_FOR_SECOND, + PROCESSING_SECOND_USE, + } + + private enum Zone { + CRYSTAL_NUCLEUS, + JUNGLE, + MITHRIL_DEPOSITS, + GOBLIN_HOLDOUT, + PRECURSOR_REMNANTS, + MAGMA_FIELDS, + } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/PlayerListMgr.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/PlayerListMgr.java index 472cf700..b08a09d6 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/PlayerListMgr.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/PlayerListMgr.java @@ -1,19 +1,20 @@ package de.hysky.skyblocker.skyblock.tabhud.util; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import de.hysky.skyblocker.mixins.accessors.PlayerListHudAccessor; import de.hysky.skyblocker.utils.Utils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.PlayerListEntry; import net.minecraft.text.MutableText; import net.minecraft.text.Text; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * This class may be used to get data from the player list. It doesn't get its @@ -24,8 +25,15 @@ public class PlayerListMgr { public static final Logger LOGGER = LoggerFactory.getLogger("Skyblocker Regex"); - private static List playerList; - private static String footer; + /** + * The player list in tab. + */ + private static List playerList = new ArrayList<>(); // Initialize to prevent npe. + /** + * The player list in tab, but a list of strings instead of {@link PlayerListEntry}s. + */ + private static List playerStringList = new ArrayList<>(); + private static String footer; public static void updateList() { @@ -38,25 +46,40 @@ public class PlayerListMgr { // check is needed, else game crashes on server leave if (cpnwh != null) { playerList = cpnwh.getPlayerList().stream().sorted(PlayerListHudAccessor.getOrdering()).toList(); + playerStringList = playerList.stream().map(PlayerListEntry::getDisplayName).filter(Objects::nonNull).map(Text::getString).map(String::strip).toList(); } } - public static void updateFooter(Text f) { - if (f == null) { - footer = null; - } else { - footer = f.getString(); - } - } + /** + * @return the cached player list + */ + public static List getPlayerList() { + return playerList; + } + + /** + * @return the cached player list as a list of strings + */ + public static List getPlayerStringList() { + return playerStringList; + } + + public static void updateFooter(Text f) { + if (f == null) { + footer = null; + } else { + footer = f.getString(); + } + } - public static String getFooter() { - return footer; - } + public static String getFooter() { + return footer; + } /** * Get the display name at some index of the player list and apply a pattern to * it - * + * * @return the matcher if p fully matches, else null */ public static Matcher regexAt(int idx, Pattern p) { @@ -78,7 +101,7 @@ public class PlayerListMgr { /** * Get the display name at some index of the player list as string - * + * * @return the string or null, if the display name is null, empty or whitespace * only */ @@ -105,9 +128,9 @@ public class PlayerListMgr { /** * Gets the display name at some index of the player list - * + * * @return the text or null, if the display name is null - * + * * @implNote currently designed specifically for crimson isles faction quests * widget and the rift widgets, might not work correctly without * modification for other stuff. you've been warned! @@ -157,7 +180,7 @@ public class PlayerListMgr { /** * Get the display name at some index of the player list as Text as seen in the * game - * + * * @return the PlayerListEntry at that index */ public static PlayerListEntry getRaw(int idx) { diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 97add21b..b7866dc2 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -475,12 +475,10 @@ "skyblocker.config.mining.crystalsWaypoints.textScale.@Tooltip": "Scale the size of the commission labels.", "skyblocker.config.mining.crystalsWaypoints.findInChat": "Find Waypoints In Chat", "skyblocker.config.mining.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", - "skyblocker.config.mining.crystalsWaypoints.addedWaypoint": "Added waypoint for ", - "skyblocker.config.mining.crystalsWaypoints.addedWaypoint.at": "at", + "skyblocker.config.mining.crystalsWaypoints.addedWaypoint": "Added waypoint for '%s' at %d %d %d.", "skyblocker.config.mining.crystalsWaypoints.noActive": "You have no active waypoints to share or remove.", "skyblocker.config.mining.crystalsWaypoints.allActive": "You have no more waypoints left to create.", - "skyblocker.config.mining.crystalsWaypoints.MarkLocation.start": "Mark", - "skyblocker.config.mining.crystalsWaypoints.MarkLocation.end": "as: ", + "skyblocker.config.mining.crystalsWaypoints.markLocation": "Mark (%s) as: %s", "skyblocker.config.mining.crystalsWaypoints.getLocationHover.add": "Add Location", "skyblocker.config.mining.crystalsWaypoints.getLocationHover.remove": "Remove Location", "skyblocker.config.mining.crystalsWaypoints.getLocationHover.share": "Share Location", -- cgit From d3cb3448f98c024beca3334e39eeb46fd1079e02 Mon Sep 17 00:00:00 2001 From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> Date: Wed, 24 Jul 2024 00:09:50 +0800 Subject: Fix test and daily mojank --- .../skyblocker/skyblock/dwarven/CrystalsLocationsManager.java | 6 +++++- .../skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java | 7 +++---- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') 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 8ccafed2..22e494ab 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -188,7 +188,11 @@ public class CrystalsLocationsManager { protected static Text getSetLocationMessage(String location, BlockPos blockPos) { int locationColor = WAYPOINT_LOCATIONS.get(location).getColor(); - return Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.addedWaypoint", Text.literal(location).withColor(locationColor), blockPos.getX(), blockPos.getY(), blockPos.getZ())); + + // Minecraft transforms all arguments (`%s`, `%d`, whatever) to `%$1s` DURING LOADING in `Language#load(InputStream, BiConsumer)` for some unknown reason. + // And then `TranslatableTextContent#forEachPart` only accepts `%s` for some other unknown reason. + // So that's why the arguments are all `%s`. Wtf mojang????????? + return Constants.PREFIX.get().append(Text.translatableWithFallback("skyblocker.config.mining.crystalsWaypoints.addedWaypoint", "Added waypoint for '%s' at %s %s %s.", Text.literal(location).withColor(locationColor), blockPos.getX(), blockPos.getY(), blockPos.getZ())); } /** 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 10c55faf..aac4a641 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationManagerTest.java @@ -1,11 +1,10 @@ package de.hysky.skyblocker.skyblock.dwarven; +import de.hysky.skyblocker.utils.Constants; import net.minecraft.util.math.BlockPos; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import de.hysky.skyblocker.utils.Constants; - class CrystalsLocationManagerTest { boolean matches(String text) { return CrystalsLocationsManager.TEXT_CWORDS_PATTERN.matcher(text).find(); @@ -50,7 +49,7 @@ class CrystalsLocationManagerTest { @Test void testSetLocationMessage() { - Assertions.assertEquals(CrystalsLocationsManager.getSetLocationMessage("Jungle Temple", new BlockPos(10, 11, 12)).getString(), Constants.PREFIX.get().getString() + "skyblocker.config.mining.crystalsWaypoints.addedWaypointJungle Temple skyblocker.config.mining.crystalsWaypoints.addedWaypoint.at : 10 11 12."); - Assertions.assertEquals(CrystalsLocationsManager.getSetLocationMessage("Fairy Grotto", new BlockPos(0, 0, 0)).getString(), Constants.PREFIX.get().getString() + "skyblocker.config.mining.crystalsWaypoints.addedWaypointFairy Grotto skyblocker.config.mining.crystalsWaypoints.addedWaypoint.at : 0 0 0."); + Assertions.assertEquals(Constants.PREFIX.get().getString() + "Added waypoint for 'Jungle Temple' at 10 11 12.", CrystalsLocationsManager.getSetLocationMessage("Jungle Temple", new BlockPos(10, 11, 12)).getString()); + Assertions.assertEquals(Constants.PREFIX.get().getString() + "Added waypoint for 'Fairy Grotto' at 0 0 0.", CrystalsLocationsManager.getSetLocationMessage("Fairy Grotto", new BlockPos(0, 0, 0)).getString()); } } -- cgit From cd9f7062e7b66f6f8fee078cbef32aee8d07df94 Mon Sep 17 00:00:00 2001 From: olim Date: Wed, 24 Jul 2024 12:20:20 +0100 Subject: add error message when target location is to far away --- .../de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java | 4 ++-- src/main/resources/assets/skyblocker/lang/en_us.json | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java index d513a38b..7b14002b 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java @@ -219,8 +219,10 @@ public class WishingCompassSolver { //send message to player with location and name Zone playerZone = getZoneOfLocation(startPosOne); MiningLocationLabel.CrystalHollowsLocationsCategory location = getTargetLocation(playerZone); + //set to unknown if the target is to far from the region it's allowed to spawn in if (!verifyLocation(playerZone, targetLocation)) { location = MiningLocationLabel.CrystalHollowsLocationsCategory.UNKNOWN; + CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.targetLocationToFar").formatted(Formatting.RED)), false); } //offset the jungle location to its doors if (location == MiningLocationLabel.CrystalHollowsLocationsCategory.JUNGLE_TEMPLE) { @@ -259,8 +261,6 @@ public class WishingCompassSolver { return null; } return new Vec3d(intersection.getX(), intersection.getY(), intersection.getZ()); - - } private static ActionResult onBlockInteract(PlayerEntity playerEntity, World world, Hand hand, BlockHitResult blockHitResult) { diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index b7866dc2..760a7221 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -490,6 +490,7 @@ "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.enableTabMessage": "Enable crystals in the /tab to allow the compass to identify discovered items", "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.wishingCompassUsedMessage": "Wishing compass used. Move to another location and use a second compass to triangulate the target", "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.somethingWentWrongMessage": "The lines did not intersect (Something went wrong) please try again.", + "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.targetLocationToFar": "The target location is too far away to identify the structure, possibly due to a missing structure in the lobby.", "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.foundMessage": "Wishing compass solver found ", "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.useOutsideNucleusMessage": "Use compass outside of nucleus for better results", "skyblocker.config.mining.crystalsWaypoints.wishingCompassSolver.moveFurtherMessage": "Move further away from the first use before using again", -- cgit