diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt index 9b58cdd29..2713dfe01 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/MatterBottlerBlockEntity.kt @@ -71,7 +71,7 @@ class MatterBottlerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : //private var work_behavior = true val container: MatteryContainer = object : MatteryContainer(this::setChangedLight, 6) { - override fun getMaxStackSize(slot: Int): Int { + override fun getMaxStackSize(slot: Int, itemStack: ItemStack): Int { return 1 } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/container/ContainerHandler.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/container/ContainerHandler.kt index 57121bce9..6a3a4f457 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/container/ContainerHandler.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/container/ContainerHandler.kt @@ -20,16 +20,16 @@ class ContainerHandler @JvmOverloads internal constructor( if (localStack.isEmpty) { if (!simulate) { - container.setItem(slot, stack.copyWithCount(stack.count.coerceAtMost(stack.maxStackSize).coerceAtMost(container.getMaxStackSize(slot)))) + container.setItem(slot, stack.copyWithCount(stack.count.coerceAtMost(container.getMaxStackSize(slot, stack)))) } - if (stack.count <= container.getMaxStackSize(slot).coerceAtMost(stack.maxStackSize)) { + if (stack.count <= container.getMaxStackSize(slot, stack)) { return ItemStack.EMPTY } else { - return stack.copyWithCount(container.getMaxStackSize(slot)) + return stack.copyWithCount(container.getMaxStackSize(slot, stack)) } - } else if (localStack.isStackable && localStack.maxStackSize.coerceAtMost(container.getMaxStackSize(slot)) > localStack.count && ItemStack.isSameItemSameTags(localStack, stack)) { - val newCount = localStack.maxStackSize.coerceAtMost(localStack.count + stack.count).coerceAtMost(container.getMaxStackSize(slot)) + } else if (localStack.isStackable && container.getMaxStackSize(slot, localStack) > localStack.count && ItemStack.isSameItemSameTags(localStack, stack)) { + val newCount = container.getMaxStackSize(slot, localStack).coerceAtMost(localStack.count + stack.count) val diff = newCount - localStack.count if (diff != 0) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/container/MatteryContainer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/container/MatteryContainer.kt index 060b8804b..4b342f692 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/container/MatteryContainer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/container/MatteryContainer.kt @@ -215,17 +215,7 @@ open class MatteryContainer(protected val watcher: Runnable, private val size: I return ContainerHandler(this, filter) } - open fun getMaxStackSize(slot: Int) = maxStackSize - - open fun getMaxStackSizeWithItem(slot: Int): Int { - val item = this[slot] - - if (!item.isEmpty) { - return getMaxStackSize(slot).coerceAtMost(item.maxStackSize) - } - - return getMaxStackSize(slot) - } + open fun getMaxStackSize(slot: Int, itemStack: ItemStack) = maxStackSize.coerceAtMost(itemStack.maxStackSize) /** * @return Leftover [ItemStack] @@ -244,7 +234,7 @@ open class MatteryContainer(protected val watcher: Runnable, private val size: I for (slot in range) { if (ItemStack.isSameItemSameTags(slots[slot], copy)) { val slotStack = slots[slot] - val slotLimit = getMaxStackSize(slot).coerceAtMost(slotStack.maxStackSize) + val slotLimit = getMaxStackSize(slot, slotStack) if (slotStack.count < slotLimit) { val newCount = (slotStack.count + copy.count).coerceAtMost(slotLimit) @@ -274,7 +264,7 @@ open class MatteryContainer(protected val watcher: Runnable, private val size: I // двигаем в пустые слоты for (slot in range) { if (slots[slot].isEmpty) { - val diff = copy.count.coerceAtMost(getMaxStackSize(slot).coerceAtMost(copy.maxStackSize)) + val diff = copy.count.coerceAtMost(getMaxStackSize(slot, copy)) if (!simulate) { val copyToPut = copy.copy() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/item/matter/MatterDustItem.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/item/matter/MatterDustItem.kt index d2ae858c3..8447d888a 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/item/matter/MatterDustItem.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/item/matter/MatterDustItem.kt @@ -71,7 +71,7 @@ class MatterDustItem : Item(Properties().stacksTo(64)), IMatterItem { // можем ли мы стакнуть материю из второго слота в первый? if (!stack2.isEmpty && isFull(stack2)) { - if (ItemStack.isSameItemSameTags(stack, stack2) && container.getMaxStackSizeWithItem(mainSlot) >= stack.count + 1) { + if (ItemStack.isSameItemSameTags(stack, stack2) && container.getMaxStackSize(mainSlot, stack) >= stack.count + 1) { stack.count++ stack2.count--