aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/Storage.java3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestFinderConfig.java30
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestsConfig.java5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/DamageIndicatorDeathEvent.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/DamageIndicatorManager.kt14
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/EntityData.kt3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotAPI.kt36
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestFinder.kt146
9 files changed, 239 insertions, 6 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index 76e6a44e8..b1dd1c921 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.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.PestFinder
import at.hannibal2.skyhanni.features.garden.pests.PestSpawn
import at.hannibal2.skyhanni.features.garden.pests.PestSpawnTimer
import at.hannibal2.skyhanni.features.garden.pests.SprayFeatures
@@ -651,6 +652,7 @@ class SkyHanniMod {
loadModule(FishingBaitWarnings())
loadModule(PestSpawn())
loadModule(PestSpawnTimer)
+ loadModule(PestFinder())
loadModule(SprayFeatures())
init()
diff --git a/src/main/java/at/hannibal2/skyhanni/config/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/Storage.java
index e2d8750b0..91570137e 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/Storage.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/Storage.java
@@ -9,6 +9,7 @@ import at.hannibal2.skyhanni.features.fishing.tracker.FishingProfitTracker;
import at.hannibal2.skyhanni.features.fishing.trophy.TrophyRarity;
import at.hannibal2.skyhanni.features.garden.CropAccessory;
import at.hannibal2.skyhanni.features.garden.CropType;
+import at.hannibal2.skyhanni.features.garden.GardenPlotAPI;
import at.hannibal2.skyhanni.features.garden.farming.ArmorDropTracker;
import at.hannibal2.skyhanni.features.garden.farming.DicerDropTracker;
import at.hannibal2.skyhanni.features.garden.fortuneguide.FarmingItems;
@@ -227,7 +228,7 @@ public class Storage {
}
@Expose
- public Map<Integer, String> plotNames = new HashMap<>();
+ public Map<Integer, GardenPlotAPI.PlotData> plotData = new HashMap<>();
@Expose
public Map<CropType, LorenzVec> cropStartLocations = new HashMap<>();
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestFinderConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestFinderConfig.java
new file mode 100644
index 000000000..444da848d
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/PestFinderConfig.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 PestFinderConfig {
+
+ @Expose
+ @ConfigOption(
+ name = "Display",
+ desc = "Show a display with all know pest locations."
+ )
+ @ConfigEditorBoolean
+ @FeatureToggle
+ public boolean showDisplay = true;
+
+ @Expose
+ @ConfigOption(
+ name = "Only With Vacuum",
+ desc = "Only show the pest display while holding a vacuum in the hand."
+ )
+ @ConfigEditorBoolean
+ public boolean onlyWithVacuum = true;
+
+ @Expose
+ public Position position = new Position(-350, 200, 1.3f);
+}
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 94d954ff4..94e972dfe 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
@@ -12,6 +12,11 @@ public class PestsConfig {
public PestSpawnConfig pestSpawn = new PestSpawnConfig();
@Expose
+ @ConfigOption(name = "Pest Finder", desc = "")
+ @Accordion
+ public PestFinderConfig pestFinder = new PestFinderConfig();
+
+ @Expose
@ConfigOption(name = "Pest Timer", desc = "")
@Accordion
public PestTimerConfig pestTimer = new PestTimerConfig();
diff --git a/src/main/java/at/hannibal2/skyhanni/events/DamageIndicatorDeathEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/DamageIndicatorDeathEvent.kt
new file mode 100644
index 000000000..141f293a3
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/events/DamageIndicatorDeathEvent.kt
@@ -0,0 +1,6 @@
+package at.hannibal2.skyhanni.events
+
+import at.hannibal2.skyhanni.features.combat.damageindicator.EntityData
+import net.minecraft.entity.EntityLivingBase
+
+class DamageIndicatorDeathEvent(val entity: EntityLivingBase, val data: EntityData) : LorenzEvent()
diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/DamageIndicatorManager.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/DamageIndicatorManager.kt
index d268431f8..da682d17a 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/DamageIndicatorManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/DamageIndicatorManager.kt
@@ -4,8 +4,10 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.data.ScoreboardData
import at.hannibal2.skyhanni.events.BossHealthChangeEvent
+import at.hannibal2.skyhanni.events.DamageIndicatorDeathEvent
import at.hannibal2.skyhanni.events.DamageIndicatorDetectedEvent
import at.hannibal2.skyhanni.events.DamageIndicatorFinalBossEvent
+import at.hannibal2.skyhanni.events.EntityHealthUpdateEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
@@ -158,7 +160,6 @@ class DamageIndicatorManager {
// data.ignoreBlocks =
// data.bossType == BossType.END_ENDSTONE_PROTECTOR && Minecraft.getMinecraft().thePlayer.isSneaking
-
if (!data.ignoreBlocks && !data.entity.canBeSeen(70.0)) continue
if (!data.isConfigEnabled()) continue
@@ -854,6 +855,17 @@ class DamageIndicatorManager {
}
@SubscribeEvent
+ fun onEntityHealthUpdate(event: EntityHealthUpdateEvent) {
+ val data = data[event.entity.uniqueID] ?: return
+ if (event.health <= 1) {
+ if (!data.firstDeath) {
+ data.firstDeath = true
+ DamageIndicatorDeathEvent(event.entity, data).postAndCatch()
+ }
+ }
+ }
+
+ @SubscribeEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.move(2, "damageIndicator", "combat.damageIndicator")
event.move(3, "slayer.endermanPhaseDisplay", "slayer.endermen.phaseDisplay")
diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/EntityData.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/EntityData.kt
index 970bdd0dd..50e5b4547 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/EntityData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/EntityData.kt
@@ -21,10 +21,11 @@ class EntityData(
var nameSuffix: String = "",
var nameAbove: String = "",
var dead: Boolean = false,
+ var firstDeath: Boolean = false, // TODO this defines if hp is very low, replace dead with this later
var deathLocation: LorenzVec? = null,
) {
val timeToKill by lazy {
val duration = System.currentTimeMillis() - foundTime
"§e" + TimeUtils.formatDuration(duration, TimeUnit.SECOND, showMilliSeconds = true)
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotAPI.kt
index 6ab6775e9..0d6905edf 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotAPI.kt
@@ -4,7 +4,9 @@ import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LocationUtils
import at.hannibal2.skyhanni.utils.LocationUtils.isInside
+import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import com.google.gson.annotations.Expose
import net.minecraft.util.AxisAlignedBB
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -21,10 +23,37 @@ object GardenPlotAPI {
class Plot(val id: Int, var inventorySlot: Int, val box: AxisAlignedBB)
- val Plot.name get() = GardenAPI.storage?.plotNames?.get(id) ?: "$id"
+ class PlotData(
+ @Expose
+ val id: Int,
+
+ @Expose
+ var name: String,
+
+ @Expose
+ var pests: Int
+ )
+
+ private fun Plot.getData() = GardenAPI.storage?.plotData?.getOrPut(id) { PlotData(id, "$id", 0) }
+
+ var Plot.name: String
+ get() = getData()?.name ?: "$id"
+ set(value) {
+ getData()?.name = value
+ }
+
+ var Plot.pests: Int
+ get() = getData()?.pests ?: 0
+ set(value) {
+ getData()?.pests = value
+ }
fun Plot.isBarn() = id == -1
+ fun Plot.sendTeleportTo() {
+ LorenzUtils.sendCommandToServer("tptoplot $name")
+ }
+
init {
val plotMap = listOf(
listOf(21, 13, 9, 14, 22),
@@ -57,12 +86,13 @@ object GardenPlotAPI {
if (!GardenAPI.inGarden()) return
if (event.inventoryName != "Configure Plots") return
- val names = GardenAPI.storage?.plotNames ?: return
for (plot in plots) {
val itemName = event.inventoryItems[plot.inventorySlot]?.name ?: continue
pestNamePattern.matchMatcher(itemName) {
- names[plot.id] = group("name")
+ plot.name = group("name")
}
}
}
+
+ fun getPlotByName(plotName: String) = plots.firstOrNull { it.name == plotName }
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestFinder.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestFinder.kt
new file mode 100644
index 000000000..df056bfc9
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestFinder.kt
@@ -0,0 +1,146 @@
+package at.hannibal2.skyhanni.features.garden.pests
+
+import at.hannibal2.skyhanni.events.DamageIndicatorDeathEvent
+import at.hannibal2.skyhanni.events.GuiRenderEvent
+import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
+import at.hannibal2.skyhanni.events.IslandChangeEvent
+import at.hannibal2.skyhanni.events.LorenzChatEvent
+import at.hannibal2.skyhanni.events.garden.pests.PestSpawnEvent
+import at.hannibal2.skyhanni.features.garden.GardenAPI
+import at.hannibal2.skyhanni.features.garden.GardenPlotAPI
+import at.hannibal2.skyhanni.features.garden.GardenPlotAPI.name
+import at.hannibal2.skyhanni.features.garden.GardenPlotAPI.pests
+import at.hannibal2.skyhanni.features.garden.GardenPlotAPI.sendTeleportTo
+import at.hannibal2.skyhanni.utils.ItemUtils.getLore
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber
+import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
+import at.hannibal2.skyhanni.utils.StringUtils
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.renderables.Renderable
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+class PestFinder {
+
+ private val config get() = PestAPI.config.pestFinder
+
+ private var display = emptyList<Renderable>()
+
+ @SubscribeEvent
+ fun onPestSpawn(event: PestSpawnEvent) {
+ if (!isEnabled()) return
+ PestSpawnTimer.lastSpawnTime = SimpleTimeMark.now()
+ val plot = GardenPlotAPI.getPlotByName(event.plotName)
+ if (plot == null) {
+ LorenzUtils.userError("Open Desk to load plot names and pest locations!")
+ return
+ }
+ plot.pests += event.amountPests
+ update()
+ }
+
+ @SubscribeEvent
+ fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
+ if (!isEnabled()) return
+ if (event.inventoryName != "Configure Plots") return
+
+ val pestInventoryPattern = "§4§lൠ §cThis plot has §6(?<amount>\\d) Pests?§c!".toPattern()
+
+ for (plot in GardenPlotAPI.plots) {
+ plot.pests = 0
+ val item = event.inventoryItems[plot.inventorySlot] ?: continue
+ for (line in item.getLore()) {
+ pestInventoryPattern.matchMatcher(line) {
+ plot.pests = group("amount").formatNumber().toInt()
+ }
+ }
+ }
+ update()
+
+ }
+
+ private fun update() {
+ display = drawDisplay()
+ }
+
+ private fun drawDisplay() = buildList {
+ val totalAmount = totalAmount()
+ if (totalAmount == 0) {
+ add(Renderable.string("§cNo pests detected."))
+ add(Renderable.string("§7Open §eConfigure Plots Menu"))
+ add(Renderable.string("§7when incorrect to reload."))
+ return@buildList
+ }
+
+ add(Renderable.string("§eTotal pests on garden: §c${totalAmount()}§7/§c8"))
+
+ for (plot in GardenPlotAPI.plots) {
+ val pests = plot.pests
+ if (pests == 0) continue
+
+ val name = plot.name
+ val pestsName = StringUtils.optionalPlural(pests, "pest", "pests")
+ val renderable = Renderable.clickAndHover(
+ "§c$pestsName §7in §b$name",
+ listOf(
+ "§7Pests Found: §e$pests",
+ "§7In plot §b$name",
+ "",
+ "§eClick here to warp!"
+ ),
+ onClick = {
+ plot.sendTeleportTo()
+ }
+ )
+ add(renderable)
+ }
+ }
+
+ @SubscribeEvent
+ fun onIslandChange(event: IslandChangeEvent) {
+ update()
+ }
+
+ @SubscribeEvent
+ fun onChat(event: LorenzChatEvent) {
+ if (!isEnabled()) return
+ if (event.message == "§cThere are not any Pests on your Garden right now! Keep farming!") {
+ GardenPlotAPI.plots.forEach {
+ it.pests = 0
+ }
+ update()
+ }
+ }
+
+ @SubscribeEvent
+ fun onDamageIndicatorDeath(event: DamageIndicatorDeathEvent) {
+ if (!isEnabled()) return
+
+ // Check if an unknown damage indiactor mob dies in garden
+ val type = event.data.bossType
+ if (!PestType.entries.any { it.damageIndicatorBoss == type }) return
+
+ val plot = GardenPlotAPI.getCurrentPlot()?.takeIf { it.pests > 0 } ?: run {
+ LorenzUtils.userError("Could not detect the plot of the killed pest. Please Open the Configure Plots menu again.")
+ return
+ }
+
+ plot.pests--
+ update()
+ }
+
+ private fun totalAmount() = GardenPlotAPI.plots.sumOf { it.pests }
+
+ @SubscribeEvent
+ fun onRenderOverlay(event: GuiRenderEvent) {
+ if (!isEnabled()) return
+ if (config.onlyWithVacuum && !PestAPI.hasVacuumInHand()) return
+
+ if (GardenAPI.inGarden() && config.showDisplay) {
+ config.position.renderRenderables(display, posLabel = "Pest Finder")
+ }
+ }
+
+ fun isEnabled() = GardenAPI.inGarden() && config.showDisplay
+}