Make getMaxStackSize also accept itemstack
This commit is contained in:
parent
716ccae94a
commit
0878bd9a7e
@ -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
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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()
|
||||
|
@ -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--
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user