From ad5e66f4b03ae80cd4f4cf6268495e6b4db901de Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Fri, 21 Apr 2023 23:51:37 +0200 Subject: added useful stuff --- .../java/at/hannibal2/skyhanni/utils/ItemBlink.kt | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/utils/ItemBlink.kt (limited to 'src/main/java/at/hannibal2/skyhanni/utils/ItemBlink.kt') 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() + 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 -- cgit