diff options
Diffstat (limited to 'src/main')
3 files changed, 37 insertions, 27 deletions
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 ccadaec94..70bd0ea9b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt @@ -1,15 +1,24 @@ package at.hannibal2.skyhanni.features.fishing import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import net.minecraft.init.Blocks import net.minecraft.item.ItemStack object FishingAPI { + private val lavaBlocks = listOf(Blocks.lava, Blocks.flowing_lava) + private val waterBlocks = listOf(Blocks.water, Blocks.flowing_water) + fun hasFishingRodInHand() = InventoryUtils.itemInHandId.asString().contains("ROD") fun ItemStack.isBait(): Boolean { val name = name ?: return false return stackSize == 1 && (name.removeColor().startsWith("Obfuscated") || name.endsWith(" Bait")) } + + fun isLavaRod() = InventoryUtils.getItemInHand()?.getLore()?.any { it.contains("Lava Rod") } ?: false + + fun getAllowedBlocks() = if (isLavaRod()) lavaBlocks else waterBlocks } 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 3be74ea8a..03e3e393b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingBaitWarnings.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingBaitWarnings.kt @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.features.fishing.FishingAPI.isBait +import at.hannibal2.skyhanni.utils.BlockUtils.getBlockAt import at.hannibal2.skyhanni.utils.EntityUtils import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils @@ -14,6 +15,7 @@ import at.hannibal2.skyhanni.utils.getLorenzVec import net.minecraft.client.Minecraft import net.minecraft.entity.item.EntityItem import net.minecraft.entity.projectile.EntityFishHook +import net.minecraft.item.ItemStack import net.minecraftforge.event.entity.EntityJoinWorldEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.seconds @@ -39,10 +41,18 @@ class FishingBaitWarnings { @SubscribeEvent fun onTick(event: LorenzTickEvent) { - if (!isEnabled() || bobber == null) return - //Is there a way to get event sent time to be more accurate? + if (!isEnabled()) return + val bobber = bobber ?: return + if (bobber.isDead) { + this.bobber = null + return + } + if (!event.isMod(5)) return if (timeLastCast.passedSince() < 1.seconds) return + val block = bobber.getLorenzVec().getBlockAt() + if (block in FishingAPI.getAllowedBlocks()) return + if (!isUsingBait && config.noBaitWarning) showNoBaitWarning() reset() } @@ -56,29 +66,32 @@ class FishingBaitWarnings { fun onRenderWorld(event: LorenzRenderWorldEvent) { if (!isEnabled() || !config.baitChangeWarning) return val bobber = bobber ?: return - for (entityItem in EntityUtils.getEntitiesNearby<EntityItem>(bobber.getLorenzVec(), 1.5)) { - val itemStack = entityItem.entityItem - if (!itemStack.isBait()) continue - val name = itemStack.name?.removeColor() ?: continue + EntityUtils.getEntitiesNearby<EntityItem>(bobber.getLorenzVec(), 1.5) + .forEach { onBaitDetection(it.entityItem) } + } + + private fun onBaitDetection(itemStack: ItemStack) { + if (!itemStack.isBait()) return + val name = itemStack.name?.removeColor() ?: return - isUsingBait = true - lastBait?.let { - if (name == it) continue - showBaitChangeWarning(it, name) - } - lastBait = name + isUsingBait = true + lastBait?.let { + if (name == it) return + showBaitChangeWarning(it, name) } + lastBait = name } private fun showBaitChangeWarning(before: String, after: String) { SoundUtils.playClickSound() LorenzUtils.sendTitle("§eBait changed!", 2.seconds) - LorenzUtils.chat("§e[SkyHanni] Fishing Bait change detected: $before -> $after") + LorenzUtils.chat("§e[SkyHanni] Fishing Bait changed: $before -> $after") } private fun showNoBaitWarning() { SoundUtils.playErrorSound() LorenzUtils.sendTitle("§cNo bait is used!", 2.seconds) + LorenzUtils.chat("§e[SkyHanni] You do not use any fishing baits!") } private fun isEnabled() = LorenzUtils.inSkyBlock && FishingAPI.hasFishingRodInHand() diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/SharkFishCounter.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/SharkFishCounter.kt index c592e72a4..8861f0663 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/SharkFishCounter.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/SharkFishCounter.kt @@ -5,9 +5,6 @@ import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.SeaCreatureFishEvent -import at.hannibal2.skyhanni.utils.InventoryUtils -import at.hannibal2.skyhanni.utils.ItemUtils.getLore -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.RenderUtils.renderString @@ -56,16 +53,7 @@ class SharkFishCounter { } } - private fun isWaterFishingRod(): Boolean { - val heldItem = InventoryUtils.getItemInHand() ?: return false - val isRod = heldItem.name?.contains("Rod") ?: return false - if (!isRod) return false - - val isLavaRod = heldItem.getLore().any { it.contains("Lava Rod") } - if (isLavaRod) return false - - return true - } + private fun isWaterFishingRod() = FishingAPI.hasFishingRodInHand() && !FishingAPI.isLavaRod() @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { @@ -75,4 +63,4 @@ class SharkFishCounter { SkyHanniMod.feature.fishing.sharkFishCounterPos.renderString(display, posLabel = "Shark Fish Counter") } -}
\ No newline at end of file +} |