Get rid of "slot" and "container" in IContainerSlot since they were bad design choices
This commit is contained in:
parent
a0b04fc1f4
commit
124a1b3db6
@ -266,21 +266,24 @@ fun Container.computeSortedIndices(comparator: Comparator<ItemStack> = ItemStack
|
||||
if (isEmpty)
|
||||
return IntList.of()
|
||||
|
||||
val slots = slotIterator().filter { (it !is IFilteredContainerSlot || !it.isForbiddenForAutomation) && it.maxStackSize(it.item) >= it.item.count }.toList()
|
||||
val slots = slotIterator()
|
||||
.withIndex()
|
||||
.filter { (_, it) -> (it !is IFilteredContainerSlot || !it.isForbiddenForAutomation) && it.maxStackSize(it.item) >= it.item.count }
|
||||
.toList()
|
||||
|
||||
if (slots.isEmpty())
|
||||
return IntList.of()
|
||||
|
||||
val items = Object2ObjectOpenCustomHashMap<ItemStack, Pair<ItemStack, IntList>>(ItemStackHashStrategy)
|
||||
|
||||
slots.forEach {
|
||||
slots.forEach { (index, it) ->
|
||||
val get = items[it.item]
|
||||
|
||||
if (get == null) {
|
||||
items[it.item] = it.item.copy() to IntArrayList().also { s -> s.add(it.slot) }
|
||||
items[it.item] = it.item.copy() to IntArrayList().also { s -> s.add(index) }
|
||||
} else {
|
||||
get.first.count += it.item.count
|
||||
get.second.add(it.slot)
|
||||
get.second.add(index)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,8 +15,8 @@ import ru.dbotthepony.mc.otm.core.registryName
|
||||
import ru.dbotthepony.mc.otm.data.getOrNull
|
||||
|
||||
open class ContainerSlot(
|
||||
final override val container: SlottedContainer,
|
||||
final override val slot: Int
|
||||
protected val container: SlottedContainer,
|
||||
protected val slot: Int
|
||||
) : ISlottedContainerSlot, INBTSerializable<CompoundTag> {
|
||||
private var _item: ItemStack = ItemStack.EMPTY
|
||||
|
||||
@ -110,7 +110,7 @@ open class ContainerSlot(
|
||||
open class Simple(
|
||||
protected val listener: (new: ItemStack, old: ItemStack) -> Unit,
|
||||
protected val maxStackSize: Int = Item.DEFAULT_MAX_STACK_SIZE,
|
||||
) : SlottedContainerBuilder.SlotProvider {
|
||||
) : SlottedContainer.SlotProvider {
|
||||
protected open inner class Instance(container: SlottedContainer, slot: Int) : ContainerSlot(container, slot) {
|
||||
override val maxStackSize: Int
|
||||
get() = this@Simple.maxStackSize
|
||||
|
@ -10,15 +10,9 @@ import ru.dbotthepony.mc.otm.core.isNotEmpty
|
||||
* for Player interaction.
|
||||
*/
|
||||
interface IContainerSlot : Delegate<ItemStack> {
|
||||
val slot: Int
|
||||
val container: Container
|
||||
|
||||
fun setChanged()
|
||||
var item: ItemStack
|
||||
|
||||
operator fun component1() = slot
|
||||
operator fun component2() = item
|
||||
|
||||
/**
|
||||
* Max stack size regardless of item
|
||||
*
|
||||
@ -53,7 +47,7 @@ interface IContainerSlot : Delegate<ItemStack> {
|
||||
val isNotEmpty: Boolean
|
||||
get() = item.isNotEmpty
|
||||
|
||||
class Simple(override val slot: Int, override val container: Container) : IContainerSlot {
|
||||
class Simple(private val slot: Int, private val container: Container) : IContainerSlot {
|
||||
override fun setChanged() {
|
||||
container.setChanged()
|
||||
}
|
||||
|
@ -7,8 +7,6 @@ import net.neoforged.neoforge.items.IItemHandler
|
||||
* Slot of [ISlottedContainer], with additional methods to implement interaction behavior for both for players and mechanisms
|
||||
*/
|
||||
interface ISlottedContainerSlot : IContainerSlot {
|
||||
override val container: ISlottedContainer
|
||||
|
||||
fun canAutomationPlaceItem(itemStack: ItemStack): Boolean {
|
||||
return true
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user