More specialized versions of iterators in IEnhancedContainer
This commit is contained in:
parent
54012cf136
commit
448041fe2e
@ -76,10 +76,22 @@ interface IEnhancedContainer<out S : IContainerSlot> : Container, RecipeInput, I
|
||||
}
|
||||
|
||||
fun nonEmptySlotIterator(): Iterator<S> {
|
||||
return slotIterator().filter { it.isNotEmpty }
|
||||
return nonEmptySlotIndexIterator().map { containerSlot(it) }
|
||||
}
|
||||
|
||||
private fun slotIterator(allowedSlots: IntCollection, predicate: Predicate<ItemStack>): IntIterator {
|
||||
fun emptySlotIterator(): Iterator<S> {
|
||||
return emptySlotIndexIterator().map { containerSlot(it) }
|
||||
}
|
||||
|
||||
fun nonEmptySlotIterator(allowedSlots: IntCollection): Iterator<S> {
|
||||
return nonEmptySlotIndexIterator(allowedSlots).map { containerSlot(it) }
|
||||
}
|
||||
|
||||
fun emptySlotIterator(allowedSlots: IntCollection): Iterator<S> {
|
||||
return emptySlotIndexIterator(allowedSlots).map { containerSlot(it) }
|
||||
}
|
||||
|
||||
private fun slotIndexWalker(allowedSlots: IntCollection, predicate: Predicate<ItemStack>): IntIterator {
|
||||
return object : IntIterator() {
|
||||
private val parent = allowedSlots.intIterator()
|
||||
private var foundNext = false
|
||||
@ -120,6 +132,14 @@ interface IEnhancedContainer<out S : IContainerSlot> : Container, RecipeInput, I
|
||||
}
|
||||
}
|
||||
|
||||
fun emptySlotIndexIterator(allowedSlots: IntCollection): IntIterator {
|
||||
return slotIndexWalker(allowedSlots) { it.isEmpty }
|
||||
}
|
||||
|
||||
fun nonEmptySlotIndexIterator(allowedSlots: IntCollection): IntIterator {
|
||||
return slotIndexWalker(allowedSlots) { it.isNotEmpty }
|
||||
}
|
||||
|
||||
fun emptySlotIndexIterator(): IntIterator {
|
||||
return emptySlotIndexIterator(slotRange)
|
||||
}
|
||||
@ -128,20 +148,30 @@ interface IEnhancedContainer<out S : IContainerSlot> : Container, RecipeInput, I
|
||||
return nonEmptySlotIndexIterator(slotRange)
|
||||
}
|
||||
|
||||
fun emptySlotIndexIterator(allowedSlots: IntCollection): IntIterator {
|
||||
return slotIterator(allowedSlots) { it.isEmpty }
|
||||
fun slotIndexWithItemIterator(item: Item): IntIterator {
|
||||
return slotIndexWithItemIterator(item, slotRange)
|
||||
}
|
||||
|
||||
fun nonEmptySlotIndexIterator(allowedSlots: IntCollection): IntIterator {
|
||||
return slotIterator(allowedSlots) { it.isNotEmpty }
|
||||
fun slotIndexWithItemIterator(item: Item, allowedSlots: IntCollection): IntIterator {
|
||||
val parent = nonEmptySlotIndexIterator(allowedSlots).filter { this[it].isNotEmpty && this[it].item === item }
|
||||
|
||||
return object : IntIterator() {
|
||||
override fun nextInt(): Int {
|
||||
return parent.next()
|
||||
}
|
||||
|
||||
override fun hasNext(): Boolean {
|
||||
return parent.hasNext()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun slotWithItemIterator(item: Item): IntIterator {
|
||||
fun slotWithItemIterator(item: Item): Iterator<S> {
|
||||
return slotWithItemIterator(item, slotRange)
|
||||
}
|
||||
|
||||
fun slotWithItemIterator(item: Item, allowedSlots: IntCollection): IntIterator {
|
||||
return slotIterator(allowedSlots) { it.isNotEmpty && it.item === item }
|
||||
fun slotWithItemIterator(item: Item, allowedSlots: IntCollection): Iterator<S> {
|
||||
return slotIndexWithItemIterator(item, allowedSlots).map { containerSlot(it) }
|
||||
}
|
||||
|
||||
fun nextEmptySlot(startIndex: Int): Int {
|
||||
@ -257,9 +287,7 @@ interface IEnhancedContainer<out S : IContainerSlot> : Container, RecipeInput, I
|
||||
return stack
|
||||
|
||||
// двигаем в одинаковые слоты
|
||||
for (i in slotWithItemIterator(stack.item, slots)) {
|
||||
val slot = containerSlot(i)
|
||||
|
||||
for (slot in slotWithItemIterator(stack.item, slots)) {
|
||||
val condition: Boolean
|
||||
|
||||
if (slot is IFilteredContainerSlot) {
|
||||
@ -295,9 +323,7 @@ interface IEnhancedContainer<out S : IContainerSlot> : Container, RecipeInput, I
|
||||
}
|
||||
|
||||
if (!onlyIntoExisting) {
|
||||
for (i in emptySlotIndexIterator(slots)) {
|
||||
val slot = containerSlot(i)
|
||||
|
||||
for (slot in emptySlotIterator(slots)) {
|
||||
val condition: Boolean
|
||||
|
||||
if (slot is IFilteredContainerSlot) {
|
||||
|
Loading…
Reference in New Issue
Block a user