diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-02-26 18:14:02 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-02-26 18:14:02 +0100 |
commit | 5e040affe428afbb6bd51be18304cb6e02f9b8a2 (patch) | |
tree | 997c9f78542655b47721c027a6c3c997c1c368df /src/main/java/at | |
parent | 3bc84f50fcb86abbe956c9ccbdf52cbdb563af47 (diff) | |
download | skyhanni-5e040affe428afbb6bd51be18304cb6e02f9b8a2.tar.gz skyhanni-5e040affe428afbb6bd51be18304cb6e02f9b8a2.tar.bz2 skyhanni-5e040affe428afbb6bd51be18304cb6e02f9b8a2.zip |
Fixed fishing trackers appearing when rod swapping. Fixed fishing bait change spam. Fixed fishing no bait warning appearing at wrong moment/not appearing.
Diffstat (limited to 'src/main/java/at')
7 files changed, 96 insertions, 72 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/events/FishingBobberInWaterEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/FishingBobberInWaterEvent.kt new file mode 100644 index 000000000..9423ea2d9 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/FishingBobberInWaterEvent.kt @@ -0,0 +1,3 @@ +package at.hannibal2.skyhanni.events + +class FishingBobberInWaterEvent : LorenzEvent() diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt index ae58bec30..3335f61ca 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt @@ -2,11 +2,15 @@ package at.hannibal2.skyhanni.features.fishing import at.hannibal2.skyhanni.data.jsonobjects.repo.ItemsJson import at.hannibal2.skyhanni.events.FishingBobberCastEvent +import at.hannibal2.skyhanni.events.FishingBobberInWaterEvent import at.hannibal2.skyhanni.events.ItemInHandChangeEvent +import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.features.fishing.trophy.TrophyFishManager import at.hannibal2.skyhanni.features.fishing.trophy.TrophyFishManager.getFilletValue import at.hannibal2.skyhanni.features.fishing.trophy.TrophyRarity +import at.hannibal2.skyhanni.utils.BlockUtils.getBlockAt import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name @@ -37,6 +41,9 @@ object FishingAPI { private var lavaRods = listOf<NEUInternalName>() private var waterRods = listOf<NEUInternalName>() + var bobber: EntityFishHook? = null + var bobberHasTouchedWater = false + @SubscribeEvent fun onJoinWorld(event: EntityJoinWorldEvent) { if (!LorenzUtils.inSkyBlock || !holdingRod) return @@ -45,9 +52,38 @@ object FishingAPI { if (entity.angler != Minecraft.getMinecraft().thePlayer) return lastCastTime = SimpleTimeMark.now() + bobber = entity + bobberHasTouchedWater = false FishingBobberCastEvent(entity).postAndCatch() } + private fun resetBobber() { + bobber = null + bobberHasTouchedWater = false + } + + @SubscribeEvent + fun onWorldChange(event: LorenzWorldChangeEvent) { + resetBobber() + } + + @SubscribeEvent + fun onTick(event: LorenzTickEvent) { + if (!LorenzUtils.inSkyBlock) return + val bobber = bobber ?: return + if (bobber.isDead) { + resetBobber() + } else { + if (!bobberHasTouchedWater) { + val block = bobber.getLorenzVec().getBlockAt() + if (block in getAllowedBlocks()) { + bobberHasTouchedWater = true + FishingBobberInWaterEvent().postAndCatch() + } + } + } + } + private fun NEUInternalName.isFishingRod() = contains("ROD") fun ItemStack.isBait(): Boolean { @@ -63,7 +99,6 @@ object FishingAPI { holdingWaterRod = event.newItem in waterRods } - @SubscribeEvent fun onRepoReload(event: RepositoryReloadEvent) { val data = event.getConstant<ItemsJson>("Items") @@ -73,7 +108,7 @@ object FishingAPI { fun isLavaRod() = InventoryUtils.getItemInHand()?.getLore()?.any { it.contains("Lava Rod") } ?: false - fun getAllowedBlocks() = if (isLavaRod()) lavaBlocks else waterBlocks + private fun getAllowedBlocks() = if (isLavaRod()) lavaBlocks else waterBlocks fun getFilletPerTrophy(internalName: NEUInternalName): Int { val internal = internalName.asString() diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingBaitWarnings.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingBaitWarnings.kt index 348ec0342..352b36d16 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingBaitWarnings.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingBaitWarnings.kt @@ -2,89 +2,95 @@ package at.hannibal2.skyhanni.features.fishing import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.FishingBobberCastEvent -import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent -import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.events.FishingBobberInWaterEvent +import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.features.fishing.FishingAPI.isBait -import at.hannibal2.skyhanni.utils.BlockUtils.getBlockAt import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.DelayedRun import at.hannibal2.skyhanni.utils.EntityUtils import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.SoundUtils -import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.getLorenzVec import net.minecraft.entity.item.EntityItem import net.minecraft.entity.projectile.EntityFishHook -import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds class FishingBaitWarnings { private val config get() = SkyHanniMod.feature.fishing.fishingBaitWarnings - private var bobber: EntityFishHook? = null - private var lastBait: String? = null - private var isUsingBait: Boolean = false @SubscribeEvent fun onBobberThrow(event: FishingBobberCastEvent) { - bobber = event.bobber - isUsingBait = false } - @SubscribeEvent - fun onTick(event: LorenzTickEvent) { - if (!isEnabled()) return - val bobber = bobber ?: return - if (bobber.isDead) { - this.bobber = null - return - } - if (!event.isMod(5)) return - if (FishingAPI.lastCastTime.passedSince() < 1.seconds) return - - val block = bobber.getLorenzVec().getBlockAt() - if (block !in FishingAPI.getAllowedBlocks()) return + private var lastBait: String? = null + private var wasUsingBait = true - if (!isUsingBait && config.noBaitWarning) showNoBaitWarning() - reset() + @SubscribeEvent + fun onWorldChange(event: LorenzWorldChangeEvent) { + lastBait = null + wasUsingBait = true } - fun reset() { - bobber = null - isUsingBait = false + @SubscribeEvent + fun onBobberInWater(event: FishingBobberInWaterEvent) { + DelayedRun.runDelayed(500.milliseconds) { + checkBobber() + } } - @SubscribeEvent - fun onRenderWorld(event: LorenzRenderWorldEvent) { - if (!isEnabled() || !config.baitChangeWarning) return - val bobber = bobber ?: return - EntityUtils.getEntitiesNearby<EntityItem>(bobber.getLorenzVec(), 1.5) - .forEach { onBaitDetection(it.entityItem) } + private fun checkBobber() { + val bobber = FishingAPI.bobber ?: return + val bait = detectBait(bobber) + if (bait == null) { + if (config.noBaitWarning) { + if (!wasUsingBait) { + showNoBaitWarning() + } + } + } else { + if (config.baitChangeWarning) { + lastBait?.let { + if (it != bait) { + showBaitChangeWarning(it, bait) + } + } + } + } + wasUsingBait = bait != null + lastBait = bait } - private fun onBaitDetection(itemStack: ItemStack) { - if (!itemStack.isBait()) return - val name = itemStack.name?.removeColor() ?: return + private fun detectBait(bobber: EntityFishHook): String? { + for (entity in EntityUtils.getEntitiesNearby<EntityItem>(bobber.getLorenzVec(), 6.0)) { + val itemStack = entity.entityItem ?: continue + if (!itemStack.isBait()) continue + val name = itemStack.name ?: continue + val ticksExisted = entity.ticksExisted + if (ticksExisted in 6..15) { + return name + } - isUsingBait = true - lastBait?.let { - if (name == it) return - showBaitChangeWarning(it, name) + val distance = "distance: ${entity.getDistanceToEntity(bobber).addSeparators()}" + ChatUtils.debug("fishing bait: ticksExisted: $ticksExisted, $distance") } - lastBait = name + return null } private fun showBaitChangeWarning(before: String, after: String) { SoundUtils.playClickSound() LorenzUtils.sendTitle("§eBait changed!", 2.seconds) - ChatUtils.chat("Fishing Bait changed: $before -> $after") + ChatUtils.chat("Fishing Bait changed: $before §e-> $after") } private fun showNoBaitWarning() { SoundUtils.playErrorSound() LorenzUtils.sendTitle("§cNo bait is used!", 2.seconds) - ChatUtils.chat("You do not use any fishing baits!") + ChatUtils.chat("You're not using any fishing baits!") } private fun isEnabled() = LorenzUtils.inSkyBlock && FishingAPI.isFishing() && !LorenzUtils.inKuudraFight diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/IsFishingDetection.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/IsFishingDetection.kt index 1e3d73f5a..7fa6fcfcc 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/IsFishingDetection.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/IsFishingDetection.kt @@ -1,6 +1,6 @@ package at.hannibal2.skyhanni.features.fishing -import at.hannibal2.skyhanni.events.FishingBobberCastEvent +import at.hannibal2.skyhanni.events.FishingBobberInWaterEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.utils.EntityUtils import at.hannibal2.skyhanni.utils.LocationUtils @@ -24,7 +24,7 @@ object IsFishingDetection { private var lastSeaCreatureKillAreaTime = SimpleTimeMark.farPast() @SubscribeEvent - fun onBobberThrow(event: FishingBobberCastEvent) { + fun onBobberInWater(event: FishingBobberInWaterEvent) { lastRodCastLocation = LocationUtils.playerLocation() lastRodCastTime = SimpleTimeMark.now() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingProfitTracker.kt index 6b7e7cea9..dc6246abe 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingProfitTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingProfitTracker.kt @@ -210,7 +210,7 @@ object FishingProfitTracker { if (!isEnabled()) return val recentPickup = config.showWhenPickup && lastCatchTime.passedSince() < 3.seconds - if (recentPickup || FishingAPI.isFishing()) { + if (recentPickup || FishingAPI.isFishing(checkRodInHand = false)) { tracker.renderDisplay(config.position) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/SeaCreatureTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/SeaCreatureTracker.kt index e39e8fb11..5eab75fbd 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/SeaCreatureTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/SeaCreatureTracker.kt @@ -162,7 +162,7 @@ object SeaCreatureTracker { @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent) { if (!isEnabled()) return - if (!FishingAPI.isFishing()) return + if (!FishingAPI.isFishing(checkRodInHand = false)) return tracker.renderDisplay(config.position) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/GeyserFishing.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/GeyserFishing.kt index e4ffe0053..fb0b591cd 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/GeyserFishing.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/GeyserFishing.kt @@ -2,9 +2,7 @@ package at.hannibal2.skyhanni.features.fishing.trophy import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.IslandType -import at.hannibal2.skyhanni.events.FishingBobberCastEvent import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent -import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.ReceiveParticleEvent import at.hannibal2.skyhanni.features.fishing.FishingAPI @@ -15,7 +13,6 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.RenderUtils.drawFilledBoundingBox_nea import at.hannibal2.skyhanni.utils.SpecialColour -import net.minecraft.entity.projectile.EntityFishHook import net.minecraft.util.AxisAlignedBB import net.minecraft.util.EnumParticleTypes import net.minecraftforge.fml.common.eventhandler.EventPriority @@ -25,7 +22,6 @@ import java.awt.Color class GeyserFishing { private val config get() = SkyHanniMod.feature.fishing.trophyFishing.geyserOptions - private var bobber: EntityFishHook? = null private var geyser: LorenzVec? = null private var geyserBox: AxisAlignedBB? = null @@ -42,34 +38,18 @@ class GeyserFishing { potentialGeyser.x + 2, 118.0 - 0.09, potentialGeyser.z + 2 ) - if (config.hideParticles && bobber != null) { + if (config.hideParticles && FishingAPI.bobber != null) { hideGeyserParticles(event) } } @SubscribeEvent fun onWorldChange(event: LorenzWorldChangeEvent) { - bobber = null geyser = null geyserBox = null } @SubscribeEvent - fun onBobberThrow(event: FishingBobberCastEvent) { - bobber = event.bobber - } - - @SubscribeEvent - fun onTick(event: LorenzTickEvent) { - if (!shouldProcessParticles()) return - val bobber = bobber ?: return - if (bobber.isDead) { - this.bobber = null - return - } - } - - @SubscribeEvent fun onRenderWorld(event: LorenzRenderWorldEvent) { if (!config.drawBox) return if (!IslandType.CRIMSON_ISLE.isInIsland()) return @@ -83,7 +63,7 @@ class GeyserFishing { } private fun hideGeyserParticles(event: ReceiveParticleEvent) { - val bobber = bobber ?: return + val bobber = FishingAPI.bobber ?: return val geyser = geyser ?: return if (bobber.distanceTo(event.location) < 3 && bobber.distanceTo(geyser) < 3) { |