diff options
author | Linnea Gräf <roman.graef@gmail.com> | 2023-11-02 15:28:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-02 15:28:49 +0100 |
commit | 2a6d3a96d40ca425e661737fb4fc467b2040437b (patch) | |
tree | bb89ff8177ebb3abdc2a047f16b9671bc18cacd8 /src/main/java/io | |
parent | e1c24ecc30132fc98aa9cf33b928232b2efabcd8 (diff) | |
download | NotEnoughUpdates-2a6d3a96d40ca425e661737fb4fc467b2040437b.tar.gz NotEnoughUpdates-2a6d3a96d40ca425e661737fb4fc467b2040437b.tar.bz2 NotEnoughUpdates-2a6d3a96d40ca425e661737fb4fc467b2040437b.zip |
Add custom TODOs (#870)
Co-authored-by: Lulonaut <lulonaut@lulonaut.tech>
Diffstat (limited to 'src/main/java/io')
7 files changed, 130 insertions, 109 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index f878dbf1..f20c5338 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -56,6 +56,7 @@ import io.github.moulberry.notenoughupdates.recipes.RecipeGenerator; import io.github.moulberry.notenoughupdates.util.Utils; import io.github.moulberry.notenoughupdates.util.brigadier.BrigadierRoot; import io.github.moulberry.notenoughupdates.util.hypixelapi.HypixelItemAPI; +import io.github.moulberry.notenoughupdates.util.kotlin.KotlinTypeAdapterFactory; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiScreen; @@ -150,7 +151,8 @@ public class NotEnoughUpdates { put("MYTHIC", EnumChatFormatting.LIGHT_PURPLE.toString()); }}; public static ProfileViewer profileViewer; - private final Gson gson = new GsonBuilder().setPrettyPrinting().excludeFieldsWithoutExposeAnnotation().create(); + private final Gson gson = new GsonBuilder().setPrettyPrinting().excludeFieldsWithoutExposeAnnotation() + .registerTypeAdapterFactory(KotlinTypeAdapterFactory.INSTANCE).create(); public NEUManager manager; public NEUOverlay overlay; public NEUConfig config; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiEnchantColour.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiEnchantColour.java index 41208681..174650d9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiEnchantColour.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiEnchantColour.java @@ -25,10 +25,12 @@ import com.google.gson.JsonArray; import com.google.gson.JsonParseException; import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; +import info.bliki.api.Template; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.util.lerp.LerpingInteger; import io.github.moulberry.notenoughupdates.itemeditor.GuiElementTextField; import io.github.moulberry.notenoughupdates.options.NEUConfig; +import io.github.moulberry.notenoughupdates.util.TemplateUtil; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; @@ -51,6 +53,7 @@ import java.util.ArrayList; import java.util.Base64; import java.util.HashMap; import java.util.List; +import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -527,16 +530,7 @@ public class GuiEnchantColour extends GuiScreen { private boolean validShareContents() { try { String base64 = (String) Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor); - - if (base64.length() <= sharePrefix.length()) return false; - - base64 = base64.trim(); - - try { - return new String(Base64.getDecoder().decode(base64)).startsWith(sharePrefix); - } catch (IllegalArgumentException e) { - return false; - } + return Objects.equals(TemplateUtil.getTemplatePrefix(base64), sharePrefix); } catch (HeadlessException | IOException | UnsupportedFlavorException | IllegalStateException e) { return false; } @@ -647,26 +641,7 @@ public class GuiEnchantColour extends GuiScreen { } catch (HeadlessException | IOException | UnsupportedFlavorException e) { return; } - - if (base64.length() <= sharePrefix.length()) return; - - base64 = base64.trim(); - - String jsonString; - try { - jsonString = new String(Base64.getDecoder().decode(base64)); - if (!jsonString.startsWith(sharePrefix)) return; - jsonString = jsonString.substring(sharePrefix.length()); - } catch (IllegalArgumentException e) { - return; - } - - JsonArray presetArray; - try { - presetArray = new JsonParser().parse(jsonString).getAsJsonArray(); - } catch (IllegalStateException | JsonParseException e) { - return; - } + JsonArray presetArray = TemplateUtil.maybeDecodeTemplate(sharePrefix, base64, JsonArray.class); ArrayList<String> presetList = new ArrayList<>(); for (int i = 0; i < presetArray.size(); i++) { @@ -690,8 +665,8 @@ public class GuiEnchantColour extends GuiScreen { for (String s : result) { jsonArray.add(new JsonPrimitive(s)); } - String base64String = Base64.getEncoder().encodeToString((sharePrefix + - jsonArray).getBytes(StandardCharsets.UTF_8)); + + String base64String = TemplateUtil.encodeTemplate(sharePrefix, jsonArray); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(base64String), null); } else if (mouseY > guiTopSidebar + 2 + (24 * 2) && mouseY < guiTopSidebar + 20 + 2 + 24 * 2) { NotEnoughUpdates.INSTANCE.config.hidden.enchantColours = NEUConfig.createDefaultEnchantColours(); 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 2d64db59..200b1c0c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java @@ -35,6 +35,7 @@ import io.github.moulberry.notenoughupdates.miscfeatures.IQTest; import io.github.moulberry.notenoughupdates.miscgui.GuiEnchantColour; import io.github.moulberry.notenoughupdates.miscgui.GuiInvButtonEditor; import io.github.moulberry.notenoughupdates.miscgui.NEUOverlayPlacements; +import io.github.moulberry.notenoughupdates.miscgui.customtodos.CustomTodo; import io.github.moulberry.notenoughupdates.options.customtypes.NEUDebugFlag; import io.github.moulberry.notenoughupdates.options.separatesections.AHGraph; import io.github.moulberry.notenoughupdates.options.separatesections.AHTweaks; @@ -493,6 +494,8 @@ public class NEUConfig extends Config { public static class Hidden { @Expose + public List<CustomTodo> customTodos = new ArrayList<>(); + @Expose public HashMap<String, NEUConfig.HiddenProfileSpecific> profileSpecific = new HashMap<>(); @Expose public HashMap<String, NEUConfig.HiddenLocationSpecific> locationSpecific = new HashMap<>(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TextOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TextOverlay.java index cefb6929..c4768b3e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TextOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TextOverlay.java @@ -184,6 +184,9 @@ public abstract class TextOverlay { for (String s2 : s.split("\n")) { Vector2f pos = new Vector2f(x + paddingX, y + paddingY + yOff); renderLine(s2, pos, dummy); + if (s2.startsWith("CUSTOM")) { + s2 = s2.split(":", 2)[1]; + } int xPad = (int) pos.x; int yPad = (int) pos.y; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java index bf73e2ec..ca244303 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java @@ -22,6 +22,7 @@ package io.github.moulberry.notenoughupdates.overlays; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.config.Position; import io.github.moulberry.notenoughupdates.events.SlotClickEvent; +import io.github.moulberry.notenoughupdates.miscgui.customtodos.CustomTodoHud; import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.util.ItemUtils; import io.github.moulberry.notenoughupdates.util.SBInfo; @@ -168,91 +169,97 @@ public class TimersOverlay extends TextTabOverlay { return; } GlStateManager.enableDepth(); - ItemStack icon = null; String clean = Utils.cleanColour(line); String beforeColon = clean.split(":")[0]; - switch (beforeColon) { - case "Cakes": - icon = CAKES_ICON; - break; - case "Puzzler": - icon = PUZZLER_ICON; - break; - case "Godpot": - icon = NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.manager - .getItemInformation() - .get("GOD_POTION")); - break; - case "Fetchur": { - if (FETCHUR_ICONS == null) { - FETCHUR_ICONS = new ItemStack[]{ - new ItemStack(Blocks.wool, 50, 14), - new ItemStack(Blocks.stained_glass, 20, 4), - new ItemStack(Items.compass, 1, 0), - new ItemStack(Items.prismarine_crystals, 20, 0), - new ItemStack(Items.fireworks, 1, 0), - NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.manager - .getItemInformation() - .get("CHEAP_COFFEE")), - new ItemStack(Items.oak_door, 1, 0), - new ItemStack(Items.rabbit_foot, 3, 0), - NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.manager - .getItemInformation() - .get("SUPERBOOM_TNT")), - new ItemStack(Blocks.pumpkin, 1, 0), - new ItemStack(Items.flint_and_steel, 1, 0), - new ItemStack(Items.emerald, 50, 0), - //new ItemStack(Items.ender_pearl, 16, 0) - }; - } + if (beforeColon.startsWith("CUSTOM")) { + var item = Item.getByNameOrId(beforeColon.substring(6)); + if (item == null) { + item = Items.paper; + } + icon = new ItemStack(item); + } else + switch (beforeColon) { + case "Cakes": + icon = CAKES_ICON; + break; + case "Puzzler": + icon = PUZZLER_ICON; + break; + case "Godpot": + icon = NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.manager + .getItemInformation() + .get("GOD_POTION")); + break; + case "Fetchur": { + if (FETCHUR_ICONS == null) { + FETCHUR_ICONS = new ItemStack[]{ + new ItemStack(Blocks.wool, 50, 14), + new ItemStack(Blocks.stained_glass, 20, 4), + new ItemStack(Items.compass, 1, 0), + new ItemStack(Items.prismarine_crystals, 20, 0), + new ItemStack(Items.fireworks, 1, 0), + NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.manager + .getItemInformation() + .get("CHEAP_COFFEE")), + new ItemStack(Items.oak_door, 1, 0), + new ItemStack(Items.rabbit_foot, 3, 0), + NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.manager + .getItemInformation() + .get("SUPERBOOM_TNT")), + new ItemStack(Blocks.pumpkin, 1, 0), + new ItemStack(Items.flint_and_steel, 1, 0), + new ItemStack(Blocks.emerald_ore, 50, 0), + //new ItemStack(Items.ender_pearl, 16, 0) + }; + } - ZonedDateTime currentTimeEST = ZonedDateTime.now(ZoneId.of("America/Atikokan")); + ZonedDateTime currentTimeEST = ZonedDateTime.now(ZoneId.of("America/Atikokan")); - long fetchurIndex = ((currentTimeEST.getDayOfMonth() + 1) % 12) - 1; - //Added because disabled fetchur and enabled it again but it was showing the wrong item - //Lets see if this stays correct + long fetchurIndex = ((currentTimeEST.getDayOfMonth() + 1) % 12) - 1; + //Added because disabled fetchur and enabled it again but it was showing the wrong item + //Lets see if this stays correct - if (fetchurIndex < 0) fetchurIndex += 12; + if (fetchurIndex < 0) fetchurIndex += 12; - icon = FETCHUR_ICONS[(int) fetchurIndex]; - break; + icon = FETCHUR_ICONS[(int) fetchurIndex]; + break; + } + case "Commissions": + icon = COMMISSIONS_ICON; + break; + case "Experiments": + icon = EXPERIMENTS_ICON; + break; + case "Cookie Buff": + icon = COOKIE_ICON; + break; + case "Mithril Powder": + icon = NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.manager + .getItemInformation() + .get("MITHRIL_ORE")); + break; + case "Gemstone Powder": + icon = NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.manager + .getItemInformation() + .get("PERFECT_AMETHYST_GEM")); + break; + case "Heavy Pearls": + icon = NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.manager + .getItemInformation() + .get("HEAVY_PEARL")); + break; + case "Free Rift Infusion": + icon = new ItemStack(Blocks.double_plant, 1, 1); + break; + case "Crimson Isle Quests": + icon = QUEST_ICON; + break; + case "NPC Buy Daily Limit": + icon = SHOP_ICON; + break; } - case "Commissions": - icon = COMMISSIONS_ICON; - break; - case "Experiments": - icon = EXPERIMENTS_ICON; - break; - case "Cookie Buff": - icon = COOKIE_ICON; - break; - case "Mithril Powder": - icon = NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.manager - .getItemInformation() - .get("MITHRIL_ORE")); - break; - case "Gemstone Powder": - icon = NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.manager - .getItemInformation() - .get("PERFECT_AMETHYST_GEM")); - break; - case "Heavy Pearls": - icon = NotEnoughUpdates.INSTANCE.manager.jsonToStack(NotEnoughUpdates.INSTANCE.manager - .getItemInformation() - .get("HEAVY_PEARL")); - break; - case "Free Rift Infusion": - icon = new ItemStack(Blocks.double_plant, 1, 1); - break; - case "Crimson Isle Quests": - icon = QUEST_ICON; - break; - case "NPC Buy Daily Limit": - icon = SHOP_ICON; - break; - } if (icon != null) { GlStateManager.pushMatrix(); @@ -1047,6 +1054,9 @@ public class TimersOverlay extends TextTabOverlay { overlayStrings.add(text); } } + + CustomTodoHud.processInto(overlayStrings); + if (overlayStrings.isEmpty()) overlayStrings = null; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java b/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java index 82708669..ad0000d4 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java @@ -23,6 +23,7 @@ import com.google.common.reflect.TypeToken; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe; +import io.github.moulberry.notenoughupdates.events.SidebarChangeEvent; import io.github.moulberry.notenoughupdates.miscfeatures.CookieWarning; import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.LocationChangeEvent; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager; @@ -310,6 +311,7 @@ public class SBInfo { public ArrayList<String> completedQuests = new ArrayList<>(); private static final Pattern SKILL_LEVEL_PATTERN = Pattern.compile("([^0-9:]+) (\\d{1,2})"); + private static List<String> lastLines = new ArrayList<>(); public void tick() { @@ -364,6 +366,11 @@ public class SBInfo { try { List<String> lines = SidebarUtil.readSidebarLines(true, false); + + if (lines.equals(lastLines)) return; + new SidebarChangeEvent(lines, lastLines).post(); + lastLines = lines; + boolean tempIsInDungeon = false; for (String line : lines) { if (line.contains("Cleared:") && line.contains("%")) { 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 a0266122..f36db034 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/TabListUtils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/TabListUtils.java @@ -21,10 +21,14 @@ package io.github.moulberry.notenoughupdates.util; import com.google.common.collect.ComparisonChain; import com.google.common.collect.Ordering; +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe; +import io.github.moulberry.notenoughupdates.events.TabListChangeEvent; import net.minecraft.client.Minecraft; import net.minecraft.client.network.NetworkPlayerInfo; import net.minecraft.scoreboard.ScorePlayerTeam; import net.minecraft.world.WorldSettings; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -32,6 +36,7 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; +@NEUAutoSubscribe public class TabListUtils { private static final Ordering<NetworkPlayerInfo> playerOrdering = Ordering.from(new PlayerComparator()); @@ -55,7 +60,23 @@ public class TabListUtils { } } + public static List<String> tabList = new ArrayList<>(); + public static List<String> tabListLastTick = new ArrayList<>(); + + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent event) { + if (Minecraft.getMinecraft().thePlayer == null) return; + if (event.phase != TickEvent.Phase.END) return; + tabListLastTick = tabList; + tabList = getTabList0(); + new TabListChangeEvent(tabList, tabListLastTick).post(); + } + public static List<String> getTabList() { + return tabList; + } + + private List<String> getTabList0() { List<NetworkPlayerInfo> players = playerOrdering.sortedCopy(Minecraft.getMinecraft().thePlayer.sendQueue.getPlayerInfoMap()); |