From 2abcfe0a016147e402a47fe14450cb78649acba6 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Tue, 15 Aug 2023 14:21:56 +0200 Subject: removed distance checks when detecting sea creatures for fishing timer --- .../skyhanni/features/fishing/BarnFishingTimer.kt | 100 --------------------- .../skyhanni/features/fishing/FishingTimer.kt | 99 ++++++++++++++++++++ 2 files changed, 99 insertions(+), 100 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/fishing/BarnFishingTimer.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/fishing/FishingTimer.kt (limited to 'src') diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/BarnFishingTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/BarnFishingTimer.kt deleted file mode 100644 index 557a1a508..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/BarnFishingTimer.kt +++ /dev/null @@ -1,100 +0,0 @@ -package at.hannibal2.skyhanni.features.fishing - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.IslandType -import at.hannibal2.skyhanni.events.GuiRenderEvent -import at.hannibal2.skyhanni.events.LorenzTickEvent -import at.hannibal2.skyhanni.utils.* -import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland -import at.hannibal2.skyhanni.utils.RenderUtils.renderString -import net.minecraft.entity.item.EntityArmorStand -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import org.lwjgl.input.Keyboard - -class BarnFishingTimer { - private val config get() = SkyHanniMod.feature.fishing - private val barnLocation = LorenzVec(108, 89, -252) - - private var rightLocation = false - private var currentCount = 0 - private var startTime = 0L - private var inHollows = false - - @SubscribeEvent - fun onTick(event: LorenzTickEvent) { - if (!LorenzUtils.inSkyBlock) return - if (!config.barnTimer) return - - if (event.repeatSeconds(3)) { - rightLocation = isRightLocation() - } - - if (!rightLocation) return - - if (event.isMod(5)) checkMobs() - if (event.isMod(7)) tryPlaySound() - if (Keyboard.isKeyDown(config.manualResetTimer)) startTime = System.currentTimeMillis() - } - - private fun tryPlaySound() { - if (currentCount == 0) return - - val duration = System.currentTimeMillis() - startTime - val barnTimerAlertTime = config.barnTimerAlertTime * 1_000 - if (duration > barnTimerAlertTime && duration < barnTimerAlertTime + 3_000) { - SoundUtils.playBeepSound() - } - } - - private fun checkMobs() { - // We ignore sea creatures more than 10 blocks away in crystal hollows - val newCount = if (inHollows) countMobs(10) else countMobs(40) - - if (currentCount == 0 && newCount > 0) { - startTime = System.currentTimeMillis() - } - - currentCount = newCount - if (newCount == 0) { - startTime = 0 - } - - if (inHollows && newCount >= 60 && config.wormLimitAlert) { - SoundUtils.playBeepSound() - } - } - - private fun countMobs(radius: Int) = EntityUtils.getEntitiesNextToPlayer(radius.toDouble()) - .count { entity -> SeaCreatureManager.allFishingMobNames.any { entity.name.contains(it) } } - - private fun isRightLocation(): Boolean { - if (config.barnTimerCrystalHollows && IslandType.CRYSTAL_HOLLOWS.isInIsland()) { - inHollows = true - return true - } - inHollows = false - - if (!IslandType.THE_FARMING_ISLANDS.isInIsland()) { - return LocationUtils.playerLocation().distance(barnLocation) < 50 - } - - return false - } - - @SubscribeEvent - fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { - if (!LorenzUtils.inSkyBlock) return - if (!config.barnTimer) return - if (!rightLocation) return - if (currentCount == 0) return - - val duration = System.currentTimeMillis() - startTime - val barnTimerAlertTime = config.barnTimerAlertTime * 1_000 - val color = if (duration > barnTimerAlertTime) "§c" else "§e" - val timeFormat = TimeUtils.formatDuration(duration, biggestUnit = TimeUnit.MINUTE) - val name = if (currentCount == 1) "sea creature" else "sea creatures" - val text = "$color$timeFormat §8(§e$currentCount §b$name§8)" - - config.barnTimerPos.renderString(text, posLabel = "BarnTimer") - } -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingTimer.kt new file mode 100644 index 000000000..65e1442b7 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingTimer.kt @@ -0,0 +1,99 @@ +package at.hannibal2.skyhanni.features.fishing + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.utils.* +import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland +import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import net.minecraft.entity.item.EntityArmorStand +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import org.lwjgl.input.Keyboard + +class BarnFishingTimer { + private val config get() = SkyHanniMod.feature.fishing + private val barnLocation = LorenzVec(108, 89, -252) + + private var rightLocation = false + private var currentCount = 0 + private var startTime = 0L + private var inHollows = false + + @SubscribeEvent + fun onTick(event: LorenzTickEvent) { + if (!LorenzUtils.inSkyBlock) return + if (!config.barnTimer) return + + if (event.repeatSeconds(3)) { + rightLocation = isRightLocation() + } + + if (!rightLocation) return + + if (event.isMod(5)) checkMobs() + if (event.isMod(7)) tryPlaySound() + if (Keyboard.isKeyDown(config.manualResetTimer)) startTime = System.currentTimeMillis() + } + + private fun tryPlaySound() { + if (currentCount == 0) return + + val duration = System.currentTimeMillis() - startTime + val barnTimerAlertTime = config.barnTimerAlertTime * 1_000 + if (duration > barnTimerAlertTime && duration < barnTimerAlertTime + 3_000) { + SoundUtils.playBeepSound() + } + } + + private fun checkMobs() { + val newCount = countMobs() + + if (currentCount == 0 && newCount > 0) { + startTime = System.currentTimeMillis() + } + + currentCount = newCount + if (newCount == 0) { + startTime = 0 + } + + if (inHollows && newCount >= 60 && config.wormLimitAlert) { + SoundUtils.playBeepSound() + } + } + + private fun countMobs() = EntityUtils.getEntities() + .count { entity -> SeaCreatureManager.allFishingMobNames.any { entity.name.contains(it) } } + + private fun isRightLocation(): Boolean { + if (config.barnTimerCrystalHollows && IslandType.CRYSTAL_HOLLOWS.isInIsland()) { + inHollows = true + return true + } + inHollows = false + + if (!IslandType.THE_FARMING_ISLANDS.isInIsland()) { + return LocationUtils.playerLocation().distance(barnLocation) < 50 + } + + return false + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { + if (!LorenzUtils.inSkyBlock) return + if (!config.barnTimer) return + if (!rightLocation) return + if (currentCount == 0) return + + val duration = System.currentTimeMillis() - startTime + val barnTimerAlertTime = config.barnTimerAlertTime * 1_000 + val color = if (duration > barnTimerAlertTime) "§c" else "§e" + val timeFormat = TimeUtils.formatDuration(duration, biggestUnit = TimeUnit.MINUTE) + val name = if (currentCount == 1) "sea creature" else "sea creatures" + val text = "$color$timeFormat §8(§e$currentCount §b$name§8)" + + config.barnTimerPos.renderString(text, posLabel = "BarnTimer") + } +} \ No newline at end of file -- cgit