I have noticed that the following code, puts the item in hand correctly, but it doesn't reserve a slot for it in the main inventory - so if logistic robots fill player's inventory with junk, the player will not be able to put that item back:
Code: Select all
player.get_main_inventory().main_inventory.find_item_stack("ZoomingReinvented_binoculars")
player.clean_cursor()
player.cursor_stack.swap_stack(binoculars_in_inventory)
Overall, a task that I would expect to be a few lines of code, has already a dozen and still doesn't work the way I would like it to:
Code: Select all
if not player.cursor_stack.valid_for_read or player.cursor_stack.name ~= "ZoomingReinvented_binoculars" then
local main_inventory = player.get_main_inventory();
local binoculars_in_inventory = main_inventory.find_item_stack("ZoomingReinvented_binoculars")
if not binoculars_in_inventory and main_inventory.can_insert("ZoomingReinvented_binoculars") then
main_inventory.insert("ZoomingReinvented_binoculars")
end
binoculars_in_inventory = main_inventory.find_item_stack("ZoomingReinvented_binoculars")
if binoculars_in_inventory then
player.clean_cursor()
player.cursor_stack.swap_stack(binoculars_in_inventory)
end
end