diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-04-30 11:58:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-30 11:58:40 +0200 |
commit | c220e8271ab3370ea0f4286bada28fd64cab913f (patch) | |
tree | 5d9bbb7f8ee13a750c391fcfda283843cb6ef32e /src/main/java/at/hannibal2/skyhanni | |
parent | be3448faed6f60f28b0f8d27e72d3f2c3e7f55cf (diff) | |
download | skyhanni-c220e8271ab3370ea0f4286bada28fd64cab913f.tar.gz skyhanni-c220e8271ab3370ea0f4286bada28fd64cab913f.tar.bz2 skyhanni-c220e8271ab3370ea0f4286bada28fd64cab913f.zip |
Fix: Workaround for Pest Particle Waypoint (#1263)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
4 files changed, 117 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index f814e0bef..cae61fe89 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -228,6 +228,7 @@ import at.hannibal2.skyhanni.features.garden.inventory.plots.GardenPlotIcon import at.hannibal2.skyhanni.features.garden.inventory.plots.GardenPlotMenuHighlighting import at.hannibal2.skyhanni.features.garden.pests.PestAPI import at.hannibal2.skyhanni.features.garden.pests.PestFinder +import at.hannibal2.skyhanni.features.garden.pests.PestParticleLine import at.hannibal2.skyhanni.features.garden.pests.PestParticleWaypoint import at.hannibal2.skyhanni.features.garden.pests.PestProfitTracker import at.hannibal2.skyhanni.features.garden.pests.PestSpawn @@ -863,6 +864,7 @@ class SkyHanniMod { loadModule(PestFinder()) loadModule(PestParticleWaypoint()) loadModule(StereoHarmonyDisplay()) + loadModule(PestParticleLine()) loadModule(SprayFeatures()) loadModule(DojoRankDisplay()) loadModule(SprayDisplay()) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleLine.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleLine.kt new file mode 100644 index 000000000..a88310e37 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleLine.kt @@ -0,0 +1,112 @@ +package at.hannibal2.skyhanni.features.garden.pests + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.ClickType +import at.hannibal2.skyhanni.events.ItemClickEvent +import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent +import at.hannibal2.skyhanni.events.ReceiveParticleEvent +import at.hannibal2.skyhanni.features.garden.GardenAPI +import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled +import at.hannibal2.skyhanni.utils.DelayedRun +import at.hannibal2.skyhanni.utils.LorenzColor +import at.hannibal2.skyhanni.utils.LorenzUtils.isAnyOf +import at.hannibal2.skyhanni.utils.LorenzVec +import at.hannibal2.skyhanni.utils.RenderUtils.draw3DLine_nea +import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import net.minecraft.util.EnumParticleTypes +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.seconds + +// TODO remove this workaround once PestParticleWaypoint does work again +class PestParticleLine { + private val config get() = SkyHanniMod.feature.garden.pests.pestWaypoint + + class ParticleLocation(val location: LorenzVec, val spawnTime: SimpleTimeMark) + + private var lastPestTrackerUse = SimpleTimeMark.farPast() + private val locations = mutableListOf<MutableList<ParticleLocation>>() + + @SubscribeEvent + fun onItemClick(event: ItemClickEvent) { + if (!isEnabled()) return + if (PestAPI.hasVacuumInHand()) { + if (event.clickType == ClickType.LEFT_CLICK) { + lastPestTrackerUse = SimpleTimeMark.now() + } + } + } + + @SubscribeEvent + fun onReceiveParticle(event: ReceiveParticleEvent) { + if (!isEnabled()) return + // TODO time in config + if (lastPestTrackerUse.passedSince() > 5.seconds) return + + if (event.type.isAnyOf(EnumParticleTypes.ENCHANTMENT_TABLE, EnumParticleTypes.VILLAGER_ANGRY)) { + if (config.hideParticles) event.cancel() + } + + if (event.type != EnumParticleTypes.VILLAGER_ANGRY) return + val location = event.location + + // run in main thread to avoid concurrent errors + DelayedRun.runNextTick { + getCurrentList(location).add(ParticleLocation(location, SimpleTimeMark.now())) + } + } + + private fun getCurrentList(location: LorenzVec): MutableList<ParticleLocation> { + locations.lastOrNull()?.let { + val distance = it.last().location.distance(location) + if (distance < 4) { + return it + } + } + + val newList = mutableListOf<ParticleLocation>() + locations.add(newList) + if (locations.size == 5) { + locations.removeAt(0) + } + return newList + } + + @SubscribeEvent + fun onRenderWorld(event: LorenzRenderWorldEvent) { + if (!isEnabled()) return + // TODO time in config + if (lastPestTrackerUse.passedSince() > 10.seconds) { + locations.clear() + return + } + + for (list in locations) { + draw(event, list) + } + } + + private fun draw(event: LorenzRenderWorldEvent, list: List<ParticleLocation>) { + val color = LorenzColor.YELLOW.toColor() + for ((prev, next) in list.asSequence().zipWithNext()) { + // TODO time in config + if (next.spawnTime.passedSince() > 5.seconds) continue + val location = next.location + event.draw3DLine_nea( + prev.location, + location, + color, + 3, + false + ) + val isVeryLast = list == locations.lastOrNull() && next == list.lastOrNull() + if (isVeryLast) { + val lastLocation = location.add(-0.5, -0.5, -0.5) + event.drawWaypointFilled(lastLocation, color, beacon = true) + event.drawDynamicText(lastLocation, "§ePest Guess", 1.3) + } + } + } + + fun isEnabled() = GardenAPI.inGarden() && config.enabled +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleWaypoint.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleWaypoint.kt index 45fc2f50d..968601e92 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleWaypoint.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleWaypoint.kt @@ -28,6 +28,7 @@ import java.awt.Color import kotlin.math.absoluteValue import kotlin.time.Duration.Companion.seconds +// TODO delete workaround class PestParticleLine when this class works again class PestParticleWaypoint { private val config get() = SkyHanniMod.feature.garden.pests.pestWaypoint diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 815bc13aa..664eb86b9 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -334,6 +334,8 @@ object LorenzUtils { inline fun <reified T : Enum<T>> enumJoinToPattern(noinline transform: (T) -> CharSequence = { it.name }) = enumValues<T>().joinToString("|", transform = transform) + inline fun <reified T : Enum<T>> T.isAnyOf(vararg array: T): Boolean = array.contains(this) + // TODO move to val by lazy fun isInDevEnvironment() = ((Launch.blackboard ?: mapOf())["fml.deobfuscatedEnvironment"] as Boolean?) ?: true |