From 72adbc192fc53cd90408f4382b66310d77e2be2a Mon Sep 17 00:00:00 2001 From: KingsMMA <63374258+KingsMMA@users.noreply.github.com> Date: Sat, 22 Oct 2022 00:31:07 +1000 Subject: Added Powder Grinding Tracker (#263) --- .../notenoughupdates/NotEnoughUpdates.java | 11 ++ .../notenoughupdates/listener/ChatListener.java | 9 +- .../notenoughupdates/listener/WorldListener.java | 41 +++++ .../notenoughupdates/options/NEUConfig.java | 18 ++ .../options/seperateSections/LocationEdit.java | 12 ++ .../options/seperateSections/Mining.java | 75 +++++++- .../notenoughupdates/overlays/OverlayManager.java | 19 +++ .../overlays/PowderGrindingOverlay.java | 188 +++++++++++++++++++++ .../moulberry/notenoughupdates/util/SBInfo.java | 17 +- 9 files changed, 383 insertions(+), 7 deletions(-) create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/listener/WorldListener.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/overlays/PowderGrindingOverlay.java (limited to 'src') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index ea674610..054cbca4 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -35,6 +35,7 @@ import io.github.moulberry.notenoughupdates.listener.ItemTooltipRngListener; import io.github.moulberry.notenoughupdates.listener.NEUEventListener; import io.github.moulberry.notenoughupdates.listener.OldAnimationChecker; import io.github.moulberry.notenoughupdates.listener.RenderListener; +import io.github.moulberry.notenoughupdates.listener.WorldListener; import io.github.moulberry.notenoughupdates.miscfeatures.AbiphoneWarning; import io.github.moulberry.notenoughupdates.miscfeatures.AntiCoopAdd; import io.github.moulberry.notenoughupdates.miscfeatures.AuctionBINWarning; @@ -270,6 +271,10 @@ public class NotEnoughUpdates { saveConfig(); } + if (config != null) + if (config.mining.powderGrindingTrackerResetMode == 2) + OverlayManager.powderGrindingOverlay.load(); + MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(new NEUEventListener(this)); MinecraftForge.EVENT_BUS.register(new RecipeGenerator(this)); @@ -314,6 +319,7 @@ public class NotEnoughUpdates { MinecraftForge.EVENT_BUS.register(new BetterContainers()); MinecraftForge.EVENT_BUS.register(AuctionBINWarning.getInstance()); MinecraftForge.EVENT_BUS.register(navigation); + MinecraftForge.EVENT_BUS.register(new WorldListener(this)); if (Minecraft.getMinecraft().getResourceManager() instanceof IReloadableResourceManager) { IReloadableResourceManager manager = (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager(); @@ -349,6 +355,11 @@ public class NotEnoughUpdates { } public void saveConfig() { + try { + OverlayManager.powderGrindingOverlay.save(); + } catch (Exception ignored) { + } + try { configFile.createNewFile(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java index 62937afc..f85c165a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java @@ -295,11 +295,18 @@ public class ChatListener { unformatted.startsWith(" ") || unformatted.startsWith("✦") || unformatted.equals( " You've earned a Crystal Loot Bundle!")) OverlayManager.crystalHollowOverlay.message(unformatted); + Matcher LvlMatcher = SKYBLOCK_LVL_MESSAGE.matcher(unformatted); if (LvlMatcher.matches()) { - if (Integer.parseInt(LvlMatcher.group(1)) < NotEnoughUpdates.INSTANCE.config.misc.filterChatLevel && NotEnoughUpdates.INSTANCE.config.misc.filterChatLevel != 0) { + if (Integer.parseInt(LvlMatcher.group(1)) < NotEnoughUpdates.INSTANCE.config.misc.filterChatLevel && + NotEnoughUpdates.INSTANCE.config.misc.filterChatLevel != 0) { e.setCanceled(true); } } + + if (unformatted.equals("You uncovered a treasure chest!") || + unformatted.equals("You have successfully picked the lock on this chest!") + || (unformatted.startsWith("You received +") && unformatted.endsWith(" Powder"))) + OverlayManager.powderGrindingOverlay.message(unformatted); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/WorldListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/WorldListener.java new file mode 100644 index 00000000..365b96c5 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/WorldListener.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2022 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.listener; + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.overlays.OverlayManager; +import net.minecraftforge.event.world.WorldEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +public class WorldListener { + + private final NotEnoughUpdates neu; + + public WorldListener(NotEnoughUpdates neu) { + this.neu = neu; + } + + @SubscribeEvent + public void onWorldLoad(WorldEvent.Load e) { + if (neu.config.mining.powderGrindingTrackerResetMode == 0) + OverlayManager.powderGrindingOverlay.reset(); + } + +} 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 a1561658..e18d1d84 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java @@ -197,6 +197,12 @@ public class NEUConfig extends Config { NotEnoughUpdates.INSTANCE.openGui = new GuiScreenElementWrapper(new NEUConfigEditor(NotEnoughUpdates.INSTANCE.config, "apis")); return; + case 25: + editOverlay(activeConfigCategory, OverlayManager.powderGrindingOverlay, mining.powderGrindingTrackerPosition); + return; + case 26: + OverlayManager.powderGrindingOverlay.reset(); + return; default: System.err.printf("Unknown runnableId = %d in category %s%n", runnableId, activeConfigCategory); } @@ -578,6 +584,18 @@ public class NEUConfig extends Config { public HashMap savedEquipment = new HashMap<>(); @Expose public int magicalPower = 0; + + @Expose + public int chestCount = 0; + + @Expose + public int openedChestCount = 0; + + @Expose + public int mithrilPowderFound = 0; + + @Expose + public int gemstonePowderFound = 0; } public HiddenLocationSpecific getLocationSpecific() { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/LocationEdit.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/LocationEdit.java index 48214481..10e554c9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/LocationEdit.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/LocationEdit.java @@ -205,4 +205,16 @@ public class LocationEdit { ) @ConfigAccordionId(id = 3) public Position combatPosition = new Position(10, 200); + + @Expose + @ConfigOption( + name = "Edit Tracker Position", + desc = "Change the position of the Powder Grinding Tracker Overlay (chests and gained powder)" + ) + @ConfigEditorButton( + runnableId = 25, + buttonText = "Edit" + ) + @ConfigAccordionId(id = 9) + public Position powderGrindingTrackerPosition = new Position(10, 265); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java index 727ad329..2568653d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Mining.java @@ -156,7 +156,7 @@ public class Mining { @Expose @ConfigOption( name = "Edit Dwarven Overlay Position", - desc = "Change the position of the Dwarven Mines information Overlay (commisions, powder & forge statuses)" + desc = "Change the position of the Dwarven Mines information Overlay (commissions, powder & forge statuses)" ) @ConfigEditorButton( runnableId = 1, @@ -713,6 +713,79 @@ public class Mining { ) public int wishingCompassWaypointNames = 0; + @ConfigOption( + name = "Powder Grinding Tracker", + desc = "" + ) + @ConfigEditorAccordion(id = 9) + public boolean powderGrindingTrackerAccordion = false; + + + @Expose + @ConfigOption( + name = "Enable Tracker", + desc = "Show an Overlay with useful information related to Power Grinding" + ) + @ConfigAccordionId(id = 9) + @ConfigEditorBoolean + public boolean powderGrindingTrackerEnabled = false; + + @Expose + @ConfigOption( + name = "Tracker Text", + desc = "\u00a7eDrag text to change the appearance of the Overlay\n" + + "\u00a7rGo to the Crystal Hollows to show this Overlay with useful information" + ) + @ConfigEditorDraggableList( + exampleText = { + "\u00a73Chests Found: \u00a7a13", + "\u00a73Opened Chests: \u00a7a11", + "\u00a73Unopened Chests: \u00a7c2", + "\u00a73Mithril Powder Found: \u00a726,243", + "\u00a73Average Mithril Powder/Chest: \u00a72568", + "\u00a73Gemstone Powder Found: \u00a7d6,243", + "\u00a73Average Gemstone Powder/Chest: \u00a7d568" + } + ) + @ConfigAccordionId(id = 9) + public List powderGrindingTrackerText = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5, 6)); + + @Expose + @ConfigOption( + name = "Edit Tracker Position", + desc = "Change the position of the Powder Grinding Tracker Overlay (chests and gained powder)" + ) + @ConfigEditorButton( + runnableId = 25, + buttonText = "Edit" + ) + @ConfigAccordionId(id = 9) + public Position powderGrindingTrackerPosition = new Position(10, 265); + + @Expose + @ConfigOption( + name = "Tracker Reset Mode", + desc = "When the Powder Grinding Tracker should be reset" + ) + @ConfigEditorDropdown( + values = {"On World Change", "On Restart", "Never"}, + initialIndex = 2 + ) + @ConfigAccordionId(id = 9) + public int powderGrindingTrackerResetMode = 2; + + @Expose + @ConfigOption( + name = "Reset Tracker", + desc = "Reset all stats for Powder Grinding Tracker" + ) + @ConfigEditorButton( + runnableId = 26, + buttonText = "Reset" + ) + @ConfigAccordionId(id = 9) + public int resetPowderGrindingTracker = 0; + @Expose @ConfigOption( name = "Puzzler Solver", diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/OverlayManager.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/OverlayManager.java index 84684558..5047882d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/OverlayManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/OverlayManager.java @@ -30,6 +30,7 @@ public class OverlayManager { public static Class dontRenderOverlay = null; public static MiningOverlay miningOverlay; + public static PowderGrindingOverlay powderGrindingOverlay; public static FarmingSkillOverlay farmingOverlay; public static FishingSkillOverlay fishingSkillOverlay; public static MiningSkillOverlay miningSkillOverlay; @@ -98,6 +99,23 @@ public class OverlayManager { return TextOverlayStyle.BACKGROUND; }); + List powderGrindingDummy = Lists.newArrayList( + "\u00a73Chests Found: \u00a7a13", + "\u00a73Opened Chests: \u00a7a11", + "\u00a73Unopened Chests: \u00a7c2", + "\u00a73Mithril Powder Found: \u00a726,243", + "\u00a73Average Mithril Powder/Chest: \u00a72568", + "\u00a73Gemstone Powder Found: \u00a7d6,243", + "\u00a73Average Gemstone Powder/Chest: \u00a7d568" + ); + powderGrindingOverlay = new PowderGrindingOverlay(NotEnoughUpdates.INSTANCE.config.mining.powderGrindingTrackerPosition, () -> { + List strings = new ArrayList<>(); + for (int i : NotEnoughUpdates.INSTANCE.config.mining.powderGrindingTrackerText) { + if (i >= 0 && i < powderGrindingDummy.size()) strings.add(powderGrindingDummy.get(i)); + } + return strings; + }, () -> TextOverlayStyle.BACKGROUND); + List farmingDummy = Lists.newArrayList( "\u00a7bCounter: \u00a7e37,547,860", "\u00a7bCrops/m: \u00a7e38.29", @@ -296,6 +314,7 @@ public class OverlayManager { }); textOverlays.add(miningOverlay); + textOverlays.add(powderGrindingOverlay); textOverlays.add(farmingOverlay); textOverlays.add(miningSkillOverlay); textOverlays.add(combatSkillOverlay); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/PowderGrindingOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/PowderGrindingOverlay.java new file mode 100644 index 00000000..50ecce90 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/PowderGrindingOverlay.java @@ -0,0 +1,188 @@ +/* + * Copyright (C) 2022 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.overlays; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.core.config.Position; +import io.github.moulberry.notenoughupdates.core.util.lerp.LerpUtils; +import io.github.moulberry.notenoughupdates.options.NEUConfig; +import io.github.moulberry.notenoughupdates.util.SBInfo; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.nio.charset.StandardCharsets; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +public class PowderGrindingOverlay extends TextTabOverlay { + + private final static JsonParser PARSER = new JsonParser(); + + + public int chestCount = 0; + public int openedChestCount = 0; + public int mithrilPowderFound = 0; + public float lastMithrilPowderFound = 0; + public float lastMithrilPowderAverage = 0; + public int gemstonePowderFound = 0; + public float lastGemstonePowderFound = 0; + public float lastGemstonePowderAverage = 0; + private long lastUpdate = -1; + + public PowderGrindingOverlay( + Position position, + Supplier> dummyStrings, + Supplier styleSupplier + ) { + super(position, dummyStrings, styleSupplier); + } + + private float interp(float now, float last) { + float interp = now; + if (last >= 0 && last != now) { + float factor = (System.currentTimeMillis() - lastUpdate) / 1000f; + factor = LerpUtils.clampZeroOne(factor); + interp = last + (now - last) * factor; + } + return interp; + } + + @Override + public void update() { + if (NotEnoughUpdates.INSTANCE.config.mining.powderGrindingTrackerEnabled) { + lastUpdate = System.currentTimeMillis(); + lastMithrilPowderFound = this.mithrilPowderFound; + lastMithrilPowderAverage = this.openedChestCount > 0 ? + 1f * this.mithrilPowderFound / this.openedChestCount : + 0; + lastGemstonePowderFound = this.gemstonePowderFound; + lastGemstonePowderAverage = this.openedChestCount > 0 ? + 1f * this.gemstonePowderFound / this.openedChestCount : + 0; + } else overlayStrings = null; + } + + @Override + public void updateFrequent() { + overlayStrings = null; + if (!NotEnoughUpdates.INSTANCE.config.mining.powderGrindingTrackerEnabled) return; + + String location = SBInfo.getInstance().getLocation(); + if (location == null) return; + if (location.equals("crystal_hollows")) { + + overlayStrings = new ArrayList<>(); + for (int index : NotEnoughUpdates.INSTANCE.config.mining.powderGrindingTrackerText) { + NumberFormat format = NumberFormat.getIntegerInstance(); + switch (index) { + case 0: + overlayStrings.add("\u00a73Chests Found: \u00a7a" + format.format(this.chestCount)); + break; + case 1: + overlayStrings.add("\u00a73Opened Chests: \u00a7a" + format.format(this.openedChestCount)); + break; + case 2: + overlayStrings.add("\u00a73Unopened Chests: \u00a7c" + format.format(this.chestCount - this.openedChestCount)); + break; + case 3: + overlayStrings.add("\u00a73Mithril Powder Found: \u00a72" + + format.format(interp(this.mithrilPowderFound, lastMithrilPowderFound))); + break; + case 4: + overlayStrings.add("\u00a73Average Mithril Powder/Chest: \u00a72" + format.format(interp( + (this.openedChestCount > 0 ? + 1f * this.mithrilPowderFound / this.openedChestCount : + 0), lastMithrilPowderAverage))); + break; + case 5: + overlayStrings.add("\u00a73Gemstone Powder Found: \u00a7d" + + format.format(interp(this.gemstonePowderFound, lastGemstonePowderFound))); + break; + case 6: + overlayStrings.add("\u00a73Average Gemstone Powder/Chest: \u00a7d" + format.format(interp( + (this.openedChestCount > 0 ? + 1f * this.gemstonePowderFound / this.openedChestCount : + 0), lastGemstonePowderAverage))); + break; + } + } + } + + if (overlayStrings != null && overlayStrings.isEmpty()) overlayStrings = null; + } + + public void message(String message) { + if (message.equals("You uncovered a treasure chest!")) { + this.chestCount++; + } else if (message.equals("You have successfully picked the lock on this chest!")) { + this.openedChestCount++; + } else { + boolean mithril = message.endsWith(" Mithril Powder"); + boolean gemstone = message.endsWith(" Gemstone Powder"); + if (!(mithril || gemstone)) return; + try { + int amount = Integer.parseInt(message.split(" ")[2].replaceAll("\\+", "")); + if (mithril) this.mithrilPowderFound += amount; + else this.gemstonePowderFound += amount; + } catch (NumberFormatException | IndexOutOfBoundsException e) { + e.printStackTrace(); + } + } + } + + public void load() { + NEUConfig.HiddenProfileSpecific profileSpecific = NotEnoughUpdates.INSTANCE.config.getProfileSpecific(); + if (profileSpecific == null) return; + this.chestCount = profileSpecific.chestCount; + this.openedChestCount = profileSpecific.openedChestCount; + this.mithrilPowderFound = profileSpecific.mithrilPowderFound; + this.gemstonePowderFound = profileSpecific.gemstonePowderFound; + } + + public void save() { + NEUConfig.HiddenProfileSpecific profileSpecific = NotEnoughUpdates.INSTANCE.config.getProfileSpecific(); + if (profileSpecific == null) return; + profileSpecific.chestCount = this.chestCount; + profileSpecific.openedChestCount = this.openedChestCount; + profileSpecific.mithrilPowderFound = this.mithrilPowderFound; + profileSpecific.gemstonePowderFound = this.gemstonePowderFound; + } + + public void reset() { + this.chestCount = 0; + this.openedChestCount = 0; + this.mithrilPowderFound = 0; + this.gemstonePowderFound = 0; + } + +} 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 d78a6988..095dde87 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java @@ -24,6 +24,7 @@ import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.listener.ScoreboardLocationChangeListener; import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.LocationChangeEvent; +import io.github.moulberry.notenoughupdates.overlays.OverlayManager; import io.github.moulberry.notenoughupdates.overlays.SlayerOverlay; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiChest; @@ -302,15 +303,21 @@ public class SBInfo { lastLocRaw = System.currentTimeMillis(); NotEnoughUpdates.INSTANCE.sendChatMessage("/locraw"); } - if (currentTime - lastMayorUpdate > 300 * 1000) { - updateMayor(); - lastMayorUpdate = currentTime; - } + if (currentTime - lastMayorUpdate > 300 * 1000) { + updateMayor(); + lastMayorUpdate = currentTime; + } try { for (NetworkPlayerInfo info : Minecraft.getMinecraft().thePlayer.sendQueue.getPlayerInfoMap()) { String name = Minecraft.getMinecraft().ingameGUI.getTabList().getPlayerName(info); if (name.startsWith(profilePrefix)) { - currentProfile = Utils.cleanColour(name.substring(profilePrefix.length())); + String newProfile = Utils.cleanColour(name.substring(profilePrefix.length())); + if (!Objects.equals(currentProfile, newProfile)) { + currentProfile = newProfile; + if (NotEnoughUpdates.INSTANCE.config != null) + if (NotEnoughUpdates.INSTANCE.config.mining.powderGrindingTrackerResetMode == 2) + OverlayManager.powderGrindingOverlay.load(); + } hasNewTab = true; } else if (name.startsWith(skillsPrefix)) { String levelInfo = name.substring(skillsPrefix.length()).trim(); -- cgit