diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt b/src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt index 92a36b623..d38b6824b 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.data import at.hannibal2.skyhanni.events.EntityMoveEvent +import at.hannibal2.skyhanni.events.IslandChangeEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWarpEvent @@ -8,22 +9,36 @@ import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.DelayedRun import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.RegexUtils.matches +import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.getLorenzVec import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.client.Minecraft import net.minecraft.entity.Entity import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.milliseconds +import kotlin.time.Duration.Companion.seconds @SkyHanniModule object EntityMovementData { private val warpingPattern by RepoPattern.pattern( "data.entity.warping", - "§7(?:Warping|Warping you to your SkyBlock island|Warping using transfer token|Finding player|Sending a visit request)\\.\\.\\." + "§7(?:Warping|Warping you to your SkyBlock island|Warping using transfer token|Finding player|Sending a visit request)\\.\\.\\.", ) + private var nextTeleport: OnNextTeleport? = null + + fun onNextTeleport(island: IslandType, action: () -> Unit) { + nextTeleport = OnNextTeleport(island, action) + } + + class OnNextTeleport(val island: IslandType, val action: () -> Unit) { + val startTime: SimpleTimeMark = SimpleTimeMark.now() + } + private val entityLocation = mutableMapOf<Entity, LorenzVec>() fun addToTrack(entity: Entity) { @@ -33,6 +48,40 @@ object EntityMovementData { } @SubscribeEvent + fun onIslandChange(event: IslandChangeEvent) { + val nextData = nextTeleport ?: return + if (nextData.island != event.newIsland) return + val passedSince = nextData.startTime.passedSince() + if (passedSince > 5.seconds) { + nextTeleport = null + return + } + + DelayedRun.runDelayed(100.milliseconds) { + nextData.action() + } + nextTeleport = null + } + + @SubscribeEvent + fun onPlayerMove(event: EntityMoveEvent) { + if (!LorenzUtils.inSkyBlock || event.entity != Minecraft.getMinecraft().thePlayer) return + + val nextData = nextTeleport ?: return + + val passedSince = nextData.startTime.passedSince() + if (passedSince > 5.seconds) { + nextTeleport = null + return + } + if (passedSince > 50.milliseconds && nextData.island.isInIsland()) { + nextData.action() + nextTeleport = null + return + } + } + + @SubscribeEvent fun onTick(event: LorenzTickEvent) { if (!LorenzUtils.inSkyBlock) return addToTrack(Minecraft.getMinecraft().thePlayer) |