aboutsummaryrefslogtreecommitdiff
path: root/src
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
parentd279599080ba81c17d20c97a45c715caf72db8ef (diff)
downloadskyhanni-25655d0c66e1ef193fe17a173f42ff82d26111f9.tar.gz
skyhanni-25655d0c66e1ef193fe17a173f42ff82d26111f9.tar.bz2
skyhanni-25655d0c66e1ef193fe17a173f42ff82d26111f9.zip
Added pest spawn and pest timer features.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestSpawnConfig.java33
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestTimerConfig.java30
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestsConfig.java18
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/garden/pests/PestSpawnEvent.kt5
-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
10 files changed, 230 insertions, 10 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index cae6e6ce1..bc173c5d4 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -166,6 +166,8 @@ import at.hannibal2.skyhanni.features.garden.inventory.GardenInventoryNumbers
import at.hannibal2.skyhanni.features.garden.inventory.GardenNextPlotPrice
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.visitor.GardenVisitorColorNames
import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorDropStatistics
import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorFeatures
@@ -642,6 +644,8 @@ class SkyHanniMod {
loadModule(DungeonFinderFeatures())
loadModule(PabloHelper())
loadModule(FishingBaitWarnings())
+ loadModule(PestSpawn())
+ loadModule(PestSpawnTimer)
init()
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java
index 7553f2f2a..13269ad57 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java
@@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.config.core.config.Position;
import at.hannibal2.skyhanni.config.features.garden.composter.ComposterConfig;
import at.hannibal2.skyhanni.config.features.garden.cropmilestones.CropMilestonesConfig;
import at.hannibal2.skyhanni.config.features.garden.optimalspeed.OptimalSpeedConfig;
+import at.hannibal2.skyhanni.config.features.garden.pests.PestsConfig;
import at.hannibal2.skyhanni.config.features.garden.visitor.VisitorConfig;
import com.google.gson.annotations.Expose;
import io.github.moulberry.moulconfig.annotations.Accordion;
@@ -84,6 +85,10 @@ public class GardenConfig {
public ComposterConfig composters = new ComposterConfig();
@Expose
+ @Category(name = "Pests", desc = "Pests Settings")
+ public PestsConfig pests = new PestsConfig();
+
+ @Expose
@ConfigOption(name = "Farming Fortune Display", desc = "")
@Accordion
public FarmingFortuneConfig farmingFortunes = new FarmingFortuneConfig();
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestSpawnConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestSpawnConfig.java
new file mode 100644
index 000000000..ac91fbe5b
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestSpawnConfig.java
@@ -0,0 +1,33 @@
+package at.hannibal2.skyhanni.config.features.garden.pests;
+
+import at.hannibal2.skyhanni.config.FeatureToggle;
+import com.google.gson.annotations.Expose;
+import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean;
+import io.github.moulberry.moulconfig.annotations.ConfigEditorDropdown;
+import io.github.moulberry.moulconfig.annotations.ConfigEditorKeybind;
+import io.github.moulberry.moulconfig.annotations.ConfigOption;
+import org.lwjgl.input.Keyboard;
+
+public class PestSpawnConfig {
+
+ @Expose
+ @ConfigOption(
+ name = "Chat Message Format",
+ desc = "Change how the pest spawn chat message should be formatted.")
+ @ConfigEditorDropdown(values = {"Hypixel Style", "Compact", "Disabled"})
+ public int chatMessageFormat = 0;
+
+ @Expose
+ @ConfigOption(
+ name = "Show Title",
+ desc = "Show a Title when a pest spawns."
+ )
+ @ConfigEditorBoolean
+ @FeatureToggle
+ public boolean showTitle = true;
+
+ @Expose
+ @ConfigOption(name = "Teleport Hotkey", desc = "Press this key to warp to the plot where the last pest has spawned.")
+ @ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE)
+ public int teleportHotkey = Keyboard.KEY_NONE;
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestTimerConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestTimerConfig.java
new file mode 100644
index 000000000..a0e01a926
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestTimerConfig.java
@@ -0,0 +1,30 @@
+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 PestTimerConfig {
+
+ @Expose
+ @ConfigOption(
+ name = "Enabled",
+ desc = "Show the time since the last pest spawned on your garden."
+ )
+ @ConfigEditorBoolean
+ @FeatureToggle
+ public boolean enabled = true;
+
+ @Expose
+ @ConfigOption(
+ name = "Only With Vacuum",
+ desc = "Only show the time while holding vacuum in the hand."
+ )
+ @ConfigEditorBoolean
+ public boolean onlyWithVacuum = false;
+
+ @Expose
+ public Position position = new Position(390, 65, false, true);
+}
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
new file mode 100644
index 000000000..7acde7b64
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestsConfig.java
@@ -0,0 +1,18 @@
+package at.hannibal2.skyhanni.config.features.garden.pests;
+
+import com.google.gson.annotations.Expose;
+import io.github.moulberry.moulconfig.annotations.Accordion;
+import io.github.moulberry.moulconfig.annotations.ConfigOption;
+
+public class PestsConfig {
+
+ @Expose
+ @ConfigOption(name = "Pest Spawn", desc = "")
+ @Accordion
+ public PestSpawnConfig pestSpawn = new PestSpawnConfig();
+
+ @Expose
+ @ConfigOption(name = "Pest Timer", desc = "")
+ @Accordion
+ public PestTimerConfig pestTimer = new PestTimerConfig();
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/events/garden/pests/PestSpawnEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/garden/pests/PestSpawnEvent.kt
new file mode 100644
index 000000000..20b80ff4a
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/events/garden/pests/PestSpawnEvent.kt
@@ -0,0 +1,5 @@
+package at.hannibal2.skyhanni.events.garden.pests
+
+import at.hannibal2.skyhanni.events.LorenzEvent
+
+class PestSpawnEvent(val amountPests: Int, val plotName: String) : LorenzEvent()
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()