From cde33a4c83a2f2d781ff8bb740b7166691c04600 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Sat, 27 Apr 2024 10:15:43 +0200 Subject: Add hotm upgrade TODOs/warning (#1090) --- .../notenoughupdates/options/NEUConfig.java | 7 +- .../options/separatesections/Mining.java | 9 ++ .../notenoughupdates/overlays/MiningOverlay.java | 13 ++- .../notenoughupdates/util/TabListUtils.java | 1 + .../moulberry/notenoughupdates/util/Utils.java | 24 +++- .../notenoughupdates/miscfeatures/HotmDesires.kt | 129 +++++++++++++++++++++ .../notenoughupdates/util/kotlin/RegexUtil.kt | 30 +++++ 7 files changed, 205 insertions(+), 8 deletions(-) create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/HotmDesires.kt create mode 100644 src/main/kotlin/io/github/moulberry/notenoughupdates/util/kotlin/RegexUtil.kt diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java index 3fa0908b..cbc14b79 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java @@ -31,6 +31,7 @@ import io.github.moulberry.notenoughupdates.core.config.GuiPositionEditor; import io.github.moulberry.notenoughupdates.core.config.Position; import io.github.moulberry.notenoughupdates.dungeons.GuiDungeonMapEditor; import io.github.moulberry.notenoughupdates.miscfeatures.FairySouls; +import io.github.moulberry.notenoughupdates.miscfeatures.HotmDesires; import io.github.moulberry.notenoughupdates.miscfeatures.IQTest; import io.github.moulberry.notenoughupdates.miscgui.GuiEnchantColour; import io.github.moulberry.notenoughupdates.miscgui.GuiInvButtonEditor; @@ -82,6 +83,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.ClientCommandHandler; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; @@ -596,7 +598,7 @@ public class NEUConfig extends Config { }}; } - public HiddenProfileSpecific getProfileSpecific() { + public @Nullable HiddenProfileSpecific getProfileSpecific() { if (SBInfo.getInstance().currentProfile == null) { return null; } @@ -627,6 +629,9 @@ public class NEUConfig extends Config { @Expose public List forgeItems = new ArrayList<>(); + @Expose + public Map hotmDesires = new HashMap<>(); + @Expose public int commissionMilestone = 0; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/separatesections/Mining.java b/src/main/java/io/github/moulberry/notenoughupdates/options/separatesections/Mining.java index 2228aa64..4b44d195 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/separatesections/Mining.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/separatesections/Mining.java @@ -947,4 +947,13 @@ public class Mining { ) @ConfigEditorBoolean public boolean mineshaftExitWaypoint = true; + + @Expose + @ConfigOption( + name = "Powder TODOs", + desc = "Click on a perk in your /hotm tree when you can't afford it to get a notification when you can." + ) + @ConfigEditorBoolean + public boolean powderTodo = true; + } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java index ad5100e3..f015a129 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java @@ -26,6 +26,7 @@ import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.core.util.lerp.LerpUtils; import io.github.moulberry.notenoughupdates.guifeatures.SkyMallDisplay; import io.github.moulberry.notenoughupdates.miscfeatures.GlaciteTunnelWaypoints; +import io.github.moulberry.notenoughupdates.miscfeatures.HotmDesires; import io.github.moulberry.notenoughupdates.miscfeatures.ItemCooldowns; import io.github.moulberry.notenoughupdates.miscfeatures.tablisttutorial.TablistAPI; import io.github.moulberry.notenoughupdates.options.NEUConfig; @@ -267,7 +268,8 @@ public class MiningOverlay extends TextTabOverlay { NotEnoughUpdates.INSTANCE.config.mining.emissaryWaypoints == 0 && !NotEnoughUpdates.INSTANCE.config.mining.titaniumAlert && NotEnoughUpdates.INSTANCE.config.mining.locWaypoints == 0 - && NotEnoughUpdates.INSTANCE.config.mining.tunnelWaypoints != Mining.GlaciteTunnelWaypointBehaviour.NONE) { + && NotEnoughUpdates.INSTANCE.config.mining.tunnelWaypoints != Mining.GlaciteTunnelWaypointBehaviour.NONE + && HotmDesires.wantsPowderInfo()) { return; } @@ -290,13 +292,16 @@ public class MiningOverlay extends TextTabOverlay { for (String line : powderLines) { if (line.contains("Mithril:")) { - mithrilPowder = DARK_AQUA + Utils.trimWhitespaceAndFormatCodes(line).replaceAll("\u00a7[f|F|r]", ""); + mithrilPowder = DARK_AQUA + Utils.trimWhitespaceAndFormatCodes(line).replaceAll("\u00a7[f|F|r]", "") + + HotmDesires.appendDesireForType("Mithril"); } if (line.contains("Gemstone:")) { - gemstonePowder = DARK_AQUA + Utils.trimWhitespaceAndFormatCodes(line).replaceAll("\u00a7[f|F|r]", ""); + gemstonePowder = DARK_AQUA + Utils.trimWhitespaceAndFormatCodes(line).replaceAll("\u00a7[f|F|r]", "") + + HotmDesires.appendDesireForType("Gemstone"); } if (line.contains("Glacite: ")) { - glacitePowder = DARK_AQUA + Utils.trimWhitespaceAndFormatCodes(line).replaceAll("\u00a7[f|F|r]", ""); + glacitePowder = DARK_AQUA + Utils.trimWhitespaceAndFormatCodes(line).replaceAll("\u00a7[f|F|r]", "") + + HotmDesires.appendDesireForType("Glacite"); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/TabListUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/TabListUtils.java index f36db034..f7357343 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/TabListUtils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/TabListUtils.java @@ -72,6 +72,7 @@ public class TabListUtils { new TabListChangeEvent(tabList, tabListLastTick).post(); } + @Deprecated public static List getTabList() { return tabList; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java index fee8c594..f13462bc 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -67,6 +67,7 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import net.minecraftforge.fml.common.Loader; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.lwjgl.BufferUtils; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; @@ -1241,7 +1242,7 @@ public class Utils { var width = fr.getStringWidth(str); float scale = ((float) availableSpace) / width; GlStateManager.scale(scale, scale, 1f); - fr.drawString(str, -width / 2F, 0, colour, shadow); + fr.drawString(str, -width / 2F, 0, colour, shadow); GlStateManager.popMatrix(); } @@ -2342,10 +2343,27 @@ public class Utils { return username; } - public static void addChatMessage(String message) { + public static void addChatMessage(@NotNull String message) { + addChatMessage(new ChatComponentText(message)); + } + + public static void addClickableChatMessage( + @NotNull String message, + @NotNull String command, + @Nullable String hoverText + ) { + if (hoverText == null) + hoverText = "§eClick to run §a" + command; + addChatMessage(new ChatComponentText(message) + .setChatStyle(new ChatStyle() + .setChatClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command)) + .setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ChatComponentText(hoverText))))); + } + + public static void addChatMessage(@NotNull IChatComponent message) { EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; if (thePlayer != null) { - thePlayer.addChatMessage(new ChatComponentText(message)); + thePlayer.addChatMessage(message); } else { System.out.println(message); } diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/HotmDesires.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/HotmDesires.kt new file mode 100644 index 00000000..ef95eff3 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/HotmDesires.kt @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2024 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.miscfeatures + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.core.util.StringUtils +import io.github.moulberry.notenoughupdates.events.SlotClickEvent +import io.github.moulberry.notenoughupdates.events.TabListChangeEvent +import io.github.moulberry.notenoughupdates.miscfeatures.tablisttutorial.TablistAPI +import io.github.moulberry.notenoughupdates.util.ItemUtils +import io.github.moulberry.notenoughupdates.util.SBInfo +import io.github.moulberry.notenoughupdates.util.Utils +import io.github.moulberry.notenoughupdates.util.kotlin.KSerializable +import io.github.moulberry.notenoughupdates.util.kotlin.useMatcher +import net.minecraftforge.event.entity.player.ItemTooltipEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@NEUAutoSubscribe +object HotmDesires { + + val powderRequirementText = "§.([0-9,]+) .* Powder".toPattern() + val youArePoorText = "§cYou don't have enough (.*) Powder!".toPattern() + + val lastPowder = mutableMapOf() + + @KSerializable + data class Desire( + val name: String, + val powderRequirement: Int, + ) + + val desires: MutableMap? + get() = NotEnoughUpdates.INSTANCE.config.profileSpecific?.hotmDesires + + @JvmStatic + fun appendDesireForType(powderType: String): String { + val desire = desires?.get(powderType) ?: return "" + return "§7/§c" + StringUtils.formatNumber(desire.powderRequirement) + } + + val tablistPowderLine = " (.*): ([0-9,]+)".toPattern() + + @SubscribeEvent + fun onTabListChange(event: TabListChangeEvent) { + val desireMap = desires ?: return + if (!isEnabled()) { + desireMap.clear() + return + } + if (SBInfo.getInstance().getLocation() !in setOf("mining_3", "crystal_hollows", "mineshaft")) { + return + } + for (line in TablistAPI.getWidgetLines(TablistAPI.WidgetNames.POWDER)) { + val (powderKind, powderCount) = tablistPowderLine.useMatcher(StringUtils.cleanColour(line)) { + val powderKind = group(1) + val powderCount = group(2).replace(",", "").toInt() + powderKind to powderCount + } ?: continue + if (lastPowder[powderKind] == powderCount) continue + lastPowder[powderKind] = powderCount + val goal = desireMap[powderKind] ?: continue + if (goal.powderRequirement > powderCount) continue + desireMap.remove(powderKind) + Utils.addClickableChatMessage( + "§e[NEU] You have enough $powderKind powder to upgrade ${goal.name}§e!", + "/hotm", + "§eClick to open your Heart of the Mountain to select the next upgrade." + ) + } + } + + fun isEnabled() = NotEnoughUpdates.INSTANCE.config.mining.powderTodo + + @SubscribeEvent + fun onClickHotmItemThatYouCannotUpgrade(event: SlotClickEvent) { + if (Utils.getOpenChestName() != "Heart of the Mountain" || !isEnabled()) + return + val name = ItemUtils.getDisplayName(event.slot.stack) ?: return + val lore = ItemUtils.getLore(event.slot.stack) + val missingPowderText = lore.lastOrNull() ?: return + val powderKind = youArePoorText.useMatcher(missingPowderText) { + group(1) + } ?: return + val powderCount = + lore.firstNotNullOfOrNull { powderRequirementText.useMatcher(it) { group(1).replace(",", "").toInt() } } + ?: return + val desireMap = desires ?: return + if (desireMap[powderKind]?.name != name) { + desireMap[powderKind] = Desire(name, powderCount) + } else { + desireMap.remove(powderKind) + } + } + + + @SubscribeEvent + fun onAfterGuiDraw(event: ItemTooltipEvent) { + if (Utils.getOpenChestName() != "Heart of the Mountain" || !isEnabled()) + return + val name = ItemUtils.getDisplayName(event.itemStack) ?: return + if (desires?.values?.any { it.name == name } != true) return + event.toolTip.add("§e[NEU] Selected this perk as your next goal.") + event.toolTip.add("§e[NEU] Click again to deselect.") + } + + @JvmStatic + fun wantsPowderInfo(): Boolean { + return desires?.isNotEmpty() == true && isEnabled() + } + +} diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/kotlin/RegexUtil.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/kotlin/RegexUtil.kt new file mode 100644 index 00000000..c2fb0fa1 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/kotlin/RegexUtil.kt @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2024 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.util.kotlin + +import java.util.regex.Matcher +import java.util.regex.Pattern + +inline fun Pattern.useMatcher(text: String, function: Matcher.() -> T): T? = + useMatcher(text)?.let(function) + +fun Pattern.useMatcher(text: String): Matcher? = + matcher(text).takeIf { it.matches() } + -- cgit