fix: incorrect usage of canTakeItem

This commit is contained in:
xtex 2023-07-30 21:05:38 +08:00
parent 40ed66d76e
commit f3be1aae48
Signed by: xtex
GPG Key ID: B918086ED8045B91

View File

@ -68,7 +68,7 @@ class ExchangeItem<E> : Behavior<E>(
private fun exchangeItems(level: ServerLevel, entity: E) {
val container = level.getBlockEntity(target!!) as Container
val inventory = entity.inventory
for (i in 1..6) {
for (i in 1..10) {
val maxCount = 1 + level.random.nextInt(16)
if (level.random.nextBoolean()) {
// take
@ -77,7 +77,7 @@ class ExchangeItem<E> : Behavior<E>(
if (!item.isEmpty) {
val takeCount = min(item.count, maxCount)
val takeItem = item.copyWithCount(takeCount)
if (inventory.canTakeItem(container, slot, takeItem) && entity.canHoldItem(takeItem)) {
if (entity.canHoldItem(takeItem)) {
val remaining = inventory.addItem(/*entity.equipItemIfPossible(takeItem)*/ takeItem)
val actualCount = takeCount - remaining.count
item.shrink(actualCount)
@ -91,7 +91,6 @@ class ExchangeItem<E> : Behavior<E>(
if (!item.isEmpty) {
val takeCount = min(item.count, maxCount)
val takeItem = item.copyWithCount(takeCount)
if (container.canTakeItem(inventory, slot, takeItem)) {
for (target in 0 until container.containerSize) {
val targetItem = container.getItem(target)
if (ItemStack.isSameItemSameTags(targetItem, takeItem)) {
@ -120,7 +119,6 @@ class ExchangeItem<E> : Behavior<E>(
}
}
}
}
container.setChanged()
inventory.setChanged()
}