aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils/ItemBlink.kt
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-21 23:51:37 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-21 23:51:37 +0200
commitad5e66f4b03ae80cd4f4cf6268495e6b4db901de (patch)
tree5faca09b5f11dc17309aef3ada27a6194e8ace4e /src/main/java/at/hannibal2/skyhanni/utils/ItemBlink.kt
parent9dcb17f1d853796620817e036c53a67ae4635125 (diff)
downloadskyhanni-ad5e66f4b03ae80cd4f4cf6268495e6b4db901de.tar.gz
skyhanni-ad5e66f4b03ae80cd4f4cf6268495e6b4db901de.tar.bz2
skyhanni-ad5e66f4b03ae80cd4f4cf6268495e6b4db901de.zip
added useful stuff
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils/ItemBlink.kt')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemBlink.kt31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemBlink.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemBlink.kt
new file mode 100644
index 000000000..8afc2a2b7
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemBlink.kt
@@ -0,0 +1,31 @@
+package at.hannibal2.skyhanni.utils
+
+import net.minecraft.item.Item
+import net.minecraft.item.ItemStack
+
+object ItemBlink {
+ private val offsets = mutableMapOf<Item, Long>()
+ private var lastOffset = 0L
+ private var endOfBlink = 0L
+ private var blinkItem: ItemStack? = null
+
+ fun setBlink(item: ItemStack?, durationMillis: Long) {
+ endOfBlink = System.currentTimeMillis() + durationMillis
+ blinkItem = item
+ }
+
+ fun ItemStack.checkBlinkItem(): ItemStack {
+ val stack = blinkItem ?: return this
+ if (System.currentTimeMillis() > endOfBlink) return this
+
+ val offset: Long = if (!offsets.containsKey(item)) {
+ lastOffset += 200
+ val number = lastOffset % 1000
+ offsets[item] = number
+ number
+ } else {
+ offsets[item]!!
+ }
+ return if ((offset + System.currentTimeMillis()) % 1000 > 500) stack else this
+ }
+} \ No newline at end of file