Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend: TickEvent repeatSeconds Deprecation #3098

Open
wants to merge 14 commits into
base: beta
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ class LorenzTickEvent(private val tick: Int) : LorenzEvent() {

fun isMod(i: Int, offset: Int = 0) = (tick + offset) % i == 0

@Deprecated("Use SecondPassedEvent instead", ReplaceWith(""))
/**
* Use of this method is discouraged, use [SecondPassedEvent] instead.
* Only use if very needed.
*/
fun repeatSeconds(i: Int, offset: Int = 0) = isMod(i * 20, offset)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package at.hannibal2.skyhanni.features.bingo.card.nextstephelper

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.CollectionAPI
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.data.SkillExperience
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.features.bingo.BingoAPI
import at.hannibal2.skyhanni.features.bingo.card.nextstephelper.steps.ChatMessageStep
import at.hannibal2.skyhanni.features.bingo.card.nextstephelper.steps.CollectionStep
Expand Down Expand Up @@ -140,15 +142,18 @@ object BingoNextStepHelper {
reset()
}

@HandleEvent
fun onSecondPassed(event: SecondPassedEvent) {
if (!isEnabled()) return

update()
updateIslandsVisited()
}

@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
if (!LorenzUtils.isBingoProfile) return
if (!config.enabled) return
if (!isEnabled()) return

if (event.repeatSeconds(1)) {
update()
updateIslandsVisited()
}
if (event.isMod(5)) {
updateCurrentSteps()
}
Expand All @@ -158,8 +163,7 @@ object BingoNextStepHelper {

@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
if (!LorenzUtils.isBingoProfile) return
if (!config.enabled) return
if (!isEnabled()) return

for (currentStep in currentSteps) {
if (currentStep is ObtainCrystalStep) {
Expand Down Expand Up @@ -260,9 +264,7 @@ object BingoNextStepHelper {
for (goal in personalGoals) {
val description = goal.description
val bingoCardStep = readDescription(description.removeColor())
if (bingoCardStep == null) {
// println("Warning: Could not find bingo steps for $description")
} else {
if (bingoCardStep != null) {
finalSteps.add(bingoCardStep)
}
}
Expand Down Expand Up @@ -467,4 +469,6 @@ object BingoNextStepHelper {
}
return this
}

private fun isEnabled() = LorenzUtils.isBingoProfile && config.enabled
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.config.features.crimsonisle.SulphurSkitterBoxConfig
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.events.minecraft.RenderWorldEvent
import at.hannibal2.skyhanni.features.fishing.FishingAPI
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
Expand Down Expand Up @@ -36,14 +37,17 @@ object SulphurSkitterBox {
@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
if (!isEnabled()) return
if (event.repeatSeconds(1)) {
calculateSpongeLocations()
}
if (event.isMod(5)) {
calculateClosestSponge()
}
}

@HandleEvent
fun onSecondPassed(event: SecondPassedEvent) {
if (!isEnabled()) return
calculateSpongeLocations()
}

private fun calculateClosestSponge() {
val location = spongeLocations.minByOrNull { it.distanceToPlayer() }
if (location == closestSponge) return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.features.rift.area.wyldwoods

import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.features.rift.RiftAPI
import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
Expand All @@ -13,7 +14,6 @@ import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.toInternalName
import at.hannibal2.skyhanni.utils.SkullTextureHolder
import at.hannibal2.skyhanni.utils.SpecialColor.toSpecialColor
import net.minecraft.entity.item.EntityArmorStand
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule
object RiftLarva {
Expand All @@ -25,16 +25,14 @@ object RiftLarva {

private val LARVA_HOOK = "LARVA_HOOK".toInternalName()

@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
@HandleEvent
fun onSecondPassed(event: SecondPassedEvent) {
if (!isEnabled()) return

checkHand()
if (!hasHookInHand) return

if (event.repeatSeconds(1)) {
findLarvas()
}
findLarvas()
}

private fun checkHand() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.features.rift.area.wyldwoods

import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.features.rift.RiftAPI
import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
Expand All @@ -13,7 +14,6 @@ import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.toInternalName
import at.hannibal2.skyhanni.utils.SkullTextureHolder
import at.hannibal2.skyhanni.utils.SpecialColor.toSpecialColor
import net.minecraft.entity.item.EntityArmorStand
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule
object RiftOdonata {
Expand All @@ -24,16 +24,14 @@ object RiftOdonata {
private val ODONATA_SKULL_TEXTURE by lazy { SkullTextureHolder.getTexture("MOB_ODONATA") }
private val emptyBottle = "EMPTY_ODONATA_BOTTLE".toInternalName()

@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
@HandleEvent
fun onSecondPassed(event: SecondPassedEvent) {
if (!isEnabled()) return

checkHand()
if (!hasBottleInHand) return

if (event.repeatSeconds(1)) {
findOdonatas()
}
findOdonatas()
}

private fun checkHand() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.ReceiveParticleEvent
import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.events.SkyHanniRenderEntityEvent
import at.hannibal2.skyhanni.events.entity.EntityClickEvent
import at.hannibal2.skyhanni.events.minecraft.RenderWorldEvent
Expand Down Expand Up @@ -102,9 +103,12 @@ object VampireSlayerFeatures {
}
}
}
if (event.repeatSeconds(1)) {
entityList.editCopy { removeIf { it.isDead } }
}
}

@HandleEvent
fun onSecondPassed(event: SecondPassedEvent) {
if (!isEnabled()) return
entityList.editCopy { removeIf { it.isDead } }
}

private fun EntityOtherPlayerMP.process() {
Expand Down
Loading