aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils/ItemBlink.kt
blob: baa9a8c40462595854d793b65ac552a01d9f683d (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
32
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
    }
}