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 19:45:11 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-26 19:45:11 +0100
commitd4d46c46404cf1424e9262f98e544e0336f2003f (patch)
tree7b72dab6f57b0c23e45594a93eafcf60ce7b4b94 /src/main/java/at/hannibal2/skyhanni/features
parent5a710d5101cd24371f3476c837b1a24f83454803 (diff)
downloadskyhanni-d4d46c46404cf1424e9262f98e544e0336f2003f.tar.gz
skyhanni-d4d46c46404cf1424e9262f98e544e0336f2003f.tar.bz2
skyhanni-d4d46c46404cf1424e9262f98e544e0336f2003f.zip
Added PestFinder
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-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
4 files changed, 194 insertions, 5 deletions
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
+}