From 4725a42df06d8bf72bc6a901bd24dda25d761623 Mon Sep 17 00:00:00 2001 From: olim Date: Tue, 30 Jan 2024 14:43:42 +0000 Subject: location colors and on map made it so that locations in the crystal hollows can be shown on them map as well as way points. and also add colors for the way points and map. --- .../hysky/skyblocker/config/SkyblockerConfig.java | 11 +++++-- .../config/categories/DwarvenMinesCategory.java | 7 ++++ .../skyblocker/skyblock/dwarven/CrystalsHud.java | 35 +++++++++++++------- .../skyblock/dwarven/CrystalsLocationsManager.java | 29 +++++++++-------- .../skyblock/dwarven/CrystalsWaypoint.java | 37 ++++++++++++---------- 5 files changed, 75 insertions(+), 44 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker') diff --git a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java index 886f81fb..6f7db908 100644 --- a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java @@ -1,6 +1,7 @@ package de.hysky.skyblocker.config; import de.hysky.skyblocker.SkyblockerMod; +import de.hysky.skyblocker.skyblock.dwarven.CrystalsWaypoint; import de.hysky.skyblocker.skyblock.item.CustomArmorTrims; import de.hysky.skyblocker.utils.chat.ChatFilterResult; import de.hysky.skyblocker.utils.waypoint.Waypoint; @@ -14,7 +15,9 @@ import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class SkyblockerConfig { @SerialEntry @@ -901,10 +904,12 @@ public class SkyblockerConfig { @SerialEntry public boolean enabled = true; - @SerialEntry public boolean enableBackground = true; + @SerialEntry + public boolean showLocations = true; + @SerialEntry public int x = 10; @@ -917,9 +922,11 @@ public class SkyblockerConfig { @SerialEntry public boolean findInChat = true; + @SerialEntry + public Map ActiveWaypoints = new HashMap<>() {}; @SerialEntry - public Waypoint.Type waypointType = Waypoint.Type.WAYPOINT; + public Waypoint.Type waypointType = Waypoint.Type.WAYPOINT; //todo see if best option / give player a choice } public enum DwarvenHudStyle { diff --git a/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java index 4a7e6854..7581af4f 100644 --- a/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java +++ b/src/main/java/de/hysky/skyblocker/config/categories/DwarvenMinesCategory.java @@ -98,6 +98,13 @@ public class DwarvenMinesCategory { newValue -> config.locations.dwarvenMines.crystalsHud.enableBackground = newValue) .controller(ConfigUtils::createBooleanController) .build()) + .option(Option.createBuilder() + .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsHud.showLocations")) + .binding(defaults.locations.dwarvenMines.crystalsHud.showLocations, + () -> config.locations.dwarvenMines.crystalsHud.showLocations, + newValue -> config.locations.dwarvenMines.crystalsHud.showLocations = newValue) + .controller(ConfigUtils::createBooleanController) + .build()) .build()) //crystals waypoints .group(OptionGroup.createBuilder() diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java index 7ec9cefa..f9eaa65f 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsHud.java @@ -4,6 +4,7 @@ import de.hysky.skyblocker.SkyblockerMod; import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.utils.Utils; import de.hysky.skyblocker.utils.scheduler.Scheduler; +import it.unimi.dsi.fastutil.Pair; import it.unimi.dsi.fastutil.ints.IntIntPair; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; @@ -16,6 +17,7 @@ import org.apache.commons.math3.analysis.UnivariateMatrixFunction; import java.awt.*; import java.util.Arrays; +import java.util.Map; public class CrystalsHud { public static final MinecraftClient client = MinecraftClient.getInstance(); @@ -26,6 +28,7 @@ public class CrystalsHud { public static boolean visable = false; + public static final int LOCATION_SIZE = 10; //todo possible config option @@ -61,6 +64,16 @@ public class CrystalsHud { //draw map texture context. drawTexture(MAP_TEXTURE,hudX,hudY,0,0,62,62,62,62); + //if enabled add waypoint locations to map + if (SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.showLocations){ + Map ActiveWaypoints= SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.ActiveWaypoints; + for (CrystalsWaypoint waypoint : ActiveWaypoints.values()){ + Color waypointColor = waypoint.category.color; + Pair renderPos = transformLocation(waypoint.pos.getX(),waypoint.pos.getZ()); + //fill square of size LOCATION_SIZE around the coordinates of the location + context.fill(hudX+renderPos.first()-LOCATION_SIZE/2,hudY+renderPos.second()-LOCATION_SIZE/2,hudX+renderPos.first()+LOCATION_SIZE/2,hudY+renderPos.second()+LOCATION_SIZE/2,waypointColor.getRGB()); + } + } //draw player on map if (client.player == null || client.getNetworkHandler() == null) { return; @@ -69,23 +82,23 @@ public class CrystalsHud { double playerX = client.player.getX(); double playerZ = client.player.getZ(); double facing = client.player.getYaw(); - //map location to map - int renderX = (int)((playerX-202)/621 * 62); - int renderY = (int)((playerZ -202)/621 * 62); - int renderAngle = (int)(facing %360); - if (renderAngle < 0){//make sure the angle is always correct between 0 and 360 - renderAngle = 360 + renderAngle; - } - //clamp location to map - renderX = Math.max(0, Math.min(62, renderX)); - renderY = Math.max(0, Math.min(62, renderY)); + Pair renderPos = transformLocation(playerX,playerZ); //draw marker on map context. - drawTexture(MAP_ICON,hudX+renderX,hudY+renderY,2,0,5,7,128,128); + drawTexture(MAP_ICON,hudX+renderPos.first(),hudY+renderPos.second(),2,0,5,7,128,128); //todo add direction and scale (could be wrong drawing methods) and offset to center on player } + private static Pair transformLocation(double x, double z){ + //converts an x and z to a location on the map + int transformedX = (int)((x-202)/621 * 62); + int transformedY = (int)((z -202)/621 * 62); + transformedX = Math.max(0, Math.min(62, transformedX)); + transformedY = Math.max(0, Math.min(62, transformedY)); + + return Pair.of(transformedX,transformedY); + } public static void update() { if (client.player == null || client.getNetworkHandler() == null || !SkyblockerConfigManager.get().locations.dwarvenMines.crystalsHud.enabled) { diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java index d9f31f1d..e5f7d473 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsLocationsManager.java @@ -27,6 +27,7 @@ import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.math.BlockPos; +import java.awt.*; import java.time.Instant; import java.util.Arrays; import java.util.HashMap; @@ -40,7 +41,7 @@ import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.lit public class CrystalsLocationsManager { public static final MinecraftClient client = MinecraftClient.getInstance(); - public static Map ActiveWaypoints= new HashMap<>() {}; + public static final Map WAYPOINTLOCATIONS = Map.of( "Jungle Temple", CrystalsWaypoint.Category.JUNGLETEMPLE, @@ -51,15 +52,11 @@ public class CrystalsLocationsManager { "Fairy Grotto", CrystalsWaypoint.Category.FAIRYGROTTO, "Dragon's Lair", CrystalsWaypoint.Category.DRAGONSLAIR ); + private static final Pattern TEXT_CWORDS_PATTERN = Pattern.compile("([0-9][0-9][0-9]) ([0-9][0-9][0-9]?) ([0-9][0-9][0-9])"); public static void init() { - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(ClientCommandManager.literal("skyblocker") - .then(ClientCommandManager.literal("hud") - .then(ClientCommandManager.literal("crystals") - .executes(Scheduler.queueOpenScreenCommand(CrystalsHudConfigScreen::new)))))); - WorldRenderEvents.AFTER_TRANSLUCENT.register(CrystalsLocationsManager::render); ClientReceiveMessageEvents.CHAT.register(CrystalsLocationsManager::extractLocationFromMessage); ClientCommandRegistrationCallback.EVENT.register(CrystalsLocationsManager::registerWaypointLocationCommands); @@ -107,15 +104,17 @@ public class CrystalsLocationsManager { } private static Text getSetLocationMessage(String location,BlockPos blockPos) { MutableText text = Text.empty(); - text.append(Text.literal("Added waypoint for "+location+" at :"+blockPos.getX()+" "+blockPos.getY()+" "+blockPos.getZ()+".")); //todo add colours - + text.append(Text.literal("Added waypoint for ")); + Color locationColor = WAYPOINTLOCATIONS.get(location).color; + text.append(Text.literal(location).withColor(locationColor.getRGB())); + text.append(Text.literal(" at : "+blockPos.getX()+" "+blockPos.getY()+" "+blockPos.getZ()+".")); return text; } private static Text getLocationInputText(String location) { MutableText text = Text.empty(); for (String waypointLocation : WAYPOINTLOCATIONS.keySet()){ - //todo add colour codes - text.append(Text.literal("["+waypointLocation+"]").styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/skyblocker crystalWaypoints "+location+" "+waypointLocation)))); + Color locationColor = WAYPOINTLOCATIONS.get(waypointLocation).color; + text.append(Text.literal("["+waypointLocation+"]").withColor(locationColor.getRGB()).styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/skyblocker crystalWaypoints "+location+" "+waypointLocation)))); } return text; @@ -125,10 +124,9 @@ public class CrystalsLocationsManager { BlockPos blockPos = location.toAbsoluteBlockPos(new ServerCommandSource(null, source.getPosition(), source.getRotation(), null, 0, null, null, null, null)); if (WAYPOINTLOCATIONS.containsKey(place)){ addCustomWaypoint(Text.of(place), blockPos); - //todo send to map //tell the client it has done this if (client.player == null || client.getNetworkHandler() == null ) { - return Command.SINGLE_SUCCESS; + return 0; } client.player.sendMessage(getSetLocationMessage(place, blockPos), false); } @@ -139,10 +137,13 @@ public class CrystalsLocationsManager { private static void addCustomWaypoint( Text waypointName, BlockPos pos) { CrystalsWaypoint.Category category = WAYPOINTLOCATIONS.get(waypointName.getString()); CrystalsWaypoint waypoint = new CrystalsWaypoint(category, waypointName, pos); + Map ActiveWaypoints= SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.ActiveWaypoints; ActiveWaypoints.put(waypointName.getString(),waypoint); } + public static void render(WorldRenderContext context) { if (SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.enabled ) { + Map ActiveWaypoints= SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.ActiveWaypoints; for (CrystalsWaypoint crystalsWaypoint : ActiveWaypoints.values()) { if (crystalsWaypoint.shouldRender()) { crystalsWaypoint.render(context); @@ -153,17 +154,17 @@ public class CrystalsLocationsManager { public static void update() { if (client.player == null || client.getNetworkHandler() == null || !SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.enabled) { - ActiveWaypoints= new HashMap<>(); + SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.ActiveWaypoints= new HashMap<>(); return; } //get if the player is in the crystals String location = Utils.getIslandArea().replace("⏣ ",""); //if new location and needs waypoint add waypoint + Map ActiveWaypoints= SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints.ActiveWaypoints; if (!location.equals("Unknown") && WAYPOINTLOCATIONS.containsKey(location) && !ActiveWaypoints.containsKey(location)){ //add waypoint at player location BlockPos playerLocation = client.player.getBlockPos(); addCustomWaypoint(Text.of(location),playerLocation); - //todo send to map gui } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java index 9c6db04f..551821ca 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CrystalsWaypoint.java @@ -22,7 +22,9 @@ import net.minecraft.util.math.Vec3d; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.awt.*; import java.util.List; +import java.util.Map; import java.util.function.Predicate; import java.util.function.Supplier; import java.util.function.ToDoubleFunction; @@ -34,8 +36,9 @@ public class CrystalsWaypoint extends Waypoint { TextCodecs.CODEC.fieldOf("name").forGetter(crystalsWaypoint -> crystalsWaypoint.name), BlockPos.CODEC.fieldOf("pos").forGetter(crystalsWaypoint -> crystalsWaypoint.pos) ).apply(instance, CrystalsWaypoint::new)); - public static final Codec> LIST_CODEC = CODEC.listOf(); - static final List SECRET_ITEMS = List.of("Decoy", "Defuse Kit", "Dungeon Chest Key", "Healing VIII", "Inflatable Jerry", "Spirit Leap", "Training Weights", "Trap", "Treasure Talisman"); + + + private static final Supplier CONFIG = () -> SkyblockerConfigManager.get().locations.dwarvenMines.crystalsWaypoints; static final Supplier TYPE_SUPPLIER = () -> CONFIG.get().waypointType; final Category category; @@ -81,7 +84,6 @@ public class CrystalsWaypoint extends Waypoint { */ @Override public void render(WorldRenderContext context) { - //TODO In the future, shrink the box for wither essence and items so its more realistic super.render(context); @@ -94,28 +96,29 @@ public class CrystalsWaypoint extends Waypoint { - enum Category implements StringIdentifiable { //todo set better colours and remove extra data - JUNGLETEMPLE("Jungle Temple", 0, 255, 0), - MINESOFDIVAN("Mines Of Divan", 255, 0, 0), - GOBLINQUEENSDEN("Goblin Queen's Den", 2, 213, 250), - LOSTPRECURSORCITY("Lost Precursor City", 2, 64, 250), - KHAZADUM("Khazad-dûm", 142, 66, 0), - FAIRYGROTTO("Fairy Grotto", 30, 30, 30), - DRAGONSLAIR("Dragon's Lair", 250, 217, 2), - DEFAULT("default", 190, 255, 252); + enum Category implements StringIdentifiable { + JUNGLETEMPLE("Jungle Temple",Color.GREEN), + MINESOFDIVAN("Mines Of Divan",Color.CYAN), + GOBLINQUEENSDEN("Goblin Queen's Den",Color.ORANGE), + LOSTPRECURSORCITY("Lost Precursor City",Color.BLUE), + KHAZADUM("Khazad-dûm",Color.RED), + FAIRYGROTTO("Fairy Grotto",Color.PINK), + DRAGONSLAIR("Dragon's Lair",Color.BLACK), + DEFAULT("Default",Color.BLACK); + + public final Color color; private static final Codec CODEC = StringIdentifiable.createCodec(Category::values); private final String name; private final float[] colorComponents; - Category(String name, int... intColorComponents) { + Category(String name,Color color) { this.name = name; + this.color = color; + colorComponents = color.getColorComponents(null); + - colorComponents = new float[intColorComponents.length]; - for (int i = 0; i < intColorComponents.length; i++) { - colorComponents[i] = intColorComponents[i] / 255F; - } } static Category get(JsonObject waypointJson) { -- cgit