diff options
author | Linnea Gräf <nea@nea.moe> | 2024-01-18 00:10:25 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-01-18 17:55:53 +0100 |
commit | d7902e06cd7285c72cd4ea2be6f18ead56a8775e (patch) | |
tree | fe07a4644bd889a4402d66105e0e6679f104cfb2 /src/main/kotlin/moe/nea/firmament/features | |
parent | ac151c8ebc4c5546795cdbf5b0c179183e2c71d1 (diff) | |
download | firmament-d7902e06cd7285c72cd4ea2be6f18ead56a8775e.tar.gz firmament-d7902e06cd7285c72cd4ea2be6f18ead56a8775e.tar.bz2 firmament-d7902e06cd7285c72cd4ea2be6f18ead56a8775e.zip |
Add Ancestral Spade solver
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/features')
3 files changed, 127 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt index 3c5ac62..99f84e6 100644 --- a/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt +++ b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt @@ -16,6 +16,7 @@ import moe.nea.firmament.features.debug.DebugView import moe.nea.firmament.features.debug.DeveloperFeatures import moe.nea.firmament.features.debug.MinorTrolling import moe.nea.firmament.features.debug.PowerUserTools +import moe.nea.firmament.features.diana.DianaWaypoints import moe.nea.firmament.features.fixes.CompatibliltyFeatures import moe.nea.firmament.features.fixes.Fixes import moe.nea.firmament.features.inventory.CraftingOverlay @@ -68,6 +69,7 @@ object FeatureManager : DataHolder<FeatureManager.Config>(serializer(), "feature loadFeature(CustomSkyBlockTextures) loadFeature(PriceData) loadFeature(Fixes) + loadFeature(DianaWaypoints) loadFeature(ItemRarityCosmetics) if (Firmament.DEBUG) { loadFeature(DeveloperFeatures) diff --git a/src/main/kotlin/moe/nea/firmament/features/diana/AncestralSpadeSolver.kt b/src/main/kotlin/moe/nea/firmament/features/diana/AncestralSpadeSolver.kt new file mode 100644 index 0000000..c34e68e --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/features/diana/AncestralSpadeSolver.kt @@ -0,0 +1,93 @@ +/* + * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe> + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package moe.nea.firmament.features.diana + +import org.joml.Vector3f +import kotlin.time.Duration.Companion.seconds +import net.minecraft.particle.ParticleTypes +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.WorldRenderLastEvent +import moe.nea.firmament.util.TimeMark +import moe.nea.firmament.util.render.RenderInWorldContext + +object AncestralSpadeSolver { + var lastDing = TimeMark.farPast() + private set + private val pitches = mutableListOf<Float>() + val particlePositions = mutableListOf<Vec3d>() + var nextGuess: Vec3d? = null + private set + + fun onParticleSpawn(event: ParticleSpawnEvent) { + if (!DianaWaypoints.TConfig.ancestralSpadeSolver) return + if (event.particleEffect != ParticleTypes.DRIPPING_LAVA) return + particlePositions.add(event.position) + if (particlePositions.size > 20) { + particlePositions.removeFirst() + } + } + + fun onPlaySound(event: SoundReceiveEvent) { + if (!DianaWaypoints.TConfig.ancestralSpadeSolver) return + if (!SoundEvents.BLOCK_NOTE_BLOCK_HARP.matchesId(event.sound.value().id)) return + + if (lastDing.passedTime() > 1.seconds) { + particlePositions.clear() + pitches.clear() + } + lastDing = TimeMark.now() + + pitches.add(event.pitch) + if (pitches.size > 20) { + pitches.removeFirst() + } + + if (particlePositions.size < 3) { + return + } + + val averagePitchDelta = + if (pitches.isEmpty()) 0.0 + else pitches + .zipWithNext { a, b -> b - a } + .average() + + val soundDistanceEstimate = (Math.E / averagePitchDelta) - particlePositions.first().distanceTo(event.position) + + if (soundDistanceEstimate > 1000) { + return + } + + val lastParticleDirection = particlePositions + .takeLast(3) + .let { (a, _, b) -> b.subtract(a) } + .normalize() + + nextGuess = event.position.add(lastParticleDirection.multiply(soundDistanceEstimate)) + } + + fun onWorldRender(event: WorldRenderLastEvent) { + if (!DianaWaypoints.TConfig.ancestralSpadeSolver) return + RenderInWorldContext.renderInWorld(event) { + nextGuess?.let { + color(1f, 1f, 0f, 0.5f) + tinyBlock(it, 1f) + color(1f, 1f, 0f, 1f) + val cameraForward = Vector3f(0f, 0f, 1f).rotate(event.camera.rotation) + line(event.camera.pos.add(Vec3d(cameraForward)), it, lineWidth = 3f) + } + if (particlePositions.size > 2 && lastDing.passedTime() < 10.seconds) { + color(0f, 1f, 0f, 0.7f) + line(*particlePositions.toTypedArray()) + } + } + } + +} diff --git a/src/main/kotlin/moe/nea/firmament/features/diana/DianaWaypoints.kt b/src/main/kotlin/moe/nea/firmament/features/diana/DianaWaypoints.kt new file mode 100644 index 0000000..eb20852 --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/features/diana/DianaWaypoints.kt @@ -0,0 +1,32 @@ +/* + * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe> + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package moe.nea.firmament.features.diana + +import moe.nea.firmament.events.ParticleSpawnEvent +import moe.nea.firmament.events.SoundReceiveEvent +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 + + object TConfig : ManagedConfig(identifier) { + val ancestralSpadeSolver by toggle("ancestral-spade") { false } + } + + override fun onLoad() { + ParticleSpawnEvent.subscribe(AncestralSpadeSolver::onParticleSpawn) + SoundReceiveEvent.subscribe(AncestralSpadeSolver::onPlaySound) + WorldRenderLastEvent.subscribe(AncestralSpadeSolver::onWorldRender) + } +} + + |