diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-26 11:46:45 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-26 11:46:45 +0100 |
commit | 2803f83266d8e75ed9f2a52b0b96027aed9b7b30 (patch) | |
tree | c062044adbb2eb9d0a5271d3bfb139590630453c /src/main/java/at/hannibal2/skyhanni/features | |
parent | 2d45461ddd85f657fd8a188b9ef778d6bf94102e (diff) | |
download | skyhanni-2803f83266d8e75ed9f2a52b0b96027aed9b7b30.tar.gz skyhanni-2803f83266d8e75ed9f2a52b0b96027aed9b7b30.tar.bz2 skyhanni-2803f83266d8e75ed9f2a52b0b96027aed9b7b30.zip |
Show the pests that are attracted when changing the selected material of the Sprayanator.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
3 files changed, 56 insertions, 1 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt index cb596f11d..5609b61b8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt @@ -16,4 +16,6 @@ object PestAPI { ) fun hasVacuumInHand() = InventoryUtils.itemInHandId in vacuumVariants + + fun SprayType.getPests() = PestType.entries.filter { it.spray == this } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/SprayFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/SprayFeatures.kt new file mode 100644 index 000000000..f31e4e3a3 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/SprayFeatures.kt @@ -0,0 +1,49 @@ +package at.hannibal2.skyhanni.features.garden.pests + +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.features.garden.pests.PestAPI.getPests +import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.seconds + +class SprayFeatures { + private val config get() = PestAPI.config.spray + + private var display: String? = null + private var lastChangeTime = SimpleTimeMark.farPast() + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + if (!config.pestWhenSelector) return + + val pattern = "§a§lSPRAYONATOR! §r§7Your selected material is now §r§a(?<spray>.*)§r§7!".toPattern() + + val type = pattern.matchMatcher(event.message) { + val sprayName = group("spray") + SprayType.getByName(sprayName) ?: error("unknown spray: '$sprayName'") + } ?: return + + val pests = type.getPests().joinToString("§7, ", prefix = "§6") { it.displayName } + display = "§a${type.displayName} §7($pests§7)" + + lastChangeTime = SimpleTimeMark.now() + + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { + if (!config.pestWhenSelector) return + + val display = display ?: return + + if (lastChangeTime.passedSince() > 5.seconds) { + this.display = null + return + } + + config.position.renderString(display, posLabel = "Pest Spray Selector") + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/SprayType.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/SprayType.kt index 7e89b1188..eec073cf3 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/SprayType.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/SprayType.kt @@ -1,10 +1,14 @@ package at.hannibal2.skyhanni.features.garden.pests enum class SprayType(val displayName: String) { + COMPOST("Compost"), PLANT_MATTER("Plant Matter"), DUNG("Dung"), - COMPOST("Compost"), HONEY_JAR("Honey Jar"), TASTY_CHEESE("Tasty Cheese"), ; + + companion object { + fun getByName(name: String) = entries.firstOrNull {it.displayName == name} + } } |