aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/features/diana
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-01-18 20:00:47 +0100
committerLinnea Gräf <nea@nea.moe>2024-01-18 20:00:47 +0100
commit608fec9cd0bbe3cf389faaeb7e258b592e3adf14 (patch)
treeef7996342498f64529ac6eb5851b2a61a1973d1c /src/main/kotlin/moe/nea/firmament/features/diana
parentd7902e06cd7285c72cd4ea2be6f18ead56a8775e (diff)
downloadfirmament-608fec9cd0bbe3cf389faaeb7e258b592e3adf14.tar.gz
firmament-608fec9cd0bbe3cf389faaeb7e258b592e3adf14.tar.bz2
firmament-608fec9cd0bbe3cf389faaeb7e258b592e3adf14.zip
Add Nearby Burrow Highlighter
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/features/diana')
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/diana/AncestralSpadeSolver.kt10
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/diana/DianaWaypoints.kt23
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/diana/NearbyBurrowsSolver.kt135
3 files changed, 164 insertions, 4 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/features/diana/AncestralSpadeSolver.kt b/src/main/kotlin/moe/nea/firmament/features/diana/AncestralSpadeSolver.kt
index c34e68e..459fa3c 100644
--- a/src/main/kotlin/moe/nea/firmament/features/diana/AncestralSpadeSolver.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/diana/AncestralSpadeSolver.kt
@@ -13,6 +13,7 @@ import net.minecraft.sound.SoundEvents
import net.minecraft.util.math.Vec3d
import moe.nea.firmament.events.ParticleSpawnEvent
import moe.nea.firmament.events.SoundReceiveEvent
+import moe.nea.firmament.events.WorldReadyEvent
import moe.nea.firmament.events.WorldRenderLastEvent
import moe.nea.firmament.util.TimeMark
import moe.nea.firmament.util.render.RenderInWorldContext
@@ -28,6 +29,8 @@ object AncestralSpadeSolver {
fun onParticleSpawn(event: ParticleSpawnEvent) {
if (!DianaWaypoints.TConfig.ancestralSpadeSolver) return
if (event.particleEffect != ParticleTypes.DRIPPING_LAVA) return
+ if (event.offset.x != 0.0F || event.offset.y != 0F || event.offset.z != 0F)
+ return
particlePositions.add(event.position)
if (particlePositions.size > 20) {
particlePositions.removeFirst()
@@ -90,4 +93,11 @@ object AncestralSpadeSolver {
}
}
+ fun onSwapWorld(event: WorldReadyEvent) {
+ nextGuess = null
+ particlePositions.clear()
+ pitches.clear()
+ lastDing = TimeMark.farPast()
+ }
+
}
diff --git a/src/main/kotlin/moe/nea/firmament/features/diana/DianaWaypoints.kt b/src/main/kotlin/moe/nea/firmament/features/diana/DianaWaypoints.kt
index eb20852..6422f67 100644
--- a/src/main/kotlin/moe/nea/firmament/features/diana/DianaWaypoints.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/diana/DianaWaypoints.kt
@@ -6,26 +6,41 @@
package moe.nea.firmament.features.diana
+import moe.nea.firmament.events.AttackBlockEvent
import moe.nea.firmament.events.ParticleSpawnEvent
+import moe.nea.firmament.events.ProcessChatEvent
import moe.nea.firmament.events.SoundReceiveEvent
+import moe.nea.firmament.events.UseBlockEvent
+import moe.nea.firmament.events.WorldReadyEvent
import moe.nea.firmament.events.WorldRenderLastEvent
import moe.nea.firmament.features.FirmamentFeature
import moe.nea.firmament.gui.config.ManagedConfig
object DianaWaypoints : FirmamentFeature {
- override val identifier: String
- get() = "diana-waypoints"
- override val config: ManagedConfig?
- get() = TConfig
+ override val identifier get() = "diana-waypoints"
+ override val config get() = TConfig
object TConfig : ManagedConfig(identifier) {
val ancestralSpadeSolver by toggle("ancestral-spade") { false }
}
override fun onLoad() {
+ ParticleSpawnEvent.subscribe(NearbyBurrowsSolver::onParticles)
+ WorldReadyEvent.subscribe(NearbyBurrowsSolver::onSwapWorld)
+ WorldRenderLastEvent.subscribe(NearbyBurrowsSolver::onRender)
+ UseBlockEvent.subscribe {
+ NearbyBurrowsSolver.onBlockClick(it.hitResult.blockPos)
+ }
+ AttackBlockEvent.subscribe {
+ NearbyBurrowsSolver.onBlockClick(it.blockPos)
+ }
+ ProcessChatEvent.subscribe(NearbyBurrowsSolver::onChatEvent)
+
+
ParticleSpawnEvent.subscribe(AncestralSpadeSolver::onParticleSpawn)
SoundReceiveEvent.subscribe(AncestralSpadeSolver::onPlaySound)
WorldRenderLastEvent.subscribe(AncestralSpadeSolver::onWorldRender)
+ WorldReadyEvent.subscribe(AncestralSpadeSolver::onSwapWorld)
}
}
diff --git a/src/main/kotlin/moe/nea/firmament/features/diana/NearbyBurrowsSolver.kt b/src/main/kotlin/moe/nea/firmament/features/diana/NearbyBurrowsSolver.kt
new file mode 100644
index 0000000..9fd7792
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/features/diana/NearbyBurrowsSolver.kt
@@ -0,0 +1,135 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+package moe.nea.firmament.features.diana
+
+import kotlin.time.Duration.Companion.seconds
+import net.minecraft.particle.ParticleTypes
+import net.minecraft.util.math.BlockPos
+import net.minecraft.util.math.MathHelper
+import net.minecraft.util.math.Position
+import moe.nea.firmament.events.ParticleSpawnEvent
+import moe.nea.firmament.events.ProcessChatEvent
+import moe.nea.firmament.events.WorldReadyEvent
+import moe.nea.firmament.events.WorldRenderLastEvent
+import moe.nea.firmament.util.TimeMark
+import moe.nea.firmament.util.mutableMapWithMaxSize
+import moe.nea.firmament.util.render.RenderInWorldContext.Companion.renderInWorld
+
+object NearbyBurrowsSolver {
+
+
+ private val recentlyDugBurrows: MutableMap<BlockPos, TimeMark> = mutableMapWithMaxSize(20)
+ private val recentEnchantParticles: MutableMap<BlockPos, TimeMark> = mutableMapWithMaxSize(500)
+ private var lastBlockClick: BlockPos? = null
+
+ enum class BurrowType {
+ START, MOB, TREASURE
+ }
+
+ val burrows = mutableMapOf<BlockPos, BurrowType>()
+
+ fun onChatEvent(event: ProcessChatEvent) {
+ val lastClickedBurrow = lastBlockClick ?: return
+ if (event.unformattedString.startsWith("You dug out a Griffin Burrow!") ||
+ event.unformattedString.startsWith(" ☠ You were killed by") ||
+ event.unformattedString.startsWith("You finished the Griffin burrow chain!")
+ ) {
+ markAsDug(lastClickedBurrow)
+ burrows.remove(lastClickedBurrow)
+ }
+ }
+
+
+ fun wasRecentlyDug(blockPos: BlockPos): Boolean {
+ val lastDigTime = recentlyDugBurrows[blockPos] ?: TimeMark.farPast()
+ return lastDigTime.passedTime() < 10.seconds
+ }
+
+ fun markAsDug(blockPos: BlockPos) {
+ recentlyDugBurrows[blockPos] = TimeMark.now()
+ }
+
+ fun wasRecentlyEnchanted(blockPos: BlockPos): Boolean {
+ val lastEnchantTime = recentEnchantParticles[blockPos] ?: TimeMark.farPast()
+ return lastEnchantTime.passedTime() < 4.seconds
+ }
+
+ fun markAsEnchanted(blockPos: BlockPos) {
+ recentEnchantParticles[blockPos] = TimeMark.now()
+ }
+
+ fun onParticles(event: ParticleSpawnEvent) {
+
+ val position: BlockPos = event.position.toBlockPos().down()
+
+ if (wasRecentlyDug(position)) return
+
+ val isEven50Spread = (event.offset.x == 0.5f && event.offset.z == 0.5f)
+
+ if (event.particleEffect.type == ParticleTypes.ENCHANT) {
+ if (event.count == 5 && event.speed == 0.05F && event.offset.y == 0.4F && isEven50Spread) {
+ markAsEnchanted(position)
+ }
+ return
+ }
+
+ if (!wasRecentlyEnchanted(position)) return
+
+ if (event.particleEffect.type == ParticleTypes.ENCHANTED_HIT
+ && event.count == 4
+ && event.speed == 0.01F
+ && event.offset.y == 0.1f
+ && isEven50Spread
+ ) {
+ burrows[position] = BurrowType.START
+ }
+ if (event.particleEffect.type == ParticleTypes.CRIT
+ && event.count == 3
+ && event.speed == 0.01F
+ && event.offset.y == 0.1F
+ && isEven50Spread
+ ) {
+ burrows[position] = BurrowType.MOB
+ }
+ if (event.particleEffect.type == ParticleTypes.DRIPPING_LAVA
+ && event.count == 2
+ && event.speed == 0.01F
+ && event.offset.y == 0.1F
+ && event.offset.x == 0.35F && event.offset.z == 0.35f
+ ) {
+ burrows[position] = BurrowType.TREASURE
+ }
+ }
+
+ fun onRender(event: WorldRenderLastEvent) {
+ renderInWorld(event) {
+ for ((location, burrow) in burrows) {
+ when (burrow) {
+ BurrowType.START -> color(.2f, .8f, .2f, 0.4f)
+ BurrowType.MOB -> color(0.3f, 0.4f, 0.9f, 0.4f)
+ BurrowType.TREASURE -> color(1f, 0.7f, 0.2f, 0.4f)
+ }
+ block(location)
+ }
+ }
+ }
+
+ fun onSwapWorld(worldReadyEvent: WorldReadyEvent) {
+ burrows.clear()
+ recentEnchantParticles.clear()
+ recentlyDugBurrows.clear()
+ lastBlockClick = null
+ }
+
+ fun onBlockClick(blockPos: BlockPos) {
+ lastBlockClick = blockPos
+ }
+}
+
+fun Position.toBlockPos(): BlockPos {
+ return BlockPos(MathHelper.floor(x), MathHelper.floor(y), MathHelper.floor(z))
+}