aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock
diff options
context:
space:
mode:
authorKevin <92656833+kevinthegreat1@users.noreply.github.com>2024-07-26 01:27:30 +0800
committerGitHub <noreply@github.com>2024-07-26 01:27:30 +0800
commit8f475f07c91076542b996cdada8385505a1bcce6 (patch)
treecb2dea55ea098eded224b555edaa97cb293ce44c /src/main/java/de/hysky/skyblocker/skyblock
parent55349c543a4b0fcbf9cbb86e0c1b7c0abd790b8c (diff)
parentcd9f7062e7b66f6f8fee078cbef32aee8d07df94 (diff)
downloadSkyblocker-8f475f07c91076542b996cdada8385505a1bcce6.tar.gz
Skyblocker-8f475f07c91076542b996cdada8385505a1bcce6.tar.bz2
Skyblocker-8f475f07c91076542b996cdada8385505a1bcce6.zip
Merge pull request #791 from olim88/improve-mining-waypoint
Improve mining waypoint
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java22
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java252
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java98
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dwarven/MetalDetector.java9
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java53
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dwarven/WishingCompassSolver.java389
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/PlayerListMgr.java71
7 files changed, 697 insertions, 197 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java
index 7f4dbdbf..30bf6b03 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<String> SMALL_LOCATIONS = List.of("Fairy Grotto", "King Yolkar", "Corleone", "Odawa", "Key Guardian");
+ private static final List<String> SMALL_LOCATIONS = List.of("Fairy Grotto", "King Yolkar", "Corleone", "Odawa", "Key Guardian", "Unknown");
public static boolean visible = false;
@@ -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,19 +72,19 @@ public class CrystalsHud {
//if enabled add waypoint locations to map
if (SkyblockerConfigManager.get().mining.crystalsHud.showLocations) {
- Map<String,CrystalsWaypoint> ActiveWaypoints = CrystalsLocationsManager.activeWaypoints;
+ Map<String, MiningLocationLabel> 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,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();
@@ -109,8 +108,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();
}
@@ -146,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 83167c18..22e494ab 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java
@@ -21,16 +21,15 @@ 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;
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.*;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -52,12 +51,15 @@ 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<String, CrystalsWaypoint.Category> WAYPOINT_LOCATIONS = Arrays.stream(CrystalsWaypoint.Category.values()).collect(Collectors.toMap(CrystalsWaypoint.Category::toString, Function.identity()));
- private static final Pattern TEXT_CWORDS_PATTERN = Pattern.compile("([0-9][0-9][0-9]) ([0-9][0-9][0-9]?) ([0-9][0-9][0-9])");
+ private static final Map<String, MiningLocationLabel.CrystalHollowsLocationsCategory> WAYPOINT_LOCATIONS = Arrays.stream(MiningLocationLabel.CrystalHollowsLocationsCategory.values()).collect(Collectors.toMap(MiningLocationLabel.CrystalHollowsLocationsCategory::getName, Function.identity()));
+ //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<String, CrystalsWaypoint> activeWaypoints = new HashMap<>();
+ protected static Map<String, MiningLocationLabel> activeWaypoints = new HashMap<>();
+ protected static List<String> verifiedWaypoints = new ArrayList<>();
public static void init() {
// Crystal Hollows Waypoints
@@ -72,47 +74,65 @@ 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;
}
-
+ String text = Formatting.strip(message.getString());
try {
- //get the message text
- String value = message.getString();
- Matcher matcher = TEXT_CWORDS_PATTERN.matcher(value);
- //if there are coordinates in the message try to get them and what they are talking about
- if (matcher.find()) {
- String location = matcher.group();
- int[] coordinates = Arrays.stream(location.split(" ", 3)).mapToInt(Integer::parseInt).toArray();
- BlockPos blockPos = new BlockPos(coordinates[0], coordinates[1], coordinates[2]);
-
- //if position is not in the hollows do not add it
- if (!checkInCrystals(blockPos)) {
- return;
- }
+ //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 (value.toLowerCase().contains(waypointLocation.toLowerCase())) { //todo be more lenient
- //all data found to create waypoint
- addCustomWaypoint(waypointLocation, blockPos);
+ //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
+ //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;
+ }
+ }
+
+ //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(getLocationMenu(location, false), 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);
}
+
+ //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();
+ String waypointName = waypointLocation.getName();
+ if (waypointLinkedMessage != null && text.contains(waypointLinkedMessage) && !verifiedWaypoints.contains(waypointName)) {
+ addCustomWaypoint(waypointLocation.getName(), CLIENT.player.getBlockPos());
+ verifiedWaypoints.add(waypointName);
+ }
+ }
+ }
}
- 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
@@ -122,16 +142,44 @@ public class CrystalsLocationsManager {
private static void registerWaypointLocationCommands(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess registryAccess) {
dispatcher.register(literal(SkyblockerMod.NAMESPACE)
.then(literal("crystalWaypoints")
- .then(argument("pos", ClientBlockPosArgumentType.blockPos())
+ .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", 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)))
+ )
+ ))
+ .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 -> addWaypointFromCommand(context.getSource(), getString(context, "place"), context.getArgument("pos", ClientPosArgument.class)))
+ .executes(context -> shareWaypoint(getString(context, "place")))
)
)
- .then(literal("share")
+ .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 -> shareWaypoint(getString(context, "place")))
+ .executes(context -> removeWaypoint(getString(context, "place")))
)
)
)
@@ -139,21 +187,77 @@ 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()));
- text.append(Text.literal(" at : " + blockPos.getX() + " " + blockPos.getY() + " " + blockPos.getZ() + "."));
+ int locationColor = WAYPOINT_LOCATIONS.get(location).getColor();
- return text;
+ // Minecraft transforms all arguments (`%s`, `%d`, whatever) to `%$1s` DURING LOADING in `Language#load(InputStream, BiConsumer<String,String>)` 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()));
}
- private static Text getLocationInputText(String location) {
- MutableText text = Constants.PREFIX.get();
+ /**
+ * 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 {@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) {
+
+ //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 Constants.PREFIX.get().append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.allActive").formatted(Formatting.RED));
+ }
+
+ //add starting message
+ MutableText text = Text.empty();
+ //add possible locations to the message
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))));
+ //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))
+ .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("skyblocker.config.mining.crystalsWaypoints.getLocationHover.add").withColor(locationColor))))
+ );
+ }
+
+ 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
+ *
+ * @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));
+ }
+
+ //depending on the action load the correct prefix and hover message
+ MutableText hoverMessage;
+ if (action.equals("remove")) {
+ text.append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.getLocationHover.remove").append(Text.literal(": ")));
+ hoverMessage = Text.translatable("skyblocker.config.mining.crystalsWaypoints.getLocationHover.remove");
+ } else {
+ text.append(Text.translatable("skyblocker.config.mining.crystalsWaypoints.getLocationHover.share").append(Text.literal(": ")));
+ 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, hoverMessage.withColor(locationColor))))
+ );
}
return text;
@@ -178,8 +282,8 @@ public class CrystalsLocationsManager {
public static int shareWaypoint(String place) {
if (activeWaypoints.containsKey(place)) {
- BlockPos pos = activeWaypoints.get(place).pos;
- MessageScheduler.INSTANCE.sendMessageAfterCooldown(Constants.PREFIX.get().getString() + " " + place + ": " + pos.getX() + ", " + pos.getY() + ", " + pos.getZ());
+ Vec3d pos = activeWaypoints.get(place).centerPos();
+ 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) {
@@ -191,25 +295,57 @@ 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);
+ 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);
+ }
- private static void addCustomWaypoint(String waypointName, BlockPos pos) {
- CrystalsWaypoint.Category category = WAYPOINT_LOCATIONS.get(waypointName);
- CrystalsWaypoint waypoint = new CrystalsWaypoint(category, Text.literal(waypointName), pos);
+ return Command.SINGLE_SUCCESS;
+ }
+
+
+ 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 (CrystalsWaypoint crystalsWaypoint : activeWaypoints.values()) {
- if (crystalsWaypoint.shouldRender()) {
- crystalsWaypoint.render(context);
- }
+ for (MiningLocationLabel crystalsWaypoint : activeWaypoints.values()) {
+ crystalsWaypoint.render(context);
}
}
}
private static void reset() {
activeWaypoints.clear();
+ verifiedWaypoints.clear();
}
public static void update() {
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java
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<UIAndVisualsConfig.Waypoints> CONFIG = () -> SkyblockerConfigManager.get().uiAndVisuals.waypoints;
- private static final Supplier<Type> 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<CrystalsWaypoint> getSquaredDistanceToFunction(Entity entity) {
- return crystalsWaypoint -> entity.squaredDistanceTo(crystalsWaypoint.centerPos);
- }
-
- static Predicate<CrystalsWaypoint> 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..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,8 @@ 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;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
@@ -17,6 +19,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 +29,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<String, Vec3i> keeperOffsets = Map.of(
@@ -242,14 +245,14 @@ 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()));
+ 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);
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()));
+ 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);
}
}
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..3817f6c7 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabel.java
@@ -1,15 +1,20 @@
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;
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.*;
+
+// 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());
@@ -24,13 +29,16 @@ 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
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);
}
@@ -154,4 +162,47 @@ 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 {
+ 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"),
+ 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, String linkedMessage) {
+ this.name = name;
+ this.color = color;
+ this.linkedMessage = linkedMessage;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public int getColor() {
+ return this.color.getRGB();