aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/garden
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/garden')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerDropTracker.kt (renamed from src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerRngDropCounter.kt)129
1 files changed, 77 insertions, 52 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerRngDropCounter.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerDropTracker.kt
index d72540720..a3b4f73cb 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerRngDropCounter.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerDropTracker.kt
@@ -1,8 +1,10 @@
package at.hannibal2.skyhanni.features.garden.farming
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.config.ConfigManager
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
-import at.hannibal2.skyhanni.events.ConfigLoadEvent
+import at.hannibal2.skyhanni.config.Storage.ProfileSpecific.GardenStorage.DicerDropTracker
+import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.events.GardenToolChangeEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
@@ -10,19 +12,28 @@ import at.hannibal2.skyhanni.events.PreProfileSwitchEvent
import at.hannibal2.skyhanni.features.garden.CropType
import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.utils.ItemUtils.name
+import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList
+import at.hannibal2.skyhanni.utils.LorenzUtils.addOrPut
import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
-import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
+import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
+import at.hannibal2.skyhanni.utils.tracker.DisplayMode
+import at.hannibal2.skyhanni.utils.tracker.SharedTracker
+import at.hannibal2.skyhanni.utils.tracker.TrackerUtils
+import at.hannibal2.skyhanni.utils.tracker.TrackerUtils.addDisplayModeToggle
+import at.hannibal2.skyhanni.utils.tracker.TrackerUtils.addSessionResetButton
+import net.minecraft.client.Minecraft
+import net.minecraft.client.gui.inventory.GuiInventory
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-class DicerRngDropCounter {
- private var display = emptyList<String>()
- private val drops = mutableMapOf<CropType, MutableMap<DropRarity, Int>>()
+object DicerDropTracker {
+ private var display = emptyList<List<Any>>()
private val itemDrops = mutableListOf<ItemDrop>()
private val config get() = SkyHanniMod.feature.garden.dicerCounters
+ private val currentSessionData = DicerDropTracker()
+ private var inventoryOpen = false
init {
- initDrops()
itemDrops.add(ItemDrop(CropType.MELON, DropRarity.UNCOMMON, "§a§lUNCOMMON DROP! §r§eDicer dropped §r§a(\\d+)x §r§aEnchanted Melon§r§e!".toRegex()))
itemDrops.add(ItemDrop(CropType.MELON, DropRarity.RARE, "§9§lRARE DROP! §r§eDicer dropped §r§a(\\d+)x §r§aEnchanted Melon§r§e!".toRegex()))
itemDrops.add(ItemDrop(CropType.MELON, DropRarity.CRAZY_RARE, "§d§lCRAZY RARE DROP! §r§eDicer dropped §r§[a|9](\\d+)x §r§[a|9]Enchanted Melon(?: Block)?§r§e!".toRegex()))
@@ -34,11 +45,6 @@ class DicerRngDropCounter {
itemDrops.add(ItemDrop(CropType.PUMPKIN, DropRarity.PRAY_TO_RNGESUS, "§5§lPRAY TO RNGESUS DROP! §r§eDicer dropped §r§[a|9](\\d+)x §r§(aEnchanted|9Polished) Pumpkin§r§e!".toRegex()))
}
- private fun initDrops() {
- drops[CropType.MELON] = mutableMapOf()
- drops[CropType.PUMPKIN] = mutableMapOf()
- }
-
enum class DropRarity(val displayName: String) {
UNCOMMON("§a§lUNCOMMON DROP"),
RARE("§9§lRARE DROP"),
@@ -49,8 +55,6 @@ class DicerRngDropCounter {
@SubscribeEvent
fun onPreProfileSwitch(event: PreProfileSwitchEvent) {
display = emptyList()
- drops.clear()
- initDrops()
}
@SubscribeEvent
@@ -62,10 +66,8 @@ class DicerRngDropCounter {
for (drop in itemDrops) {
if (drop.pattern.matches(message)) {
addDrop(drop.crop, drop.rarity)
- saveConfig()
- update()
if (config.hideChat) {
- event.blockedReason = "dicer_rng_drop_counter"
+ event.blockedReason = "dicer_drop_tracker"
}
return
}
@@ -73,19 +75,30 @@ class DicerRngDropCounter {
}
private fun update() {
- display = drawDisplay()
+ currentDisplay()?.let {
+ display = drawDisplay(it)
+ }
}
- private fun drawDisplay(): List<String> {
- val help = mutableListOf<String>()
- val items = drops[cropInHand] ?: return help
- help.add("§7RNG Drops for $toolName§7:")
+ private fun drawDisplay(storage: DicerDropTracker) = buildList<List<Any>> {
+ val cropInHand = cropInHand ?: return@buildList
+ val items = storage.drops.getOrPut(cropInHand) { mutableMapOf() }
+ addAsSingletonList("§7Dicer Drop Tracker for $toolName§7:")
+ if (inventoryOpen) {
+ addDisplayModeToggle {
+ update()
+ }
+ }
for ((rarity, amount) in items.sortedDesc()) {
val displayName = rarity.displayName
- help.add(" §7- §e${amount.addSeparators()}x $displayName")
+ addAsSingletonList(" §7- §e${amount.addSeparators()}x $displayName")
}
- return help
+ if (inventoryOpen && TrackerUtils.currentDisplayMode == DisplayMode.CURRENT) {
+ addSessionResetButton("Dicer Drop Tracker", getSharedTracker()) {
+ update()
+ }
+ }
}
private var cropInHand: CropType? = null
@@ -102,42 +115,27 @@ class DicerRngDropCounter {
}
private fun addDrop(crop: CropType, rarity: DropRarity) {
- val map = drops[crop]!!
- val old = map[rarity] ?: 0
- map[rarity] = old + 1
- }
-
- @SubscribeEvent
- fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) {
- if (isEnabled()) {
- config.pos.renderStrings(display, posLabel = "Dicer Counter")
+ val sharedTracker = getSharedTracker() ?: return
+ sharedTracker.modify {
+ val map = it.drops.getOrPut(crop) { mutableMapOf() }
+ map.addOrPut(rarity, 1)
}
+ update()
}
- class ItemDrop(val crop: CropType, val rarity: DropRarity, val pattern: Regex)
+ @SubscribeEvent
+ fun onRenderOverlay(event: GuiRenderEvent) {
+ if (!isEnabled()) return
- private fun saveConfig() {
- val map = GardenAPI.storage?.dicerRngDrops ?: return
- map.clear()
- for (drop in drops) {
- val crop = drop.key
- for ((rarity, amount) in drop.value) {
- map[crop.cropName + "." + rarity.name] = amount
- }
+ val currentlyOpen = Minecraft.getMinecraft().currentScreen is GuiInventory
+ if (inventoryOpen != currentlyOpen) {
+ inventoryOpen = currentlyOpen
+ update()
}
+ config.pos.renderStringsAndItems(display, posLabel = "Dicer Drop Tracker")
}
- @SubscribeEvent
- fun onConfigLoad(event: ConfigLoadEvent) {
- val map = GardenAPI.storage?.dicerRngDrops ?: return
- for ((internalName, amount) in map) {
- val split = internalName.split(".")
- val crop = CropType.getByName(split[0])
- val rarityName = split[1]
- val rarity = DropRarity.valueOf(rarityName)
- drops[crop]!![rarity] = amount
- }
- }
+ class ItemDrop(val crop: CropType, val rarity: DropRarity, val pattern: Regex)
fun isEnabled() = GardenAPI.inGarden() && config.display
@@ -146,5 +144,32 @@ class DicerRngDropCounter {
event.move(3, "garden.dicerCounterDisplay", "garden.dicerCounters.display")
event.move(3, "garden.dicerCounterHideChat", "garden.dicerCounters.hideChat")
event.move(3, "garden.dicerCounterPos", "garden.dicerCounters.pos")
+
+ event.move(7, "#profile.garden.dicerRngDrops", "#profile.garden.dicerDropTracker.drops") { old ->
+ val items: MutableMap<CropType, MutableMap<DropRarity, Int>> = mutableMapOf()
+ val oldItems = ConfigManager.gson.fromJson<Map<String, Int>>(old, Map::class.java)
+ for ((internalName, amount) in oldItems) {
+ val split = internalName.split(".")
+ val crop = CropType.getByName(split[0])
+ val rarityName = split[1]
+ val rarity = DropRarity.valueOf(rarityName)
+ items.getOrPut(crop) { mutableMapOf() }[rarity] = amount
+ }
+
+ ConfigManager.gson.toJsonTree(items)
+ }
+ }
+
+ private fun currentDisplay() = getSharedTracker()?.getCurrent()
+
+ private fun getSharedTracker(): SharedTracker<DicerDropTracker>? {
+ val profileSpecific = ProfileStorageData.profileSpecific ?: return null
+ return SharedTracker(profileSpecific.garden.dicerDropTracker, currentSessionData)
+ }
+
+ fun resetCommand(args: Array<String>) {
+ TrackerUtils.resetCommand("Dicer Drop Tracker", "shresetdicertracker", args, getSharedTracker()) {
+ update()
+ }
}
}