aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-30 11:07:53 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-30 11:07:53 +0100
commitb97ccd10b1648e1db2884bf11c346cb7b2bead99 (patch)
tree0b247ce7d52954aec7f6ab8f3cb6eb610e64aaf2 /src/main
parent9505f1c311d53e908d4f47ff61bb132e9aa80282 (diff)
downloadskyhanni-b97ccd10b1648e1db2884bf11c346cb7b2bead99.tar.gz
skyhanni-b97ccd10b1648e1db2884bf11c346cb7b2bead99.tar.bz2
skyhanni-b97ccd10b1648e1db2884bf11c346cb7b2bead99.zip
Changed OwnInventoryItemUpdateEvent to be called synced to main thread.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/OwnInventoryItemUpdateEvent.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt19
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/WildStrawberryDyeNotification.kt25
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt2
6 files changed, 26 insertions, 35 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt b/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt
index 605aca858..a7b31159b 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt
@@ -6,6 +6,7 @@ import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.OwnInventoryItemUpdateEvent
import at.hannibal2.skyhanni.events.PacketEvent
import at.hannibal2.skyhanni.events.entity.ItemAddInInventoryEvent
+import at.hannibal2.skyhanni.utils.DelayedRun
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull
import at.hannibal2.skyhanni.utils.LorenzUtils
@@ -36,7 +37,9 @@ class OwnInventoryData {
val windowId = packet.func_149175_c()
if (windowId == 0) {
val item = packet.func_149174_e() ?: return
- OwnInventoryItemUpdateEvent(item).postAndCatch()
+ DelayedRun.runNextTick {
+ OwnInventoryItemUpdateEvent(item).postAndCatch()
+ }
}
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/events/OwnInventoryItemUpdateEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/OwnInventoryItemUpdateEvent.kt
index a7a5ba491..32e19e751 100644
--- a/src/main/java/at/hannibal2/skyhanni/events/OwnInventoryItemUpdateEvent.kt
+++ b/src/main/java/at/hannibal2/skyhanni/events/OwnInventoryItemUpdateEvent.kt
@@ -2,7 +2,4 @@ package at.hannibal2.skyhanni.events
import net.minecraft.item.ItemStack
-/**
- * Note: This event is async and may not be executed on the main minecraft thread.
- */
-data class OwnInventoryItemUpdateEvent(val itemStack: ItemStack) : LorenzEvent() \ No newline at end of file
+data class OwnInventoryItemUpdateEvent(val itemStack: ItemStack) : LorenzEvent()
diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt
index eb32c929c..51f9a7e8b 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt
@@ -12,7 +12,6 @@ import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.OwnInventoryItemUpdateEvent
import at.hannibal2.skyhanni.events.SackChangeEvent
import at.hannibal2.skyhanni.utils.ConfigUtils
-import at.hannibal2.skyhanni.utils.DelayedRun
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList
@@ -130,18 +129,16 @@ object EnderNodeTracker {
if (!isInTheEnd()) return
if (!ProfileStorageData.loaded) return
- DelayedRun.runNow {
- val newMiteGelInInventory = Minecraft.getMinecraft().thePlayer.inventory.mainInventory
- .filter { it?.getInternalNameOrNull() == EnderNode.MITE_GEL.internalName }
- .sumOf { it.stackSize }
- val change = newMiteGelInInventory - miteGelInInventory
- if (change > 0) {
- tracker.modify { storage ->
- storage.lootCount.addOrPut(EnderNode.MITE_GEL, change)
- }
+ val newMiteGelInInventory = Minecraft.getMinecraft().thePlayer.inventory.mainInventory
+ .filter { it?.getInternalNameOrNull() == EnderNode.MITE_GEL.internalName }
+ .sumOf { it.stackSize }
+ val change = newMiteGelInInventory - miteGelInInventory
+ if (change > 0) {
+ tracker.modify { storage ->
+ storage.lootCount.addOrPut(EnderNode.MITE_GEL, change)
}
- miteGelInInventory = newMiteGelInInventory
}
+ miteGelInInventory = newMiteGelInInventory
}
@SubscribeEvent
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WildStrawberryDyeNotification.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WildStrawberryDyeNotification.kt
index c35cf5495..aaa1a734c 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WildStrawberryDyeNotification.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WildStrawberryDyeNotification.kt
@@ -3,7 +3,6 @@ package at.hannibal2.skyhanni.features.garden.farming
import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.events.OwnInventoryItemUpdateEvent
import at.hannibal2.skyhanni.features.garden.GardenAPI
-import at.hannibal2.skyhanni.utils.DelayedRun
import at.hannibal2.skyhanni.utils.ItemBlink
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.name
@@ -30,19 +29,17 @@ class WildStrawberryDyeNotification {
val itemStack = event.itemStack
- DelayedRun.runNow {
- // Prevent false positives when buying the item in ah or moving it from a storage
- val diff = System.currentTimeMillis() - lastCloseTime
- if (diff < 1_000) return@runNow
-
- val internalName = itemStack.getInternalName()
- if (internalName == item) {
- val name = itemStack.name!!
- LorenzUtils.sendTitle(name, 5.seconds)
- LorenzUtils.chat("You found a $name§e!")
- SoundUtils.playBeepSound()
- ItemBlink.setBlink(itemStack, 5_000)
- }
+ // Prevent false positives when buying the item in ah or moving it from a storage
+ val diff = System.currentTimeMillis() - lastCloseTime
+ if (diff < 1_000) return
+
+ val internalName = itemStack.getInternalName()
+ if (internalName == item) {
+ val name = itemStack.name!!
+ LorenzUtils.sendTitle(name, 5.seconds)
+ LorenzUtils.chat("You found a $name§e!")
+ SoundUtils.playBeepSound()
+ ItemBlink.setBlink(itemStack, 5_000)
}
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
index f8b5214b5..ed0627d82 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
@@ -22,7 +22,6 @@ import at.hannibal2.skyhanni.features.garden.farming.GardenCropSpeed.getSpeed
import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.ConfigUtils
-import at.hannibal2.skyhanni.utils.DelayedRun
import at.hannibal2.skyhanni.utils.EntityUtils
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemBlink
@@ -234,9 +233,7 @@ class GardenVisitorFeatures {
@SubscribeEvent
fun onOwnInventoryItemUpdate(event: OwnInventoryItemUpdateEvent) {
if (GardenAPI.onBarnPlot) {
- DelayedRun.runNow {
- update()
- }
+ update()
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt b/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt
index cbc413c22..2af59435d 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt
@@ -9,7 +9,7 @@ object DelayedRun {
map[run] = SimpleTimeMark.now() + duration
}
- fun runNow(run: () -> Unit) {
+ fun runNextTick(run: () -> Unit) {
map[run] = SimpleTimeMark.now()
}