diff options
Diffstat (limited to 'src/main/java/at')
3 files changed, 15 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/events/LorenzToolTipEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/LorenzToolTipEvent.kt index 1a987e6f9..4f6269c81 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/LorenzToolTipEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/LorenzToolTipEvent.kt @@ -8,7 +8,7 @@ import net.minecraftforge.fml.common.eventhandler.Cancelable class LorenzToolTipEvent(val slot: Slot, val itemStack: ItemStack, private val toolTip0: MutableList<String>) : LorenzEvent() { - var toolTip + var toolTip: MutableList<String> set(value) { toolTip0.clear() toolTip0.addAll(value) diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/HeldTimeInLore.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/HeldTimeInLore.kt index 6b2f97fbd..327e38aab 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/HeldTimeInLore.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/HeldTimeInLore.kt @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.features.inventory import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.LorenzToolTipEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.CollectionUtils.addOrInsert import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName @@ -28,7 +29,7 @@ object HeldTimeInLore { val seconds = event.itemStack.getSeconds() ?: return val formatted = seconds.seconds.format() - event.toolTip.add(10, "§7Time Held: §b$formatted") + event.toolTip.addOrInsert(10, "§7Time Held: §b$formatted") } private fun ItemStack.getSeconds(): Int? = when (getInternalName()) { @@ -37,3 +38,5 @@ object HeldTimeInLore { else -> null } } + + diff --git a/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt index 33e85e2fe..9590ba5c1 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt @@ -429,4 +429,14 @@ object CollectionUtils { fun <K, V : Any> Map<K?, V>.filterNotNullKeys(): Map<K, V> { return filterKeys { it != null } as Map<K, V> } + + /** + * Inserts the element at the index or appends it to the end if out of bounds of the list. + * + * @param index index to insert at, or append if >= size + * @param element element to insert or add + */ + fun <E> MutableList<E>.addOrInsert(index: Int, element: E) { + if (index < size) add(index, element) else add(element) + } } |