From 2803f83266d8e75ed9f2a52b0b96027aed9b7b30 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sun, 26 Nov 2023 11:46:45 +0100 Subject: Show the pests that are attracted when changing the selected material of the Sprayanator. --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 2 + .../config/features/garden/pests/PestsConfig.java | 5 +++ .../config/features/garden/pests/SprayConfig.java | 22 ++++++++++ .../skyhanni/features/garden/pests/PestAPI.kt | 2 + .../features/garden/pests/SprayFeatures.kt | 49 ++++++++++++++++++++++ .../skyhanni/features/garden/pests/SprayType.kt | 6 ++- 6 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/SprayConfig.java create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/pests/SprayFeatures.kt (limited to 'src/main/java/at/hannibal2/skyhanni') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 18105ec96..e38940ec6 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -171,6 +171,7 @@ import at.hannibal2.skyhanni.features.garden.inventory.GardenPlotIcon import at.hannibal2.skyhanni.features.garden.inventory.SkyMartCopperPrice import at.hannibal2.skyhanni.features.garden.pests.PestSpawn import at.hannibal2.skyhanni.features.garden.pests.PestSpawnTimer +import at.hannibal2.skyhanni.features.garden.pests.SprayFeatures import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorColorNames import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorDropStatistics import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorFeatures @@ -646,6 +647,7 @@ class SkyHanniMod { loadModule(FishingBaitWarnings()) loadModule(PestSpawn()) loadModule(PestSpawnTimer) + loadModule(SprayFeatures()) init() diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestsConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestsConfig.java index 7acde7b64..94d954ff4 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestsConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestsConfig.java @@ -15,4 +15,9 @@ public class PestsConfig { @ConfigOption(name = "Pest Timer", desc = "") @Accordion public PestTimerConfig pestTimer = new PestTimerConfig(); + + @Expose + @ConfigOption(name = "Spray", desc = "") + @Accordion + public SprayConfig spray = new SprayConfig(); } diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/SprayConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/SprayConfig.java new file mode 100644 index 000000000..a1026bd6c --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/SprayConfig.java @@ -0,0 +1,22 @@ +package at.hannibal2.skyhanni.config.features.garden.pests; + +import at.hannibal2.skyhanni.config.FeatureToggle; +import at.hannibal2.skyhanni.config.core.config.Position; +import com.google.gson.annotations.Expose; +import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; +import io.github.moulberry.moulconfig.annotations.ConfigOption; + +public class SprayConfig { + + @Expose + @ConfigOption( + name = "Pest Spray Selector", + desc = "Show the pests that are attracted when changing the selected material of the §aSprayanator§7." + ) + @ConfigEditorBoolean + @FeatureToggle + public boolean pestWhenSelector = true; + + @Expose + public Position position = new Position(315, -200, 2.3f); +} 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(?.*)§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} + } } -- cgit