diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
4 files changed, 74 insertions, 8 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt index 2d88024fc..e55fb5e9d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.events.BurrowDetectEvent import at.hannibal2.skyhanni.events.BurrowDugEvent import at.hannibal2.skyhanni.events.BurrowGuessEvent +import at.hannibal2.skyhanni.events.DebugDataCollectEvent import at.hannibal2.skyhanni.events.EntityMoveEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent @@ -44,6 +45,25 @@ object GriffinBurrowHelper { var lastTitleSentTime = SimpleTimeMark.farPast() @SubscribeEvent + fun onDebugDataCollect(event: DebugDataCollectEvent) { + event.title("Griffin Burrow Helper") + + if (!DianaAPI.isDoingDiana()) { + event.addIrrelevant("not doing diana") + return + } + + event.addData { + add("targetLocation: ${targetLocation?.printWithAccuracy(1)}") + add("guessLocation: ${guessLocation?.printWithAccuracy(1)}") + add("particleBurrows: ${particleBurrows.size}") + for ((location, type) in particleBurrows) { + add(location.printWithAccuracy(1) + " " + type) + } + } + } + + @SubscribeEvent fun onTick(event: LorenzTickEvent) { if (!isEnabled()) return if (!event.repeatSeconds(1)) return @@ -241,7 +261,6 @@ object GriffinBurrowHelper { if (!config.burrowNearestWarp) return val warp = BurrowWarpHelper.currentWarp ?: return - val text = "§bWarp to " + warp.displayName val keybindSuffix = if (config.keyBindWarp != Keyboard.KEY_NONE) { val keyname = KeyboardManager.getKeyName(config.keyBindWarp) diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowParticleFinder.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowParticleFinder.kt index a9f9467f8..2a468174f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowParticleFinder.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowParticleFinder.kt @@ -4,11 +4,13 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.BlockClickEvent import at.hannibal2.skyhanni.events.BurrowDetectEvent import at.hannibal2.skyhanni.events.BurrowDugEvent +import at.hannibal2.skyhanni.events.DebugDataCollectEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.PacketEvent import at.hannibal2.skyhanni.features.event.diana.DianaAPI.isDianaSpade import at.hannibal2.skyhanni.utils.BlockUtils.getBlockAt +import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.TimeLimitedSet import at.hannibal2.skyhanni.utils.toLorenzVec @@ -25,6 +27,31 @@ class GriffinBurrowParticleFinder { private val burrows = mutableMapOf<LorenzVec, Burrow>() private var lastDugParticleBurrow: LorenzVec? = null + // This exist to detect the unlucky timing when the user opens a burrow before it gets fully deteced + private var fakeBurrow: LorenzVec? = null + + @SubscribeEvent + fun onDebugDataCollect(event: DebugDataCollectEvent) { + event.title("Griffin Burrow Particle Finder") + + if (!DianaAPI.isDoingDiana()) { + event.addIrrelevant("not doing diana") + return + } + + event.addData { + add("burrows: ${burrows.size}") + for (burrow in burrows.values) { + val location = burrow.location + val found = burrow.found + add(location.printWithAccuracy(1)) + add(" type: " + burrow.getType()) + add(" found: $found") + add(" ") + } + } + } + @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) fun onChatPacket(event: PacketEvent.ReceiveEvent) { if (!isEnabled()) return @@ -51,8 +78,8 @@ class GriffinBurrowParticleFinder { if (burrow.hasEnchant && burrow.hasFootstep && burrow.type != -1) { if (!burrow.found) { BurrowDetectEvent(burrow.location, burrow.getType()).postAndCatch() + burrow.found = true } - burrow.found = true } } } @@ -106,17 +133,24 @@ class GriffinBurrowParticleFinder { ) { val burrow = lastDugParticleBurrow if (burrow != null) { - recentlyDugParticleBurrows.add(burrow) - lastDugParticleBurrow = null - burrows.remove(burrow)?.let { - if (it.found) { - BurrowDugEvent(it.location).postAndCatch() - } + if (!tryDig(burrow)) { + fakeBurrow = burrow } } } } + private fun tryDig(location: LorenzVec, ignoreFound: Boolean = false): Boolean { + val burrow = burrows[location] ?: return false + if (!burrow.found && !ignoreFound) return false + burrows.remove(location) + recentlyDugParticleBurrows.add(location) + lastDugParticleBurrow = null + + BurrowDugEvent(burrow.location).postAndCatch() + return true + } + @SubscribeEvent fun onBlockClick(event: BlockClickEvent) { if (!isEnabled()) return @@ -125,6 +159,15 @@ class GriffinBurrowParticleFinder { val pos = event.position if (event.itemInHand?.isDianaSpade != true || pos.getBlockAt() !== Blocks.grass) return + if (pos == fakeBurrow) { + fakeBurrow = null + // This exist to detect the unlucky timing when the user opens a burrow before it gets fully deteced + LorenzUtils.chat("§dYou found a rare burrow bug. SkyHanni can auto fix it, though.") + tryDig(pos, ignoreFound = true) + return + } + + if (burrows.containsKey(pos)) { lastDugParticleBurrow = pos } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedCache.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedCache.kt index 8aab176ef..9f29b9ff1 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedCache.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedCache.kt @@ -17,5 +17,7 @@ class TimeLimitedCache<K, V>(expireAfterWrite: Duration) { fun values(): MutableCollection<V> = cache.asMap().values + fun keys(): MutableSet<K> = cache.asMap().keys + fun containsKey(key: K): Boolean = cache.getIfPresent(key) != null } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedSet.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedSet.kt index 97caf70ad..e64c55213 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedSet.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedSet.kt @@ -11,4 +11,6 @@ class TimeLimitedSet<T>(expireAfterWrite: Duration) { fun contains(element: T): Boolean = cache.containsKey(element) fun clear() = cache.clear() + + fun toSet(): Set<T> = cache.keys().toSet() } |