blob: 8afc2a2b7c6064945444757f42279c2750fe7626 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
}
}
|