-
-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
74ed374
commit c4cdd7e
Showing
4 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/main/java/at/hannibal2/skyhanni/features/event/hoppity/ReplaceHoppityWithContributor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, String>() | ||
|
||
@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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters