diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt | 18 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/MinecraftDispatcher.kt | 17 |
2 files changed, 35 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt index fb00e729f..dd149b5dd 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt @@ -9,14 +9,20 @@ import at.hannibal2.skyhanni.features.garden.farming.GardenBestCropTime import at.hannibal2.skyhanni.features.garden.inventory.SkyMartCopperPrice import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.MinecraftDispatcher import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getCultivatingCounter import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getHoeCounter +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import net.minecraft.client.Minecraft import net.minecraft.item.ItemStack import net.minecraft.network.play.client.C09PacketHeldItemChange +import net.minecraftforge.event.world.WorldEvent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent +import kotlin.time.Duration.Companion.seconds object GardenAPI { private val cropsPerSecond: MutableMap<CropType, Int> get() = SkyHanniMod.feature.hidden.gardenCropsPerSecond @@ -63,6 +69,18 @@ object GardenAPI { } } + @SubscribeEvent + fun onWorldChange(event: WorldEvent.Load) { + SkyHanniMod.coroutineScope.launch { + delay(2.seconds) + withContext(MinecraftDispatcher) { + if (inGarden()) { + checkItemInHand() + } + } + } + } + private fun updateGardenTool() { GardenToolChangeEvent(cropInHand, itemInHand).postAndCatch() } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/MinecraftDispatcher.kt b/src/main/java/at/hannibal2/skyhanni/utils/MinecraftDispatcher.kt new file mode 100644 index 000000000..2ccbf30de --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/MinecraftDispatcher.kt @@ -0,0 +1,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) + } +}
\ No newline at end of file |