Created
May 20, 2023 10:46
-
-
Save nbness2/3c13a36fae4cbe9dfa0ab6d1b1706ea7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <I: Item> ItemContainer<I>.nbxShift(predicate: (I) -> Boolean = Item::isInvalidItem) { | |
var firstSlotToFill = -1 | |
var currentSlot = 0 | |
var item: Item | |
while (currentSlot < items.size) { | |
item = this[currentSlot] | |
if (predicate(item)) { | |
if (firstSlotToFill < 0) firstSlotToFill = currentSlot | |
currentSlot += 1 | |
continue | |
} | |
if (firstSlotToFill >= 0) { | |
this[firstSlotToFill] = item.icopy() | |
items[currentSlot] = InvalidItem | |
currentSlot = firstSlotToFill + 1 | |
firstSlotToFill = -1 | |
continue | |
} | |
currentSlot += 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment