TLDR
It seems LuaItemStack::transfer_stack() will always return true if LuaItemStack::can_set_stack() would succeed – even if no items have been transferred.The problem:
LuaItemStack::can_set_stack() will succeed if the given stack can be used at all in the given inventory. For example, it would succeed if you used it with a "firearm-magazine" in a slot of a car's ammo inventory, but it wouldn't if you'd used it with "coal". As expected, it also would succeed if there already was a "piercing-rounds-magazine" in the slot because LuaItemStack::set_stack() would just replace the existing item with the new one.LuaItemStack::transfer_stack() will return true if you try to transfer a "firearm-magazine" into a car's ammo inventory if the stack was empty or already contained "firearm-magazine" items – as expected. However, it will also return true if the stack was partially filled with "piercing-round-magazine" items, which is unexpected.
Upon closer inspection, it seems that LuaItemStack::transfer_stack() returns true because a transfer actually succeeded: stack.count will be incremented even if slot.name and stack.name differ!
How to reproduce:
Start a new game without mods and enter the following on the console:Code: Select all
/c
p = game.player; pos = p.position
car = p.surface.create_entity({name = "car", force = p.force, position = {pos.x + 5, pos.y}})
ammo = car.get_inventory(defines.inventory.car_ammo)
slot = ammo[1]
stack = {name = "piercing-rounds-magazine", quality = "normal", count = 10}
game.print(string.format("Transferring %s: %s", stack.name, slot.transfer_stack(stack)))
stack.name = "firearm-magazine"
game.print(string.format("Transferring %s: %s", stack.name, slot.transfer_stack(stack)))
stack.name = "coal"
game.print(string.format("Transferring %s: %s", stack.name, slot.transfer_stack(stack)))
I should mention that I don't have SA, this was tested with plain Factorio 2.0.