diff options
author | SeRaid <77941535+SeRaid743@users.noreply.github.com> | 2024-04-30 02:28:35 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-29 16:28:35 +0200 |
commit | 23ddb498b2531545ed29223c080a97b7f6dee4c0 (patch) | |
tree | abb2056428dd3286f80db0a3c6996d1179c9dd37 /src/main/java/at | |
parent | a5a77b601c7d82661206b0b3437fe2d09e660587 (diff) | |
download | skyhanni-23ddb498b2531545ed29223c080a97b7f6dee4c0.tar.gz skyhanni-23ddb498b2531545ed29223c080a97b7f6dee4c0.tar.bz2 skyhanni-23ddb498b2531545ed29223c080a97b7f6dee4c0.zip |
Chocfactory assorted (#1517)
Co-authored-by: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com>
Co-authored-by: Cal <cwolfson58@gmail.com>
Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at')
8 files changed, 159 insertions, 7 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 2aa4e17fb..8ccde7039 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -135,6 +135,7 @@ import at.hannibal2.skyhanni.features.event.chocolatefactory.HoppityCollectionSt import at.hannibal2.skyhanni.features.event.chocolatefactory.HoppityEggLocator import at.hannibal2.skyhanni.features.event.chocolatefactory.HoppityEggsManager import at.hannibal2.skyhanni.features.event.chocolatefactory.HoppityEggsShared +import at.hannibal2.skyhanni.features.event.chocolatefactory.HoppityNpc import at.hannibal2.skyhanni.features.event.chocolatefactory.clicks.FactoryItemTooltipFeatures import at.hannibal2.skyhanni.features.event.diana.AllBurrowsList import at.hannibal2.skyhanni.features.event.diana.BurrowWarpHelper @@ -631,6 +632,7 @@ class SkyHanniMod { loadModule(ChocolateFactoryStats) loadModule(FactoryItemTooltipFeatures) loadModule(ChocolateFactoryTimeTowerManager) + loadModule(HoppityNpc) loadModule(HoppityEggsManager) loadModule(HoppityEggLocator) loadModule(HoppityEggsShared) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/event/ChocolateFactoryConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/event/ChocolateFactoryConfig.java index d67838532..6316ca34d 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/event/ChocolateFactoryConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/event/ChocolateFactoryConfig.java @@ -133,4 +133,10 @@ public class ChocolateFactoryConfig { @Expose @ConfigLink(owner = ChocolateFactoryConfig.class, field = "tooltipMove") public Position tooltipMovePosition = new Position(-380, 150, false, true); + + @Expose + @ConfigOption(name = "Highlight Hoppity Shop", desc = "Highlight items that haven't been bought from the Hoppity shop yet.") + @ConfigEditorBoolean + @FeatureToggle + public boolean highlightHoppityShop = true; } diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryAPI.kt index 84bce4b3d..e00f2073c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryAPI.kt @@ -96,6 +96,10 @@ object ChocolateFactoryAPI { "timetower.recharge", "§7Next Charge: §a(?<duration>\\w+)" ) + private val chocolateFactoryInventoryNamePattern by patternGroup.pattern( + "inventory.name", + "Hoppity|Chocolate Shop|Chocolate Factory Milestones" + ) var rabbitSlots = mapOf<Int, Int>() var otherUpgradeSlots = setOf<Int>() @@ -110,6 +114,7 @@ object ChocolateFactoryAPI { var maxRabbits = 395 var inChocolateFactory = false + var chocolateFactoryPaused = false var currentPrestige = 1 var chocolatePerSecond = 0.0 @@ -125,6 +130,12 @@ object ChocolateFactoryAPI { @SubscribeEvent fun onInventoryOpen(event: InventoryFullyOpenedEvent) { if (!isEnabled()) return + + if (chocolateFactoryInventoryNamePattern.matches(event.inventoryName)) { + chocolateFactoryPaused = true + ChocolateFactoryStats.updateDisplay() + return + } if (event.inventoryName != "Chocolate Factory") return inChocolateFactory = true @@ -287,6 +298,7 @@ object ChocolateFactoryAPI { private fun clearData() { inChocolateFactory = false + chocolateFactoryPaused = false } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryStats.kt b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryStats.kt index 08de9fbf6..30eaecc0e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryStats.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryStats.kt @@ -2,25 +2,44 @@ package at.hannibal2.skyhanni.features.event.chocolatefactory import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.utils.ClipboardUtils +import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators -import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings +import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import at.hannibal2.skyhanni.utils.StringUtils.width import at.hannibal2.skyhanni.utils.TimeUtils.format +import at.hannibal2.skyhanni.utils.renderables.Renderable import com.google.gson.JsonPrimitive import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration object ChocolateFactoryStats { private val config get() = ChocolateFactoryAPI.config private val profileStorage get() = ChocolateFactoryAPI.profileStorage - private var displayList = listOf<String>() + private var displayList = mutableListOf<Renderable>() + private var displayText = mutableListOf<String>() @SubscribeEvent fun onBackgroundDraw(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) { - if (!ChocolateFactoryAPI.inChocolateFactory) return + if (!ChocolateFactoryAPI.inChocolateFactory && !ChocolateFactoryAPI.chocolateFactoryPaused) return if (!config.statsDisplay) return - config.position.renderStrings(displayList, posLabel = "Chocolate Factory Stats") + config.position.renderRenderables(listOf(Renderable.clickAndHover( + Renderable.verticalContainer(displayList), + tips = listOf("§bCopy to Clipboard!"), + onClick = { + val titleHeader = displayText.indexOf("§6§lChocolate Factory Stats") + if (titleHeader != -1) { + displayText[titleHeader] = "${LorenzUtils.getPlayerName()}'s Chocolate Factory Stats" + } else { + displayText.add(0, "${LorenzUtils.getPlayerName()}'s Chocolate Factory Stats") + } + ClipboardUtils.copyToClipboard(displayText.joinToString("\n") { it.removeColor() }) + } + )), posLabel = "Chocolate Factory Stats") } fun updateDisplay() { @@ -40,7 +59,14 @@ object ChocolateFactoryStats { val timeUntilPrestige = ChocolateAmount.PRESTIGE.timeUntilGoal(ChocolateFactoryAPI.chocolateForPrestige) - displayList = formatList(buildList { + // todo once TimeUtils.formatDuration() is no longer used add custom formatting for infinite + val prestigeEstimate = if (timeUntilPrestige == Duration.INFINITE) { + "§cNever" + } else { + "§6${timeUntilPrestige.format()}" + } + + displayText = formatList(buildList { add("§6§lChocolate Factory Stats") add("§eCurrent Chocolate: §6${ChocolateAmount.CURRENT.formatted}") @@ -62,15 +88,27 @@ object ChocolateFactoryStats { add("") add("§eTime Tower: §6$timeTowerInfo") - add("§eTime To Prestige: §6${timeUntilPrestige.format()}") + add("§eTime To Prestige: $prestigeEstimate") add("§eRaw Per Second: §6${profileStorage.rawChocPerSecond.addSeparators()}") }) + + val firstElement = displayText.firstOrNull { it.isNotEmpty() } ?: return + + if (ChocolateFactoryAPI.chocolateFactoryPaused) { + val leftMargin = (firstElement.width() - "§f(§cPaused§f)".width()) / 2 + val spaceWidth = " ".width() + displayText.add(0, "${" ".repeat(leftMargin / spaceWidth)}§f(§cPaused§f)") + } else { + displayText.add(0, "") + } + displayList = displayText.map(Renderable::string).toMutableList() } - private fun formatList(list: List<String>): List<String> { + private fun formatList(list: List<String>): MutableList<String> { return config.statsDisplayList .filter { it.shouldDisplay() } .map { list[it.ordinal] } + .toMutableList() } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/HoppityCollectionStats.kt b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/HoppityCollectionStats.kt index 90895468c..92461db88 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/HoppityCollectionStats.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/HoppityCollectionStats.kt @@ -38,6 +38,10 @@ class HoppityCollectionStats { "rabbit.notfound", "(?:§.)+You have not found this rabbit yet!" ) + private val rabbitsFoundPattern by patternGroup.pattern( + "rabbits.found", + "§.§l§m[ §a-z]+§r §.(?<current>[0-9]+)§./§.(?<total>[0-9]+)" + ) private var display = emptyList<Renderable>() private val loggedRabbits = mutableMapOf<String, RabbitCollectionInfo>() @@ -51,6 +55,8 @@ class HoppityCollectionStats { inInventory = true + var totalAmount = 0 + for ((_, item) in event.inventoryItems) { val itemName = item.displayName ?: continue val itemLore = item.getLore() @@ -67,6 +73,10 @@ class HoppityCollectionStats { duplicatesFound = group("duplicates").formatInt() } if (rabbitNotFoundPattern.matches(line)) found = false + + rabbitsFoundPattern.matchMatcher(line) { + totalAmount = group("total").formatInt() + } } val rarity = rabbitRarity ?: continue @@ -131,6 +141,18 @@ class HoppityCollectionStats { val newList = mutableListOf<Renderable>() newList.add(Renderable.string("§eHoppity Rabbit Collection§f:")) newList.add(LorenzUtils.fillTable(table, padding = 5)) + + if (totalAmount != totalRabbits) { + newList.add(Renderable.string("")) + newList.add( + Renderable.wrappedString( + "§cPlease Scroll through \n" + + "§call pages!", + width = 200, + ) + ) + } + display = newList } diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/HoppityEggLocator.kt b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/HoppityEggLocator.kt index ff271b2b4..f375dd4bb 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/HoppityEggLocator.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/HoppityEggLocator.kt @@ -140,6 +140,7 @@ object HoppityEggLocator { ticksSinceLastParticleFound = 0 validParticleLocations.clear() + lastParticlePosition = null } private fun calculateEggPosition() { diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/HoppityNpc.kt b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/HoppityNpc.kt new file mode 100644 index 000000000..527b3ea40 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/HoppityNpc.kt @@ -0,0 +1,66 @@ +package at.hannibal2.skyhanni.features.event.chocolatefactory + +import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.InventoryCloseEvent +import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent +import at.hannibal2.skyhanni.events.InventoryUpdatedEvent +import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.LorenzColor +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.RenderUtils.highlight +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +object HoppityNpc { + + private val config get() = ChocolateFactoryAPI.config + + private var slotsToHighlight = mutableSetOf<Int>() + private var inShop = false + + @SubscribeEvent + fun onInventoryOpen(event: InventoryFullyOpenedEvent) { + if (!isEnabled()) return + if (event.inventoryName != "Hoppity") return + inShop = true + } + + private fun clear() { + inShop = false + slotsToHighlight.clear() + } + + @SubscribeEvent + fun onInventoryClose(event: InventoryCloseEvent) { + clear() + } + + @SubscribeEvent + fun onWorldChange(event: LorenzWorldChangeEvent) { + clear() + } + + @SubscribeEvent + fun onInventoryUpdated(event: InventoryUpdatedEvent) { + if (!inShop) return + slotsToHighlight.clear() + for ((slot, item) in event.inventoryItems) { + if (item.getLore().contains("§eClick to trade!")) { + slotsToHighlight.add(slot) + } + } + } + + @SubscribeEvent + fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { + if (!inShop) return + for (slot in InventoryUtils.getItemsInOpenChest()) { + if (slot.slotIndex in slotsToHighlight) { + slot highlight LorenzColor.GREEN.addOpacity(200) + } + } + } + + fun isEnabled() = LorenzUtils.inSkyBlock && config.highlightHoppityShop +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index 56a366dc3..388700128 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.mixins.transformers.AccessorChatComponentText import at.hannibal2.skyhanni.utils.GuiRenderUtils.darkenColor import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.StringUtils.width import net.minecraft.client.Minecraft import net.minecraft.client.gui.GuiUtilRenderComponents import net.minecraft.util.ChatComponentText @@ -369,4 +370,8 @@ object StringUtils { text = newText } } + + fun String.width(): Int { + return Minecraft.getMinecraft().fontRendererObj.getStringWidth(this) + } } |