aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-07 22:27:15 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-07 22:27:15 +0100
commit4c4a0f2dbd15dfc4afa92e3a4c5ca90c0465976f (patch)
treebe7e753265ee9bb44e05211b8f5ccddf60547aeb /src/main
parentd59bf21b3b88a4ee49325403d4285c2a56b1810a (diff)
downloadskyhanni-4c4a0f2dbd15dfc4afa92e3a4c5ca90c0465976f.tar.gz
skyhanni-4c4a0f2dbd15dfc4afa92e3a4c5ca90c0465976f.tar.bz2
skyhanni-4c4a0f2dbd15dfc4afa92e3a4c5ca90c0465976f.zip
Added more Ender Node Tracker features. Added command /shresetendernodetracker to reset the full data, added session support and added button to reset the current session.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/Storage.java15
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt9
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt80
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt1
5 files changed, 66 insertions, 41 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index 81a82904a..cd2a752d0 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -596,7 +596,7 @@ class SkyHanniMod {
loadModule(BestiaryData)
loadModule(KingTalismanHelper())
loadModule(HarpFeatures)
- loadModule(EnderNodeTracker())
+ loadModule(EnderNodeTracker)
loadModule(CompactBestiaryChatMessage())
loadModule(WatchdogHider())
loadModule(AccountUpgradeReminder())
diff --git a/src/main/java/at/hannibal2/skyhanni/config/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/Storage.java
index cf8bd827a..75c9cde83 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/Storage.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/Storage.java
@@ -1,7 +1,7 @@
package at.hannibal2.skyhanni.config;
import at.hannibal2.skyhanni.data.model.ComposterUpgrade;
-import at.hannibal2.skyhanni.features.combat.endernodetracker.EnderNode;
+import at.hannibal2.skyhanni.features.combat.endernodetracker.EnderNodeTracker;
import at.hannibal2.skyhanni.features.combat.ghostcounter.GhostData;
import at.hannibal2.skyhanni.features.dungeon.DungeonAPI;
import at.hannibal2.skyhanni.features.event.jerry.frozentreasure.FrozenTreasure;
@@ -321,18 +321,7 @@ public class Storage {
}
@Expose
- public EnderNodeTracker enderNodeTracker = new EnderNodeTracker();
-
- public static class EnderNodeTracker {
- @Expose
- public int totalNodesMined = 0;
-
- @Expose
- public int totalEndermiteNests = 0;
-
- @Expose
- public Map<EnderNode, Integer> lootCount = new HashMap<>();
- }
+ public EnderNodeTracker.Data enderNodeTracker = new EnderNodeTracker.Data();
@Expose
public RiftStorage rift = new RiftStorage();
diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
index 47d267bbc..3933ed081 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
@@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.data.PartyAPI
import at.hannibal2.skyhanni.features.bingo.BingoCardDisplay
import at.hannibal2.skyhanni.features.bingo.BingoNextStepHelper
import at.hannibal2.skyhanni.features.chat.Translator
+import at.hannibal2.skyhanni.features.combat.endernodetracker.EnderNodeTracker
import at.hannibal2.skyhanni.features.combat.ghostcounter.GhostUtil
import at.hannibal2.skyhanni.features.commands.PartyCommands
import at.hannibal2.skyhanni.features.event.diana.BurrowWarpHelper
@@ -161,8 +162,12 @@ object Commands {
"Clear farming items saved for the Farming Fortune Guide"
) { clearFarmingItems() }
registerCommand("shresetghostcounter", "Resets the ghost counter") { GhostUtil.reset() }
- registerCommand("shresetpowdertracker", "Resets the powder tracker") { PowderTracker.resetCommand(it) }
- registerCommand("shresetdicertracker", "Resets the dicer counter") { DicerDropTracker.resetCommand(it) }
+ registerCommand("shresetpowdertracker", "Resets the Powder Tracker") { PowderTracker.resetCommand(it) }
+ registerCommand("shresetdicertracker", "Resets the Dicer Drop Tracker") { DicerDropTracker.resetCommand(it) }
+ registerCommand(
+ "shresetendernodetracker",
+ "Resets the Ender Node Tracker"
+ ) { EnderNodeTracker.resetCommand(it) }
registerCommand("shbingotoggle", "Toggle the bingo card display mode") { BingoCardDisplay.toggleCommand() }
registerCommand(
"shfarmingprofile",
diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt
index 4d336d326..d73123c23 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt
@@ -2,7 +2,6 @@ package at.hannibal2.skyhanni.features.combat.endernodetracker
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
-import at.hannibal2.skyhanni.config.Storage
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.events.ConfigLoadEvent
@@ -14,20 +13,21 @@ import at.hannibal2.skyhanni.events.SackChangeEvent
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList
+import at.hannibal2.skyhanni.utils.LorenzUtils.addOrPut
import at.hannibal2.skyhanni.utils.LorenzUtils.afterChange
-import at.hannibal2.skyhanni.utils.LorenzUtils.editCopy
import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull
import at.hannibal2.skyhanni.utils.NEUItems.getPriceOrNull
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.format
-import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
+import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker
+import at.hannibal2.skyhanni.utils.tracker.TrackerData
+import com.google.gson.annotations.Expose
import io.github.moulberry.notenoughupdates.util.MinecraftExecutor
import net.minecraft.client.Minecraft
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-class EnderNodeTracker {
+object EnderNodeTracker {
private val config get() = SkyHanniMod.feature.combat.enderNodeTracker
- private val storage get() = ProfileStorageData.profileSpecific?.enderNodeTracker
private var miteGelInInventory = 0
private var display = emptyList<List<Any>>()
@@ -36,6 +36,26 @@ class EnderNodeTracker {
private val enderNodeRegex = Regex("""ENDER NODE!.+You found (\d+x )?§r(.+)§r§f!""")
private val endermanRegex = Regex("""(RARE|PET) DROP! §r(.+) §r§b\(""")
+ private val tracker = SkyHanniTracker("Ender Node Tracker", Data(), { it.enderNodeTracker }) { update() }
+
+ class Data : TrackerData() {
+
+ override fun reset() {
+ totalNodesMined = 0
+ totalEndermiteNests = 0
+ lootCount.clear()
+ }
+
+ @Expose
+ var totalNodesMined = 0
+
+ @Expose
+ var totalEndermiteNests = 0
+
+ @Expose
+ var lootCount: MutableMap<EnderNode, Int> = mutableMapOf()
+ }
+
@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
if (!config.enabled) return
@@ -46,11 +66,12 @@ class EnderNodeTracker {
val message = event.message.trim()
var item: String? = null
var amount = 1
- val storage = storage ?: return
// check whether the loot is from an ender node or an enderman
enderNodeRegex.find(message)?.let {
- storage.totalNodesMined++
+ tracker.modify { storage ->
+ storage.totalNodesMined++
+ }
amount = it.groups[1]?.value?.substringBefore("x")?.toIntOrNull() ?: 1
item = it.groups[2]?.value
} ?: endermanRegex.find(message)?.let {
@@ -61,15 +82,16 @@ class EnderNodeTracker {
when {
item == null -> return
item == "§cEndermite Nest" -> {
- storage.totalEndermiteNests++
+ tracker.modify { storage ->
+ storage.totalEndermiteNests++
+ }
}
}
// increment the count of the specific item found
EnderNode.entries.find { it.displayName == item }?.let {
- val old = storage.lootCount[it] ?: 0
- storage.lootCount = storage.lootCount.editCopy {
- this[it] = old + amount
+ tracker.modify { storage ->
+ storage.lootCount.addOrPut(it, amount)
}
}
update()
@@ -89,15 +111,15 @@ class EnderNodeTracker {
if (!config.enabled) return
if (!ProfileStorageData.loaded) return
if (!isInTheEnd()) return
- val storage = storage ?: return
val change = event.sackChanges
.firstOrNull { it.internalName == EnderNode.MITE_GEL.internalName && it.delta > 0 }
?: return
- val old = storage.lootCount[EnderNode.MITE_GEL] ?: 0
- storage.lootCount = storage.lootCount.editCopy {
- this[EnderNode.MITE_GEL] = old + change.delta
+
+ tracker.modify { storage ->
+ storage.lootCount.addOrPut(EnderNode.MITE_GEL, change.delta)
}
+
update()
}
@@ -106,7 +128,6 @@ class EnderNodeTracker {
if (!config.enabled) return
if (!isInTheEnd()) return
if (!ProfileStorageData.loaded) return
- val storage = storage ?: return
MinecraftExecutor.OnThread.execute {
val newMiteGelInInventory = Minecraft.getMinecraft().thePlayer.inventory.mainInventory
@@ -114,9 +135,8 @@ class EnderNodeTracker {
.sumOf { it.stackSize }
val change = newMiteGelInInventory - miteGelInInventory
if (change > 0) {
- val old = storage.lootCount[EnderNode.MITE_GEL] ?: 0
- storage.lootCount = storage.lootCount.editCopy {
- this[EnderNode.MITE_GEL] = old + change
+ tracker.modify { storage ->
+ storage.lootCount.addOrPut(EnderNode.MITE_GEL, change)
}
update()
}
@@ -125,10 +145,11 @@ class EnderNodeTracker {
}
@SubscribeEvent
- fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) {
+ fun onRenderOverlay(event: GuiRenderEvent) {
if (!config.enabled) return
if (!isInTheEnd()) return
- config.position.renderStringsAndItems(display, posLabel = "Ender Node Tracker")
+
+ tracker.renderDisplay(config.position, display)
}
@SubscribeEvent
@@ -144,7 +165,7 @@ class EnderNodeTracker {
event.move(2, "misc.enderNodeTracker", "combat.enderNodeTracker")
}
- private fun calculateProfit(storage: Storage.ProfileSpecific.EnderNodeTracker): Map<EnderNode, Double> {
+ private fun calculateProfit(storage: Data): Map<EnderNode, Double> {
if (!ProfileStorageData.loaded) return emptyMap()
val newProfit = mutableMapOf<EnderNode, Double>()
@@ -163,7 +184,7 @@ class EnderNodeTracker {
}
private fun update() {
- val storage = storage ?: return
+ val storage = tracker.currentDisplay() ?: return
lootProfit = calculateProfit(storage)
display = formatDisplay(drawDisplay(storage))
}
@@ -190,10 +211,13 @@ class EnderNodeTracker {
else -> null
}
- private fun drawDisplay(storage: Storage.ProfileSpecific.EnderNodeTracker) = buildList<List<Any>> {
+ private fun drawDisplay(storage: Data) = buildList<List<Any>> {
if (!ProfileStorageData.loaded) return emptyList<List<Any>>()
addAsSingletonList("§5§lEnder Node Tracker")
+
+ tracker.addDisplayModeToggle(this)
+
addAsSingletonList("§d${storage.totalNodesMined.addSeparators()} Ender Nodes mined")
addAsSingletonList("§6${format(lootProfit.values.sum())} Coins made")
addAsSingletonList(" ")
@@ -220,9 +244,11 @@ class EnderNodeTracker {
val (c, u, r, e, l) = EnderNode.entries.subList(16, 21).map { (storage.lootCount[it] ?: 0).addSeparators() }
val profit = format(EnderNode.entries.subList(16, 21).sumOf { lootProfit[it] ?: 0.0 })
addAsSingletonList("§f$c§7-§a$u§7-§9$r§7-§5$e§7-§6$l §fEnderman Pet §7(§6$profit§7)")
+
+ tracker.addSessionResetButton(this)
}
- private fun calculateEnderArmor(storage: Storage.ProfileSpecific.EnderNodeTracker) =
+ private fun calculateEnderArmor(storage: Data) =
storage.lootCount.filter { isEnderArmor(it.key) }
.map { it.value }
.sum()
@@ -236,4 +262,8 @@ class EnderNodeTracker {
}
return newList
}
+
+ fun resetCommand(args: Array<String>) {
+ tracker.resetCommand(args, "shresetendernodetracker")
+ }
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt
index 4d7b74243..6ff8febc7 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt
@@ -45,6 +45,7 @@ class SkyHanniTracker<Data : TrackerData>(
}
}
+ // rename
fun currentDisplay() = getSharedTracker()?.getCurrent()
fun resetCommand(args: Array<String>, command: String) {