aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-26 13:49:05 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-26 13:49:05 +0200
commita575ac91e1efb6f398e5bfd43fd2428c3251f928 (patch)
tree1fc990bd94c9d6ed67053f0b296e94c250cf64a0 /src/main/java
parent7944f8f88ec20b8caea0c41757366734682e059d (diff)
downloadskyhanni-a575ac91e1efb6f398e5bfd43fd2428c3251f928.tar.gz
skyhanni-a575ac91e1efb6f398e5bfd43fd2428c3251f928.tar.bz2
skyhanni-a575ac91e1efb6f398e5bfd43fd2428c3251f928.zip
Auto-detecting tool in hand when joining garden
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt18
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/MinecraftDispatcher.kt17
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