More specific methods in enhanced container interface

This commit is contained in:
DBotThePony 2025-03-06 16:37:30 +07:00
parent 5422f0fec8
commit c31549792e
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 17 additions and 9 deletions

View File

@ -88,15 +88,27 @@ interface IEnhancedContainer : IContainer, RecipeInput, Iterable<ItemStack>, Sta
}
}
fun emptySlotIterator(allowedSlots: IntCollection = slotRange): IntIterator {
fun emptySlotIndexIterator(): IntIterator {
return emptySlotIndexIterator(slotRange)
}
fun nonEmptySlotIndexIterator(): IntIterator {
return nonEmptySlotIndexIterator(slotRange)
}
fun emptySlotIndexIterator(allowedSlots: IntCollection): IntIterator {
return slotIterator(allowedSlots) { it.isEmpty }
}
fun nonEmptySlotIterator(allowedSlots: IntCollection = slotRange): IntIterator {
fun nonEmptySlotIndexIterator(allowedSlots: IntCollection): IntIterator {
return slotIterator(allowedSlots) { it.isNotEmpty }
}
fun slotWithItemIterator(item: Item, allowedSlots: IntCollection = slotRange): IntIterator {
fun slotWithItemIterator(item: Item): IntIterator {
return slotWithItemIterator(item, slotRange)
}
fun slotWithItemIterator(item: Item, allowedSlots: IntCollection): IntIterator {
return slotIterator(allowedSlots) { it.isNotEmpty && it.item === item }
}
@ -234,7 +246,7 @@ interface IEnhancedContainer : IContainer, RecipeInput, Iterable<ItemStack>, Sta
if (!onlyIntoExisting) {
// двигаем в пустые слоты
for (slot in emptySlotIterator(slots)) {
for (slot in emptySlotIndexIterator(slots)) {
val diff = copy.count.coerceAtMost(getMaxStackSize(slot, stack))
if (!simulate) {

View File

@ -2,12 +2,8 @@ package ru.dbotthepony.mc.otm.container
import it.unimi.dsi.fastutil.ints.IntCollection
import it.unimi.dsi.fastutil.ints.IntSet
import net.minecraft.world.Container
import net.minecraft.world.item.ItemStack
import net.neoforged.neoforge.items.IItemHandler
import ru.dbotthepony.kommons.collect.any
import ru.dbotthepony.mc.otm.core.collect.filter
import ru.dbotthepony.mc.otm.core.collect.map
/**
* Skeletal implementation for containers which revolve around [IContainerSlot]
@ -80,7 +76,7 @@ interface ISlottedContainer : IEnhancedContainer {
}
if (!onlyIntoExisting) {
for (i in emptySlotIterator(slots)) {
for (i in emptySlotIndexIterator(slots)) {
val slot = containerSlot(i)
val condition: Boolean