Skip to content

Commit 960621e

Browse files
authored
Backend: Contributor Rabbit Name (#3109)
Co-authored-by: hannibal2 <[email protected]>
1 parent 8347d2a commit 960621e

File tree

4 files changed

+96
-2
lines changed

4 files changed

+96
-2
lines changed

src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java

+5
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ public class ChocolateFactoryConfig {
9191
@ConfigEditorBoolean
9292
public boolean showStackSizes = true;
9393

94+
@Expose
95+
@ConfigOption(name = "Contributor Rabbit Name", desc = "Replaces the rabbit names in the rabbit collection menu with SkyHanni contributor names.")
96+
@ConfigEditorBoolean
97+
public boolean contributorRabbitName = false;
98+
9499
@Expose
95100
@ConfigOption(name = "Highlight Upgrades", desc = "Highlight any upgrades that you can afford.\n" +
96101
"The upgrade with a star is the most optimal and the lightest color of green is the most optimal you can afford.")

src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCollectionData.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
88

99
@SkyHanniModule
1010
object HoppityCollectionData {
11-
private val rabbitRarities = mutableMapOf<String, RabbitCollectionRarity>()
11+
val rabbitRarities = mutableMapOf<String, RabbitCollectionRarity>()
1212
private val rarityBonuses = mutableMapOf<RabbitCollectionRarity, ChocolateBonuses>()
1313
private val specialBonuses = mutableMapOf<String, ChocolateBonuses>()
1414

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package at.hannibal2.skyhanni.features.event.hoppity
2+
3+
import at.hannibal2.skyhanni.api.event.HandleEvent
4+
import at.hannibal2.skyhanni.events.NeuRepositoryReloadEvent
5+
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
6+
import at.hannibal2.skyhanni.events.item.ItemHoverEvent
7+
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryAPI
8+
import at.hannibal2.skyhanni.features.misc.ContributorManager
9+
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
10+
import at.hannibal2.skyhanni.utils.CircularList
11+
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
12+
import at.hannibal2.skyhanni.utils.ItemUtils.name
13+
import at.hannibal2.skyhanni.utils.LorenzUtils
14+
import at.hannibal2.skyhanni.utils.StringUtils.allLettersFirstUppercase
15+
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
16+
import net.minecraftforge.fml.common.eventhandler.EventPriority
17+
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
18+
19+
@SkyHanniModule
20+
object ReplaceHoppityWithContributor {
21+
22+
private val config get() = ChocolateFactoryAPI.config
23+
24+
private val replaceMap = mutableMapOf<String, String>()
25+
26+
@HandleEvent(priority = 5)
27+
fun onNeuRepoReload(event: NeuRepositoryReloadEvent) {
28+
update()
29+
}
30+
31+
@SubscribeEvent(priority = EventPriority.LOW)
32+
fun onRepoReload(event: RepositoryReloadEvent) {
33+
update()
34+
}
35+
36+
fun update() {
37+
replaceMap.clear()
38+
39+
val contributors = ContributorManager.contributorNames
40+
val rabbits = HoppityCollectionData.rabbitRarities
41+
42+
if (contributors.isEmpty()) return
43+
if (rabbits.isEmpty()) return
44+
45+
val newNames = CircularList(contributors.toList())
46+
for (internalName in rabbits.map { it.key }.shuffled()) {
47+
val realName = internalName.allLettersFirstUppercase()
48+
val newName = newNames.next()
49+
replaceMap[realName] = newName
50+
}
51+
}
52+
53+
@HandleEvent(priority = HandleEvent.LOWEST)
54+
fun onTooltip(event: ItemHoverEvent) {
55+
if (!isEnabled()) return
56+
if (!HoppityCollectionStats.inInventory) return
57+
58+
val itemStack = event.itemStack
59+
val lore = itemStack.getLore()
60+
val last = lore.lastOrNull() ?: return
61+
if (!last.endsWith(" RABBIT")) return
62+
63+
val realName = itemStack.name
64+
val cleanName = realName.removeColor()
65+
val fakeName = replaceMap[cleanName] ?: return
66+
67+
val newName = event.toolTip[0].replace(cleanName, fakeName)
68+
event.toolTip[0] = newName
69+
70+
event.toolTip.add(" ")
71+
event.toolTip.add("§8§oSome might say this rabbit is also known as $realName")
72+
73+
// TODO find a way to handle non containing entries in a kotlin nullable way instead of checking for -1
74+
val index = event.toolTip.indexOfFirst { it.contains(" a duplicate") }
75+
if (index == -1) return
76+
val oldLine = event.toolTip[index]
77+
val newLine = oldLine.replace(cleanName, fakeName)
78+
event.toolTip[index] = newLine
79+
}
80+
81+
fun isEnabled() = LorenzUtils.inSkyBlock && config.contributorRabbitName
82+
}

src/main/java/at/hannibal2/skyhanni/features/misc/ContributorManager.kt

+8-1
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
1616
object ContributorManager {
1717
private val config get() = SkyHanniMod.feature.dev
1818

19+
// Key is the lowercase contributor name
1920
private var contributors: Map<String, ContributorJsonEntry> = emptyMap()
2021

22+
// Just the names of the contributors including their proper case
23+
var contributorNames = emptyList<String>()
24+
private set
25+
2126
@SubscribeEvent
2227
fun onRepoReload(event: RepositoryReloadEvent) {
23-
contributors = event.getConstant<ContributorsJson>("Contributors").contributors.mapKeys { it.key.lowercase() }
28+
val map = event.getConstant<ContributorsJson>("Contributors").contributors
29+
contributors = map.mapKeys { it.key.lowercase() }
30+
contributorNames = map.map { it.key }
2431
}
2532

2633
@HandleEvent

0 commit comments

Comments
 (0)