From c4cdd7e1bcd1c7a2a7e84c0477f7fead1c5d585e Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Tue, 24 Dec 2024 03:30:26 +0100 Subject: [PATCH] added rabbit name as contributor --- .../ChocolateFactoryConfig.java | 5 ++ .../event/hoppity/HoppityCollectionData.kt | 2 +- .../hoppity/ReplaceHoppityWithContributor.kt | 82 +++++++++++++++++++ .../features/misc/ContributorManager.kt | 9 +- 4 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/event/hoppity/ReplaceHoppityWithContributor.kt diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java index a6c6847671ec..f564449de0f4 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java @@ -91,6 +91,11 @@ public class ChocolateFactoryConfig { @ConfigEditorBoolean public boolean showStackSizes = true; + @Expose + @ConfigOption(name = "Contributor Rabbit Name", desc = "Replaces the rabbit names in the rabbit collection menu with SkyHanni contributor names.") + @ConfigEditorBoolean + public boolean contributorRabbitName = false; + @Expose @ConfigOption(name = "Highlight Upgrades", desc = "Highlight any upgrades that you can afford.\n" + "The upgrade with a star is the most optimal and the lightest color of green is the most optimal you can afford.") diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCollectionData.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCollectionData.kt index b6056451dd66..11b3d305309b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCollectionData.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCollectionData.kt @@ -8,7 +8,7 @@ import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule @SkyHanniModule object HoppityCollectionData { - private val rabbitRarities = mutableMapOf() + val rabbitRarities = mutableMapOf() private val rarityBonuses = mutableMapOf() private val specialBonuses = mutableMapOf() diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/ReplaceHoppityWithContributor.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/ReplaceHoppityWithContributor.kt new file mode 100644 index 000000000000..e94b45a6fd43 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/ReplaceHoppityWithContributor.kt @@ -0,0 +1,82 @@ +package at.hannibal2.skyhanni.features.event.hoppity + +import at.hannibal2.skyhanni.api.event.HandleEvent +import at.hannibal2.skyhanni.events.NeuRepositoryReloadEvent +import at.hannibal2.skyhanni.events.RepositoryReloadEvent +import at.hannibal2.skyhanni.events.item.ItemHoverEvent +import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryAPI +import at.hannibal2.skyhanni.features.misc.ContributorManager +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.CircularList +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.StringUtils.allLettersFirstUppercase +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@SkyHanniModule +object ReplaceHoppityWithContributor { + + private val config get() = ChocolateFactoryAPI.config + + private var replaceMap = mutableMapOf() + + @HandleEvent(priority = 5) + fun onNeuRepoReload(event: NeuRepositoryReloadEvent) { + update() + } + + @SubscribeEvent(priority = EventPriority.LOW) + fun onRepoReload(event: RepositoryReloadEvent) { + update() + } + + fun update() { + replaceMap.clear() + + val contributors = ContributorManager.contributorNames + val rabbits = HoppityCollectionData.rabbitRarities + + if (contributors.isEmpty()) return + if (rabbits.isEmpty()) return + + val newNames = CircularList(contributors.toList()) + for (internalName in rabbits.map { it.key }.shuffled()) { + val realName = internalName.replace("_", " ").allLettersFirstUppercase() + val newName = newNames.next() + replaceMap[realName] = newName + } + } + + @HandleEvent(priority = HandleEvent.LOWEST) + fun onTooltip(event: ItemHoverEvent) { + if (!isEnabled()) return + if (!HoppityCollectionStats.inInventory) return + + val itemStack = event.itemStack + val lore = itemStack.getLore() + val last = lore.lastOrNull() ?: return + if (!last.endsWith(" RABBIT")) return + + val realName = itemStack.name + val cleanName = realName.removeColor() + val fakeName = replaceMap[cleanName] ?: return + + val newName = event.toolTip[0].replace(cleanName, fakeName) + event.toolTip[0] = newName + + // TODO find a way to handle non containing entries in a kotlin nullable way instead of checking for -1 + val index = event.toolTip.indexOfFirst { it.contains(" a duplicate") } + if (index == -1) return + val oldLine = event.toolTip[index] + val newLine = oldLine.replace(cleanName, fakeName) + event.toolTip[index] = newLine + + event.toolTip.add(" ") + event.toolTip.add("§8§oSome might say this rabbit is also known as $realName") + } + + fun isEnabled() = LorenzUtils.inSkyBlock && config.contributorRabbitName +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/ContributorManager.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/ContributorManager.kt index ff5bdcacb66c..e4f2e54547a1 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/ContributorManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/ContributorManager.kt @@ -16,11 +16,18 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object ContributorManager { private val config get() = SkyHanniMod.feature.dev + // Key is the lowercase contributor name private var contributors: Map = emptyMap() + // Just the names of the contributors including their proper case + var contributorNames = emptyList() + private set + @SubscribeEvent fun onRepoReload(event: RepositoryReloadEvent) { - contributors = event.getConstant("Contributors").contributors.mapKeys { it.key.lowercase() } + val map = event.getConstant("Contributors").contributors + contributors = map.mapKeys { it.key.lowercase() } + contributorNames = map.map { it.key } } @HandleEvent