summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-26 07:59:13 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-26 07:59:13 +0100
commit25655d0c66e1ef193fe17a173f42ff82d26111f9 (patch)
treeb02c0ef3372ee0771b2e03ae86c776fe65e5d25e /src/main/java/at/hannibal2/skyhanni/features
parentd279599080ba81c17d20c97a45c715caf72db8ef (diff)
downloadskyhanni-25655d0c66e1ef193fe17a173f42ff82d26111f9.tar.gz
skyhanni-25655d0c66e1ef193fe17a173f42ff82d26111f9.tar.bz2
skyhanni-25655d0c66e1ef193fe17a173f42ff82d26111f9.zip
Added pest spawn and pest timer features.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt19
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestSpawn.kt77
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestSpawnTimer.kt37
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt12
4 files changed, 135 insertions, 10 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
new file mode 100644
index 000000000..61bee866a
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt
@@ -0,0 +1,19 @@
+package at.hannibal2.skyhanni.features.garden.pests
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.utils.InventoryUtils
+import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
+
+object PestAPI {
+ val config get() = SkyHanniMod.feature.garden.pests
+
+ val vacuumVariants = listOf(
+ "SKYMART_VACUUM".asInternalName(),
+ "SKYMART_TURBO_VACUUM".asInternalName(),
+ "SKYMART_HYPER_VACUUM".asInternalName(),
+ "INFINI_VACUUM".asInternalName(),
+ "INFINI_VACUUM_HOOVERIUS".asInternalName(),
+ )
+
+ fun hasVacuumInHand() = InventoryUtils.itemInHandId in vacuumVariants
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestSpawn.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestSpawn.kt
new file mode 100644
index 000000000..82c43e320
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestSpawn.kt
@@ -0,0 +1,77 @@
+package at.hannibal2.skyhanni.features.garden.pests
+
+import at.hannibal2.skyhanni.events.LorenzChatEvent
+import at.hannibal2.skyhanni.events.LorenzKeyPressEvent
+import at.hannibal2.skyhanni.events.garden.pests.PestSpawnEvent
+import at.hannibal2.skyhanni.features.garden.GardenAPI
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.NEUItems
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import net.minecraft.client.Minecraft
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration.Companion.seconds
+
+class PestSpawn {
+ private val config get() = PestAPI.config.pestSpawn
+
+ private val patternOnePest = "§6§l.*! §7A §6Pest §7has appeared in §aPlot §7- §b(?<plot>.*)§7!".toPattern()
+ private val patternMultiplePests =
+ "§6§l.*! §6(?<amount>\\d) Pests §7have spawned in §aPlot §7- §b(?<plot>.*)§7!".toPattern()
+
+ private var lastPlotTp: String? = null
+
+ @SubscribeEvent
+ fun onChat(event: LorenzChatEvent) {
+ if (!GardenAPI.inGarden()) return
+
+ var blocked = false
+
+ patternOnePest.matchMatcher(event.message) {
+ pestSpawn(1, group("plot"))
+ blocked = true
+ }
+ patternMultiplePests.matchMatcher(event.message) {
+ pestSpawn(group("amount").toInt(), group("plot"))
+ blocked = true
+ }
+ if (event.message == " §r§e§lCLICK HERE §eto teleport to the plot!") {
+ if (PestSpawnTimer.lastSpawnTime.passedSince() < 1.seconds) {
+ blocked = true
+ }
+ }
+
+ if (blocked && config.chatMessageFormat != 0) {
+ event.blockedReason = "pests_spawn"
+ }
+ }
+
+ private fun pestSpawn(amount: Int, plotName: String) {
+ PestSpawnEvent(amount, plotName).postAndCatch()
+ lastPlotTp = plotName
+
+ if (config.showTitle) {
+ LorenzUtils.sendTitle("§aPest Spawn! §e$amount §ain §b$plotName§a!", 7.seconds)
+ }
+
+ if (config.chatMessageFormat == 1) {
+ LorenzUtils.clickableChat(
+ "§aPest Spawn! §e$amount §ain §b$plotName§a!",
+ "tptoplot $plotName"
+ )
+ }
+ }
+
+ @SubscribeEvent
+ fun onKeyClick(event: LorenzKeyPressEvent) {
+ if (!GardenAPI.inGarden()) return
+ if (Minecraft.getMinecraft().currentScreen != null) return
+ if (NEUItems.neuHasFocus()) return
+
+ if (event.keyCode != config.teleportHotkey) return
+
+ lastPlotTp?.let {
+ lastPlotTp = null
+ LorenzUtils.sendCommandToServer("tptoplot $it")
+ }
+ }
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestSpawnTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestSpawnTimer.kt
new file mode 100644
index 000000000..2f2aff5b1
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestSpawnTimer.kt
@@ -0,0 +1,37 @@
+package at.hannibal2.skyhanni.features.garden.pests
+
+import at.hannibal2.skyhanni.events.GuiRenderEvent
+import at.hannibal2.skyhanni.events.garden.pests.PestSpawnEvent
+import at.hannibal2.skyhanni.features.garden.GardenAPI
+import at.hannibal2.skyhanni.utils.RenderUtils.renderString
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
+import at.hannibal2.skyhanni.utils.TimeUtils.format
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+object PestSpawnTimer {
+ private val config get() = PestAPI.config.pestTimer
+
+ var lastSpawnTime = SimpleTimeMark.farPast()
+
+ @SubscribeEvent
+ fun onPestSpawn(event: PestSpawnEvent) {
+ lastSpawnTime = SimpleTimeMark.now()
+ }
+
+ @SubscribeEvent
+ fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) {
+ if (!isEnabled()) return
+ if (config.onlyWithVacuum && !PestAPI.hasVacuumInHand()) return
+
+ val display = if (lastSpawnTime.isFarPast()) {
+ "§cNo pest spawned yet."
+ } else {
+ val timeSinceLastPest = lastSpawnTime.passedSince().format()
+ "§eLast pest spawned §b$timeSinceLastPest ago"
+ }
+
+ config.position.renderString(display, posLabel = "Pest Spawn Timer")
+ }
+
+ fun isEnabled() = GardenAPI.inGarden() && config.enabled
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt
index e7d6490be..58be63d2e 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt
@@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.features.inventory
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.CollectionAPI
import at.hannibal2.skyhanni.events.RenderItemTipEvent
+import at.hannibal2.skyhanni.features.garden.pests.PestAPI
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils
import at.hannibal2.skyhanni.utils.ItemUtils.cleanName
@@ -10,7 +11,6 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils.between
-import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNeeded
@@ -25,14 +25,6 @@ class ItemDisplayOverlayFeatures {
private val rancherBootsSpeedCapPattern = "§7Current Speed Cap: §a(?<cap>.*)".toPattern()
private val petLevelPattern = "\\[Lvl (?<level>.*)] .*".toPattern()
-
- private val gardenVacuumVariants = listOf(
- "SKYMART_VACUUM".asInternalName(),
- "SKYMART_TURBO_VACUUM".asInternalName(),
- "SKYMART_HYPER_VACUUM".asInternalName(),
- "INFINI_VACUUM".asInternalName(),
- "INFINI_VACUUM_HOOVERIUS".asInternalName(),
- )
private val gardenVacuumPatterm = "§7Vacuum Bag: §6(?<amount>\\d*) Pests?".toPattern()
@SubscribeEvent
@@ -181,7 +173,7 @@ class ItemDisplayOverlayFeatures {
}
if (itemNumberAsStackSize.contains(14)) {
- if (item.getInternalNameOrNull() in gardenVacuumVariants) {
+ if (item.getInternalNameOrNull() in PestAPI.vacuumVariants) {
for (line in item.getLore()) {
gardenVacuumPatterm.matchMatcher(line) {
val pests = group("amount").formatNumber()