From b47ebd85b5ecb2c9b2adbbcd80f750ca15fd433e Mon Sep 17 00:00:00 2001 From: olim Date: Mon, 6 May 2024 11:14:56 +0100 Subject: rework to use labels instead of trying to use crystal waypoints --- .../java/de/hysky/skyblocker/SkyblockerMod.java | 2 +- .../skyblock/dwarven/CommissionLabels.java | 69 +++++++ .../skyblock/dwarven/CommissionWaypoints.java | 69 ------- .../skyblocker/skyblock/dwarven/CrystalsHud.java | 8 +- .../skyblock/dwarven/CrystalsLocationsManager.java | 12 +- .../skyblocker/skyblock/dwarven/DwarvenHud.java | 7 +- .../skyblock/dwarven/MiningLocationLabels.java | 124 +++++++++++++ .../skyblock/dwarven/MiningWaypoints.java | 201 --------------------- 8 files changed, 208 insertions(+), 284 deletions(-) create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/dwarven/CommissionLabels.java delete mode 100644 src/main/java/de/hysky/skyblocker/skyblock/dwarven/CommissionWaypoints.java create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabels.java delete mode 100644 src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningWaypoints.java (limited to 'src') diff --git a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java index 7d7acfbf..f3bb8d9d 100644 --- a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java +++ b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java @@ -120,7 +120,7 @@ public class SkyblockerMod implements ClientModInitializer { ItemCooldowns.init(); TabHud.init(); DwarvenHud.init(); - CommissionWaypoints.init(); + CommissionLabels.init(); CrystalsHud.init(); FarmingHud.init(); LowerSensitivity.init(); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CommissionLabels.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CommissionLabels.java new file mode 100644 index 00000000..f3e8e935 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CommissionLabels.java @@ -0,0 +1,69 @@ +package de.hysky.skyblocker.skyblock.dwarven; + +import de.hysky.skyblocker.utils.Utils; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; +import net.minecraft.text.Text; +import net.minecraft.util.math.BlockPos; + +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class CommissionLabels { + + private static final Map DWARVEN_LOCATIONS = Arrays.stream(MiningLocationLabels.dwarvenCategory.values()).collect(Collectors.toMap(MiningLocationLabels.dwarvenCategory::toString, Function.identity())); + private static final Map GLACITE_LOCATIONS = Arrays.stream(MiningLocationLabels.glaciteCategory.values()).collect(Collectors.toMap(MiningLocationLabels.glaciteCategory::toString, Function.identity())); + + + protected static List activeWaypoints = new ArrayList<>(); + + public static void init() { + WorldRenderEvents.AFTER_TRANSLUCENT.register(CommissionLabels::render); + ClientPlayConnectionEvents.JOIN.register((_handler, _sender, _client) -> reset()); + } + + protected static void update(List newCommissions) { + System.out.println(newCommissions); + activeWaypoints.clear(); + String location = Utils.getIslandArea().substring(2); + //find commission locations in glacite + if (location.equals("Dwarven Base Camp") || location.equals("Glacite Tunnels")) { + for (String commission : newCommissions) { + for (Map.Entry glaciteLocation : GLACITE_LOCATIONS.entrySet()) { + if (commission.contains(glaciteLocation.getKey())) { + MiningLocationLabels.glaciteCategory category = glaciteLocation.getValue(); + for (BlockPos gemstoneLocation : category.getLocations()) { + activeWaypoints.add(new MiningLocationLabels(category, Text.of(category.getName()), gemstoneLocation)); + } + } + } + } + return; + } + //find commission locations in dwarven mines + for (String commission : newCommissions) { + for (Map.Entry dwarvenLocation : DWARVEN_LOCATIONS.entrySet()) { + if (commission.contains(dwarvenLocation.getKey())) { + MiningLocationLabels.dwarvenCategory category = dwarvenLocation.getValue(); + activeWaypoints.add(new MiningLocationLabels(category, Text.of(category.getName()), category.getLocation())); + } + } + } + } + + private static void render(WorldRenderContext context) { + if (!Utils.isInDwarvenMines()) { + return; + } + for (MiningLocationLabels MiningLocationLabels : activeWaypoints) { + MiningLocationLabels.render(context); + } + + } + + private static void reset() { + + } +} diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CommissionWaypoints.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CommissionWaypoints.java deleted file mode 100644 index a73e89b9..00000000 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CommissionWaypoints.java +++ /dev/null @@ -1,69 +0,0 @@ -package de.hysky.skyblocker.skyblock.dwarven; - -import de.hysky.skyblocker.utils.Utils; -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; -import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; -import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; -import net.minecraft.text.Text; -import net.minecraft.util.math.BlockPos; - -import java.util.*; -import java.util.function.Function; -import java.util.stream.Collectors; - -public class CommissionWaypoints { - - private static final Map DWARVEN_LOCATIONS = Arrays.stream(MiningWaypoints.dwarvenCategory.values()).collect(Collectors.toMap(MiningWaypoints.dwarvenCategory::toString, Function.identity())); - private static final Map GLACITE_LOCATIONS = Arrays.stream(MiningWaypoints.glaciteCategory.values()).collect(Collectors.toMap(MiningWaypoints.glaciteCategory::toString, Function.identity())); - - - protected static List activeWaypoints = new ArrayList<>(); - - public static void init() { - WorldRenderEvents.AFTER_TRANSLUCENT.register(CommissionWaypoints::render); - ClientPlayConnectionEvents.JOIN.register((_handler, _sender, _client) -> reset()); - } - - protected static void update(List newCommissions) { - activeWaypoints.clear(); - String location = Utils.getIslandArea().substring(2); - //find commission locations in glacite - if (location.equals("Dwarven Base Camp") || location.equals("Glacite Tunnels")) { - for (DwarvenHud.Commission commission : newCommissions) { - String commissionName = commission.commission(); - for (Map.Entry glaciteLocation : GLACITE_LOCATIONS.entrySet()) { - if (commissionName.contains(glaciteLocation.getKey())) { - MiningWaypoints.glaciteCategory category = glaciteLocation.getValue(); - for (BlockPos gemstoneLocation : category.getLocations()) { - activeWaypoints.add(new MiningWaypoints(category, Text.of(category.getName()), gemstoneLocation)); - } - } - } - } - return; - } - //find commission locations in dwarven mines - for (DwarvenHud.Commission commission : newCommissions) { - String commissionName = commission.commission(); - for (Map.Entry dwarvenLocation : DWARVEN_LOCATIONS.entrySet()) { - if (commissionName.contains(dwarvenLocation.getKey())) { - MiningWaypoints.dwarvenCategory category = dwarvenLocation.getValue(); - activeWaypoints.add(new MiningWaypoints(category, Text.of(category.getName()), category.getLocation())); - } - } - } - } - - private static void render(WorldRenderContext context) { - for (MiningWaypoints miningWaypoints : activeWaypoints) { - if (miningWaypoints.shouldRender()) { - miningWaypoints.render(context); - } - } - - } - - private static void reset() { - activeWaypoints.clear(); - } -} 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 34667d12..ff4a23b8 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java @@ -21,7 +21,7 @@ import java.util.Map; public class CrystalsHud { private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); - protected static final Identifier MAP_TEXTURE = new Identifier(SkyblockerMod.NAMESPACE, "textures/gui/crystals_map.png"); + protected static final Identifier MAP_TEXTURE = new Identifier(SkyblockerMod.NAMESPACE, "textures/gui/crystals_map.png"); private static final Identifier MAP_ICON = new Identifier("textures/map/decorations/player.png"); private static final List SMALL_LOCATIONS = List.of("Fairy Grotto", "King Yolkar", "Corleone", "Odawa", "Key Guardian"); @@ -75,8 +75,8 @@ public class CrystalsHud { if (SkyblockerConfigManager.get().mining.crystalsHud.showLocations) { Map ActiveWaypoints = CrystalsLocationsManager.activeWaypoints; - for (MiningWaypoints waypoint : ActiveWaypoints.values()) { - Color waypointColor = waypoint.category.getColor(); + for (CrystalsWaypoint waypoint : ActiveWaypoints.values()) { + Color waypointColor = waypoint.category.color; Vector2ic renderPos = transformLocation(waypoint.pos.getX(), waypoint.pos.getZ()); int locationSize = SkyblockerConfigManager.get().mining.crystalsHud.locationSize; @@ -158,4 +158,4 @@ public class CrystalsHud { //get if the player is in the crystals visible = Utils.isInCrystalHollows(); } -} +} \ No newline at end of file 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 d9889b37..3aa4dc4d 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -47,12 +47,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 MiningWaypoints.crystalCategory} values. + * A look-up table to convert between location names and waypoint in the {@link CrystalsWaypoint.Category} values. */ - private static final Map WAYPOINT_LOCATIONS = Arrays.stream(MiningWaypoints.crystalCategory.values()).collect(Collectors.toMap(MiningWaypoints.crystalCategory::toString, Function.identity())); + private static final Map WAYPOINT_LOCATIONS = Arrays.stream(CrystalsWaypoint.Category.values()).collect(Collectors.toMap(CrystalsWaypoint.Category::toString, Function.identity())); private static final Pattern TEXT_CWORDS_PATTERN = Pattern.compile("([0-9][0-9][0-9]) ([0-9][0-9][0-9]?) ([0-9][0-9][0-9])"); - protected static Map activeWaypoints = new HashMap<>(); + protected static Map activeWaypoints = new HashMap<>(); public static void init() { Scheduler.INSTANCE.scheduleCyclic(CrystalsLocationsManager::update, 40); @@ -185,8 +185,8 @@ public class CrystalsLocationsManager { private static void addCustomWaypoint(String waypointName, BlockPos pos) { - MiningWaypoints.crystalCategory category = WAYPOINT_LOCATIONS.get(waypointName); - MiningWaypoints waypoint = new MiningWaypoints(category, Text.literal(waypointName), pos); + CrystalsWaypoint.Category category = WAYPOINT_LOCATIONS.get(waypointName); + CrystalsWaypoint waypoint = new CrystalsWaypoint(category, Text.literal(waypointName), pos); activeWaypoints.put(waypointName, waypoint); } @@ -218,4 +218,4 @@ public class CrystalsLocationsManager { addCustomWaypoint(location, playerLocation); } } -} +} \ No newline at end of file diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java index 44e4535f..82e03969 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java @@ -169,7 +169,7 @@ public class DwarvenHud { return; } - List oldCommissionList = commissionList; + List oldCommissionNames = commissionList.stream().map(Commission::commission).toList(); commissionList = new ArrayList<>(); for (PlayerListEntry playerListEntry : CLIENT.getNetworkHandler().getPlayerList().stream().sorted(PlayerListHudAccessor.getOrdering()).toList()) { @@ -198,8 +198,9 @@ public class DwarvenHud { glacitePowder = glaciteMatcher.group(0).split(": ")[1]; } } - if (!oldCommissionList.equals(commissionList)) { - CommissionWaypoints.update(commissionList); + List newCommissionNames = commissionList.stream().map(Commission::commission).toList(); + if (!oldCommissionNames.equals(newCommissionNames)) { + CommissionLabels.update(newCommissionNames); } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabels.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabels.java new file mode 100644 index 00000000..7808bec3 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningLocationLabels.java @@ -0,0 +1,124 @@ +package de.hysky.skyblocker.skyblock.dwarven; + +import de.hysky.skyblocker.utils.render.RenderHelper; +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; +import net.minecraft.client.MinecraftClient; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; + +import java.awt.*; + +public class MiningLocationLabels { + final Text name; + final Category category; + private final Vec3d centerPos; + + MiningLocationLabels(Category category, Text name, BlockPos pos) { + this.name = name; + this.category = category; + this.centerPos = pos.toCenterPos(); + } + + public void render(WorldRenderContext context) { + Vec3d posUp = centerPos.add(0, 1, 0); + double distance = context.camera().getPos().distanceTo(centerPos); + float scale = (float) (1 * (distance / 10)); + RenderHelper.renderText(context, name, posUp, scale, true); + RenderHelper.renderText(context, Text.literal(Math.round(distance) + "m").formatted(Formatting.YELLOW), posUp, scale, MinecraftClient.getInstance().textRenderer.fontHeight + 1, true); + + } + + + interface Category { + String getName(); + + float[] getColorComponents(); + + } + + enum dwarvenCategory implements Category { + LAVA_SPRINGS("Lava Springs", Color.CYAN, new BlockPos(60, 197, -15)), + CLIFFSIDE_VEINS("Cliffside Veins", Color.CYAN, new BlockPos(40, 128, 40)), + RAMPARTS_QUARRY("Rampart's Quarry", Color.CYAN, new BlockPos(-100, 150, -20)), + UPPER_MINES("Upper Mines", Color.CYAN, new BlockPos(-130, 174, -50)), + ROYAL_MINES("Royal Mines", Color.CYAN, new BlockPos(130, 154, 30)), + GLACITE_WALKER("Glacite Walker", Color.CYAN, new BlockPos(0, 128, 150)); + + + public final Color color; + private final String name; + private final float[] colorComponents; + private final BlockPos location; + + dwarvenCategory(String name, Color color, BlockPos location) { + this.name = name; + this.color = color; + this.colorComponents = color.getColorComponents(null); + this.location = location; + + } + + public BlockPos getLocation() { + return location; + } + + @Override + public String toString() { + return name; + } + + + @Override + public String getName() { + return name; + } + + @Override + public float[] getColorComponents() { + return colorComponents; + } + + } + + enum glaciteCategory implements Category { + AQUAMARINE("Aquamarine", Color.BLUE, new BlockPos[]{new BlockPos(-1, 139, 437), new BlockPos(90, 151, 229), new BlockPos(56, 151, 400), new BlockPos(51, 117, 303)}), + ONYX("Onyx", Color.BLACK, new BlockPos[]{new BlockPos(79, 119, 411), new BlockPos(-14, 132, 386), new BlockPos(18, 136, 370), new BlockPos(16, 138, 411), new BlockPos(-68, 130, 408)}), + PERIDOT("Peridot", Color.GREEN, new BlockPos[]{new BlockPos(-61, 147, 302), new BlockPos(91, 122, 397),new BlockPos(-73, 122, 458), new BlockPos(-77, 120, 282)}), + CITRINE("Citrine", Color.YELLOW, new BlockPos[]{new BlockPos(-104, 144, 244), new BlockPos(39, 119, 386), new BlockPos(-57, 144, 421), new BlockPos(-47, 126, 418) }); + + public final Color color; + private final String name; + private final float[] colorComponents; + private final BlockPos[] location; + + glaciteCategory(String name, Color color, BlockPos[] location) { + this.name = name; + this.color = color; + this.colorComponents = color.getColorComponents(null); + this.location = location; + + } + + public BlockPos[] getLocations() { + return location; + } + + @Override + public String toString() { + return name; + } + + @Override + public String getName() { + return name; + } + + @Override + public float[] getColorComponents() { + return colorComponents; + } + + } +} diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningWaypoints.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningWaypoints.java deleted file mode 100644 index 7b09e51d..00000000 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/MiningWaypoints.java +++ /dev/null @@ -1,201 +0,0 @@ -package de.hysky.skyblocker.skyblock.dwarven; - -import de.hysky.skyblocker.config.SkyblockerConfig; -import de.hysky.skyblocker.config.SkyblockerConfigManager; -import de.hysky.skyblocker.utils.render.RenderHelper; -import de.hysky.skyblocker.utils.waypoint.Waypoint; -import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; -import net.minecraft.client.MinecraftClient; -import net.minecraft.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.util.List; -import java.awt.*; -import java.util.function.Supplier; - -public class MiningWaypoints extends Waypoint { - private static final Supplier CONFIG = () -> SkyblockerConfigManager.get().general.waypoints; - private static final Supplier TYPE_SUPPLIER = () -> CONFIG.get().waypointType; - final Text name; - final Category category; - private final Vec3d centerPos; - - MiningWaypoints(Category category, Text name, BlockPos pos) { - super(pos, TYPE_SUPPLIER, category.getColorComponents()); - this.name = name; - this.category = category; - this.centerPos = pos.toCenterPos(); - } - - @Override - public boolean shouldRender() { - return super.shouldRender(); - } - - @Override - public boolean equals(Object obj) { - return super.equals(obj) || obj instanceof MiningWaypoints other && 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); - - } - - interface Category { - Color getColor(); - - String getName(); - - float[] getColorComponents(); - - } - - /** - * enum for the different waypoints used int the crystals hud each with a {@link crystalCategory#name} and associated {@link crystalCategory#color} - */ - - enum crystalCategory 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; - private final float[] colorComponents; - - crystalCategory(String name, Color color) { - this.name = name; - this.color = color; - this.colorComponents = color.getColorComponents(null); - } - - @Override - public String toString() { - return name; - } - - @Override - public Color getColor() { - return color; - } - - @Override - public String getName() { - return name; - } - - @Override - public float[] getColorComponents() { - return colorComponents; - } - } - - - enum dwarvenCategory implements Category { - SOMTHING("s", Color.BLACK, new BlockPos(0, 0, 0)); - - public final Color color; - private final String name; - private final float[] colorComponents; - private final BlockPos location; - - dwarvenCategory(String name, Color color, BlockPos location) { - this.name = name; - this.color = color; - this.colorComponents = color.getColorComponents(null); - this.location = location; - - } - - public BlockPos getLocation() { - return location; - } - - @Override - public String toString() { - return name; - } - - @Override - public Color getColor() { - return color; - } - - @Override - public String getName() { - return name; - } - - @Override - public float[] getColorComponents() { - return colorComponents; - } - - } - - enum glaciteCategory implements Category { - AQUAMARINE("Aquamarine", Color.CYAN, new BlockPos[]{new BlockPos(-1, 139, 437), new BlockPos(90, 151, 229), new BlockPos(56, 151, 400), new BlockPos(51, 117, 303)}), - ONYX("Onyx", Color.BLACK, new BlockPos[]{new BlockPos(79, 119, 411), new BlockPos(-14, 132, 386), new BlockPos(18, 136, 370), new BlockPos(16, 138, 411), new BlockPos(-68, 130, 408)}), - PERIDOT("Peridot", Color.GREEN, new BlockPos[]{new BlockPos(-61, 147, 302), new BlockPos(91, 122, 397),new BlockPos(-73, 122, 458), new BlockPos(-77, 120, 282)}), - CITRINE("Citrine", Color.YELLOW, new BlockPos[]{new BlockPos(-104, 144, 244), new BlockPos(39, 119, 386), new BlockPos(-57, 144, 421), new BlockPos(-47, 126, 418) }); - - public final Color color; - private final String name; - private final float[] colorComponents; - private final BlockPos[] location; - - glaciteCategory(String name, Color color, BlockPos[] location) { - this.name = name; - this.color = color; - this.colorComponents = color.getColorComponents(null); - this.location = location; - - } - - public BlockPos[] getLocations() { - return location; - } - - @Override - public String toString() { - return name; - } - - @Override - public Color getColor() { - return color; - } - - @Override - public String getName() { - return name; - } - - @Override - public float[] getColorComponents() { - return colorComponents; - } - - } -} -- cgit