diff options
author | appable <enzospiacitelli@gmail.com> | 2023-04-10 17:44:46 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-11 02:44:46 +0200 |
commit | 04cfe48dbbc58da81c8390dfb20216a7258cba3e (patch) | |
tree | 09b517607af1cb71b2207981fc13115eb6696d91 /src/main/java/at/hannibal2/skyhanni/data | |
parent | 65d8a310f7880d1acfe799dbc0c90cc9cef08610 (diff) | |
download | skyhanni-04cfe48dbbc58da81c8390dfb20216a7258cba3e.tar.gz skyhanni-04cfe48dbbc58da81c8390dfb20216a7258cba3e.tar.bz2 skyhanni-04cfe48dbbc58da81c8390dfb20216a7258cba3e.zip |
Farming fortune display (#34)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt new file mode 100644 index 000000000..c9bf25047 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt @@ -0,0 +1,54 @@ +package at.hannibal2.skyhanni.data + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.CropUpgradeUpdateEvent +import at.hannibal2.skyhanni.events.InventoryOpenEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.features.garden.CropType +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.ItemUtils.name +import io.github.moulberry.notenoughupdates.util.stripControlCodes +import net.minecraftforge.event.world.WorldEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class GardenCropUpgrades { + private val tierPattern = "§7Current Tier: §[0-9a-e](\\d)§7/§a9".toRegex() + private val chatUpgradePattern = " {2}§r§6§lCROP UPGRADE §e§f([\\w ]+)§7 #(\\d)".toRegex() + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + chatUpgradePattern.matchEntire(event.message)?.groups?.let { matches -> + val crop = CropType.getByItemName(matches[1]!!.value) ?: return + val level = matches[2]!!.value.toInt() + crop.setUpgradeLevel(level) + } + CropUpgradeUpdateEvent().postAndCatch() + } + + @SubscribeEvent + fun onInventoryOpen(event: InventoryOpenEvent) { + if (event.inventoryName != "Crop Upgrades") return + event.inventoryItems.forEach { (_, item) -> + val crop = item.name?.stripControlCodes()?.let { + CropType.getByName(it) + } ?: return@forEach + val level = item.getLore().firstNotNullOfOrNull { + tierPattern.matchEntire(it)?.groups?.get(1)?.value?.toIntOrNull() + } ?: return@forEach + crop.setUpgradeLevel(level) + } + CropUpgradeUpdateEvent().postAndCatch() + } + + companion object { + private val cropUpgrades: MutableMap<CropType, Int> get() = + SkyHanniMod.feature.hidden.gardenCropUpgrades + + fun CropType.getUpgradeLevel() = cropUpgrades[this] + + fun CropType.setUpgradeLevel(level: Int) { + cropUpgrades[this] = level + } + + } +} |