let inventory.insert() accept more properties

gheift
Fast Inserter
Fast Inserter
Posts: 188
Joined: Tue Mar 03, 2015 9:20 pm
Contact:

let inventory.insert() accept more properties

Post by gheift »

Currently, the inventory.insert(items) only accept following properties
  • name
  • count
  • health
I would like you to add the following properties:
  • durability, for e.g. tools and repair-kits
  • ammo, for left rounds in e.g. firearm-magazines
Additionally if the passed argument is a LuaItemStack and the item in this stack contains a blueprint, book, grid or other complex properties then insert the items with all its properties to the new inventory. Currently if I pass a LuaItemStack with a full blueprint and I use it in inventory.insert(stack_with_blueprint) it inserts an empty blueprint in the inventory.

Thanks,
Gerhard
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5341
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: let inventory.insert() accept more properties

Post by Klonan »

You can use LuaItemStack.set_stack to achieve the same functionality,
Insert is meant to be a simple way of inserting items to an entity,
LuaItemstack contains more powerful functions, and should be used if you want to do anything more complex
http://lua-api.factorio.com/latest/LuaItemStack.html
gheift
Fast Inserter
Fast Inserter
Posts: 188
Joined: Tue Mar 03, 2015 9:20 pm
Contact:

Re: let inventory.insert() accept more properties

Post by gheift »

I am aware of LuaItemStack.set_stack, but the problem is the following: lets say I want to add a firearm-magazine with 16 ammo left → count = 2, ammo = 6 to an inventory. To do so I have to either find a free ItemStack in the inventory, set the stack or if no slot is free, search for a stack with firearm-magazines and add them there by manually add the ammo and check for overflow. The same procedure must be done for tools and repair packs. The handling of entites with grids, blueprints or books is even more complicated. Perhaps a better solution would be exposing a function like this:

Code: Select all

local leftover = inventory.add_stack(itemstack)
  • itemstack is not modified
  • leftover is a stack with items, which could not be added to the inventory
if only 8 rounds fit into the inventory, and an itemstack countains 6, then I would like this to behave like this:

Code: Select all

local itemstack = {name = "firearm-magazine", count = 2, ammo = 6}
local leftover = inventory.add_stack(itemstack)
-- leftover = {name = "firearm-magazine", count = 1, ammo = 8}
A function like this should be available internal for handling the CTRL-Click of the mouse-stack to entities like chests, assemblers etc.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14913
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: let inventory.insert() accept more properties

Post by Rseding91 »

Added for 0.15.
If you want to get ahold of me I'm almost always on Discord.
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1197
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: let inventory.insert() accept more properties

Post by Mooncat »

Rseding91 wrote:Added for 0.15.
It is amazing to see you are implementing requests that have been made some time ago. Thanks a lot! :D
Post Reply

Return to “Implemented mod requests”