Page 1 of 1

[Genhis] [1.1.70] LuaItemStack.swap_stack does not keep the temporary nature of items

Posted: Wed Nov 16, 2022 6:18 pm
by Wiwiweb
As discussed on discord with Klonan:
https://discord.com/channels/1396775903 ... 1213481020
Reproduction:
* Get a save file with 2 characters (save file included)
* Get a deconstruction planner in hand (alt+D). Dismiss it (Q). It disappears and does not go to the inventory, as expected.
* Get a deconstruction planner in hand again.
* Swap character and swap cursor stack using this:

Code: Select all

/c 
local old_char = game.surfaces.nauvis.find_entities_filtered{name = "character", force = "player", limit = 1, position = {-5.5,0.5}, radius = 2}[1]
local new_char = game.surfaces.nauvis.find_entities_filtered{name = "character", force = "player", limit = 1, position = {7.5,0.5}, radius = 2}[1]
game.player.set_controller{type=defines.controllers.character, character=new_char}
new_char.cursor_stack.swap_stack(old_char.cursor_stack)
* You are now the controlling the other character, but you still have the deconstruction planner in hand.
* Dismiss it (Q). The empty planner goes to inventory instead of disappearing.

This is an issue for the Jetpack mod, where it can cause players to end up with lots of empty planners in their inventories.

Re: [Genhis] [1.1.70] LuaItemStack.swap_stack does not keep the temporary nature of items

Posted: Sat Dec 03, 2022 12:37 pm
by Genhis
This is not a bug. LuaItemStack doesn't know it is supposed to be temporary. I am moving it to modding interface requests.

For the next release, I added LuaPlayer::cursor_stack_temporary (read/write boolean) which you can use to mark cursor stack as temporary. It works for blueprints, blueprint books, deconstruction planners and upgrade planners. If a player holds a different type in the cursor, write operation is silently ignored.

Re: [Genhis] [1.1.70] LuaItemStack.swap_stack does not keep the temporary nature of items

Posted: Tue Dec 06, 2022 8:21 pm
by Wiwiweb
That's great! Thanks!