aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils/MinecraftDispatcher.kt
blob: 2ccbf30de33544bab7d95b316babc4c731f30953 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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)
    }
}