Don't touch filtered slots with non-stackable items in it
This commit is contained in:
parent
3129db667d
commit
956531e08b
@ -295,31 +295,7 @@ operator fun CraftingContainer.get(column: Int, row: Int, flop: Boolean): ItemSt
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Container.sort(comparator: Comparator<ItemStack> = ItemStackSorter.DEFAULT) {
|
fun Container.sort(comparator: Comparator<ItemStack> = ItemStackSorter.DEFAULT) {
|
||||||
if (isEmpty)
|
sortWithIndices(computeSortedIndices(comparator))
|
||||||
return
|
|
||||||
|
|
||||||
val slots = slotIterator().filter { !it.isForbiddenForAutomation && it.getMaxStackSize() >= it.item.count }.toList()
|
|
||||||
|
|
||||||
if (slots.isEmpty())
|
|
||||||
return
|
|
||||||
|
|
||||||
val items = Object2ObjectOpenCustomHashMap<ItemStack, ItemStack>(ItemStackHashStrategy)
|
|
||||||
|
|
||||||
slots.forEach {
|
|
||||||
val get = items[it.item]
|
|
||||||
|
|
||||||
if (get == null) {
|
|
||||||
items[it.item] = it.item.copy()
|
|
||||||
} else {
|
|
||||||
get.count += it.item.count
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val sortedItems = ObjectArrayList(items.values)
|
|
||||||
sortedItems.sortWith(comparator)
|
|
||||||
|
|
||||||
slots.forEach { it.remove() }
|
|
||||||
sortedItems.forEach { addItem(it, false) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Container.sortWithIndices(sortedSlots: IntCollection) {
|
fun Container.sortWithIndices(sortedSlots: IntCollection) {
|
||||||
@ -337,7 +313,12 @@ fun Container.sortWithIndices(sortedSlots: IntCollection) {
|
|||||||
if (value in 0 until containerSize && seen.add(value)) {
|
if (value in 0 until containerSize && seen.add(value)) {
|
||||||
val slot = containerSlot(value)
|
val slot = containerSlot(value)
|
||||||
|
|
||||||
if (slot.isNotEmpty && !slot.isForbiddenForAutomation && slot.item.count <= slot.getMaxStackSize()) {
|
if (
|
||||||
|
slot.isNotEmpty &&
|
||||||
|
!slot.isForbiddenForAutomation &&
|
||||||
|
slot.item.count <= slot.getMaxStackSize() &&
|
||||||
|
(!slot.hasFilter || slot.getFilter() != slot.item.item || slot.getMaxStackSize() > 1)
|
||||||
|
) {
|
||||||
valid.add(slot)
|
valid.add(slot)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user