aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils/MinecraftDispatcher.kt
blob: 8771de2151fccbe5f322f5ac6dbe3b1a3a9bfdc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package at.hannibal2.skyhanni.utils

import kotlinx.coroutines.MainCoroutineDispatcher
import net.minecraft.client.Minecraft
import kotlin.coroutines.CoroutineContext

object MinecraftDispatcher : MainCoroutineDispatcher() {
    override val immediate: MainCoroutineDispatcher
        get() = this

    override fun isDispatchNeeded(context: CoroutineContext): Boolean {
        return !Minecraft.getMinecraft().isCallingFromMinecraftThread
    }

    override fun dispatch(context: CoroutineContext, block: Runnable) {
        Minecraft.getMinecraft().addScheduledTask(block)
    }
}