fast container action: fix item duplication

This commit is contained in:
Bixilon 2022-11-18 10:42:48 +01:00
parent 660e41db88
commit 3e86c1f48a
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 12 additions and 8 deletions

View File

@ -97,13 +97,16 @@ class FastMoveContainerActionTest {
container.invokeAction(FastMoveContainerAction(0)) container.invokeAction(FastMoveContainerAction(0))
assertNull(container.floatingItem) assertNull(container.floatingItem)
assertNull(container[0]) assertEquals(
assertEquals(container[54], ItemStack(CoalTest0.item, 64)) container.slots, slotsOf(
assertEquals(container[55], ItemStack(AppleTestO.item, 61)) 54 to ItemStack(CoalTest0.item, 64),
assertEquals(container[56], ItemStack(CoalTest0.item, 64)) 55 to ItemStack(AppleTestO.item, 61),
assertEquals(container[57], ItemStack(CoalTest0.item, 64)) 56 to ItemStack(CoalTest0.item, 64),
assertEquals(container[58], ItemStack(CoalTest0.item, 64)) 57 to ItemStack(CoalTest0.item, 64),
assertEquals(container[62], ItemStack(CoalTest0.item, 4)) 58 to ItemStack(CoalTest0.item, 64),
62 to ItemStack(CoalTest0.item, 4),
)
)
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 0, 1, 0, 0, slotsOf(0 to null, 58 to ItemStack(AppleTestO.item, count = 64), 56 to ItemStack(AppleTestO.item, count = 64), 54 to ItemStack(AppleTestO.item, count = 64), 57 to ItemStack(AppleTestO.item, count = 64), 62 to ItemStack(AppleTestO.item, count = 4)), null)) // TODO: respect order of changes connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 0, 1, 0, 0, slotsOf(0 to null, 58 to ItemStack(AppleTestO.item, count = 64), 56 to ItemStack(AppleTestO.item, count = 64), 54 to ItemStack(AppleTestO.item, count = 64), 57 to ItemStack(AppleTestO.item, count = 64), 62 to ItemStack(AppleTestO.item, count = 4)), null)) // TODO: respect order of changes
} }

View File

@ -58,6 +58,7 @@ class FastMoveContainerAction(
list += slot list += slot
} }
} }
val maxStack = source.item.item.maxStackSize
val changes: Int2ObjectOpenHashMap<ItemStack> = Int2ObjectOpenHashMap() val changes: Int2ObjectOpenHashMap<ItemStack> = Int2ObjectOpenHashMap()
sections@ for (list in targets) { sections@ for (list in targets) {
for (slot in list.intIterator()) { for (slot in list.intIterator()) {
@ -69,7 +70,7 @@ class FastMoveContainerAction(
container._set(this.slot, null) container._set(this.slot, null)
break@sections break@sections
} }
val countToPut = source.item._count - (source.item.item.maxStackSize - content.item._count) val countToPut = if (source.item._count + content.item._count > maxStack) maxStack - content.item._count else source.item._count
source.item._count -= countToPut source.item._count -= countToPut
content.item._count += countToPut content.item._count += countToPut
changes[slot] = content changes[slot] = content