diff options
author | olim <bobq4582@gmail.com> | 2024-06-16 21:35:39 +0100 |
---|---|---|
committer | olim <bobq4582@gmail.com> | 2024-07-15 12:36:19 +0100 |
commit | ee300d371a670e5483f5bf983e43eff20f64e90d (patch) | |
tree | 1a8e3362a6c62554d6b25b010f3075ef9e80aac1 /src/main | |
parent | 50b7a167253683d1526ac16a46e36adf1f5300d5 (diff) | |
download | Skyblocker-ee300d371a670e5483f5bf983e43eff20f64e90d.tar.gz Skyblocker-ee300d371a670e5483f5bf983e43eff20f64e90d.tar.bz2 Skyblocker-ee300d371a670e5483f5bf983e43eff20f64e90d.zip |
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
Diffstat (limited to 'src/main')
5 files changed, 92 insertions, 124 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..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<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,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<String, CrystalsWaypoint.Category> WAYPOINT_LOCATIONS = Arrays.stream(CrystalsWaypoint.Category.values()).collect(Collectors.toMap(CrystalsWaypoint.Category::toString, Function.identity())); + private static final Map<String, MiningLocationLabel.CrystalHollowsLocationsCategory> 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<String, CrystalsWaypoint> activeWaypoints = new HashMap<>(); + protected static Map<String, MiningLocationLabel> 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<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..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<String, Vec3i> 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(); + } + } } |