Misc improvements for CombinedContainer

This commit is contained in:
DBotThePony 2025-02-28 08:38:09 +07:00
parent 6747d5f471
commit 6764af0dcc
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -93,27 +93,7 @@ class CombinedContainer(containers: Stream<Pair<IEnhancedContainer, Iterable<Int
}
override fun isEmpty(): Boolean {
if (fullCoverage.isNotEmpty())
for (container in fullCoverage)
if (!container.isEmpty)
return false
if (notFullCoverage.isNotEmpty())
for (slots in notFullCoverage.values)
for (slot in slots)
if (!slot.isEmpty)
return false
return true
}
override fun getItem(slot: Int): ItemStack {
// do not violate contract of getItem not throwing exceptions when index is invalid
return slots.getOrNull(slot)?.item ?: ItemStack.EMPTY
}
override fun setItem(slot: Int, itemStack: ItemStack) {
slots.getOrNull(slot)?.item = itemStack
return fullCoverage.all { it.isEmpty } && notFullCoverage.values.all { it.all { it.isEmpty } }
}
override fun setChanged() {
@ -123,11 +103,7 @@ class CombinedContainer(containers: Stream<Pair<IEnhancedContainer, Iterable<Int
}
override fun stillValid(player: Player): Boolean {
for (container in containers)
if (!container.stillValid(player))
return false
return true
return containers.all { it.stillValid(player) }
}
override fun iterator(): Iterator<ItemStack> {