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 | |
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')
6 files changed, 85 insertions, 1 deletions
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(?<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} + } } |