diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-08-02 11:07:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-02 11:07:37 +0200 |
commit | ccdca342626e439f410f1de4bd5dc1a1790605f3 (patch) | |
tree | cf96bddf622411469d9b1e506cd402b67f4b382e /src/main/java/at/hannibal2 | |
parent | 171049f66ed122656c44e9c07eecc099fe8c6b99 (diff) | |
download | skyhanni-ccdca342626e439f410f1de4bd5dc1a1790605f3.tar.gz skyhanni-ccdca342626e439f410f1de4bd5dc1a1790605f3.tar.bz2 skyhanni-ccdca342626e439f410f1de4bd5dc1a1790605f3.zip |
Fix: Odin Truffle (#2300)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2')
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) + } } |