aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils/ItemBlink.kt
diff options
context:
space:
mode:
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