From 8b28b68d6956ae406c0b13abece629a197670edf Mon Sep 17 00:00:00 2001 From: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Date: Tue, 2 Apr 2024 06:07:46 +1100 Subject: Backend: Less fixed rate timer (#1264) --- .../features/misc/trevor/TrevorFeatures.kt | 26 ++++++++-------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features/misc') diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt index 7fe10ae5d..5b1f4e2ae 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt @@ -11,10 +11,10 @@ import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzKeyPressEvent import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent +import at.hannibal2.skyhanni.events.SecondPassedEvent import at.hannibal2.skyhanni.features.garden.farming.GardenCropSpeed import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled -import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ColorUtils.withAlpha import at.hannibal2.skyhanni.utils.ConfigUtils @@ -42,7 +42,6 @@ import net.minecraft.entity.EntityLivingBase import net.minecraft.entity.item.EntityArmorStand import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import kotlin.concurrent.fixedRateTimer import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds @@ -101,21 +100,14 @@ object TrevorFeatures { private val config get() = SkyHanniMod.feature.misc.trevorTheTrapper - init { - fixedRateTimer(name = "skyhanni-update-trapper", period = 1000L) { - if (onFarmingIsland() && config.trapperSolver) { - Minecraft.getMinecraft().addScheduledTask { - try { - updateTrapper() - TrevorTracker.update() - TrevorTracker.calculatePeltsPerHour() - if (questActive) TrevorSolver.findMob() - } catch (error: Throwable) { - ErrorManager.logErrorWithData(error, "Encountered an error when updating the trapper solver") - } - } - } - } + @SubscribeEvent + fun onSecondPassed(event: SecondPassedEvent) { + if (!onFarmingIsland()) return + if (!config.trapperSolver) return + updateTrapper() + TrevorTracker.update() + TrevorTracker.calculatePeltsPerHour() + if (questActive) TrevorSolver.findMob() } @SubscribeEvent -- cgit