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)
|
if (isEmpty)
|
||||||
return IntList.of()
|
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())
|
if (slots.isEmpty())
|
||||||
return IntList.of()
|
return IntList.of()
|
||||||
|
|
||||||
val items = Object2ObjectOpenCustomHashMap<ItemStack, Pair<ItemStack, IntList>>(ItemStackHashStrategy)
|
val items = Object2ObjectOpenCustomHashMap<ItemStack, Pair<ItemStack, IntList>>(ItemStackHashStrategy)
|
||||||
|
|
||||||
slots.forEach {
|
slots.forEach { (index, it) ->
|
||||||
val get = items[it.item]
|
val get = items[it.item]
|
||||||
|
|
||||||
if (get == null) {
|
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 {
|
} else {
|
||||||
get.first.count += it.item.count
|
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
|
import ru.dbotthepony.mc.otm.data.getOrNull
|
||||||
|
|
||||||
open class ContainerSlot(
|
open class ContainerSlot(
|
||||||
final override val container: SlottedContainer,
|
protected val container: SlottedContainer,
|
||||||
final override val slot: Int
|
protected val slot: Int
|
||||||
) : ISlottedContainerSlot, INBTSerializable<CompoundTag> {
|
) : ISlottedContainerSlot, INBTSerializable<CompoundTag> {
|
||||||
private var _item: ItemStack = ItemStack.EMPTY
|
private var _item: ItemStack = ItemStack.EMPTY
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ open class ContainerSlot(
|
|||||||
open class Simple(
|
open class Simple(
|
||||||
protected val listener: (new: ItemStack, old: ItemStack) -> Unit,
|
protected val listener: (new: ItemStack, old: ItemStack) -> Unit,
|
||||||
protected val maxStackSize: Int = Item.DEFAULT_MAX_STACK_SIZE,
|
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) {
|
protected open inner class Instance(container: SlottedContainer, slot: Int) : ContainerSlot(container, slot) {
|
||||||
override val maxStackSize: Int
|
override val maxStackSize: Int
|
||||||
get() = this@Simple.maxStackSize
|
get() = this@Simple.maxStackSize
|
||||||
|
@ -10,15 +10,9 @@ import ru.dbotthepony.mc.otm.core.isNotEmpty
|
|||||||
* for Player interaction.
|
* for Player interaction.
|
||||||
*/
|
*/
|
||||||
interface IContainerSlot : Delegate<ItemStack> {
|
interface IContainerSlot : Delegate<ItemStack> {
|
||||||
val slot: Int
|
|
||||||
val container: Container
|
|
||||||
|
|
||||||
fun setChanged()
|
fun setChanged()
|
||||||
var item: ItemStack
|
var item: ItemStack
|
||||||
|
|
||||||
operator fun component1() = slot
|
|
||||||
operator fun component2() = item
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Max stack size regardless of item
|
* Max stack size regardless of item
|
||||||
*
|
*
|
||||||
@ -53,7 +47,7 @@ interface IContainerSlot : Delegate<ItemStack> {
|
|||||||
val isNotEmpty: Boolean
|
val isNotEmpty: Boolean
|
||||||
get() = item.isNotEmpty
|
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() {
|
override fun setChanged() {
|
||||||
container.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
|
* Slot of [ISlottedContainer], with additional methods to implement interaction behavior for both for players and mechanisms
|
||||||
*/
|
*/
|
||||||
interface ISlottedContainerSlot : IContainerSlot {
|
interface ISlottedContainerSlot : IContainerSlot {
|
||||||
override val container: ISlottedContainer
|
|
||||||
|
|
||||||
fun canAutomationPlaceItem(itemStack: ItemStack): Boolean {
|
fun canAutomationPlaceItem(itemStack: ItemStack): Boolean {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user