Is it possible to read inventory faster than now? The code like
Code: Select all
local inventory = entity.get_inventory(defines.inventory.chest) -- defines.inventory.chest == 1
if inventory then
for n = 1, #inventory do
local item_stack = inventory[n]
if item_stack and item_stack.valid_for_read then
game.print(serpent.line (item_stack))
end
end
end
It looks like the C++ part is much faster, I've tested it with this mod, but there is very tiny UPS improvement.
But If we use this mod EmptySlotsReader and read slots one-by-one, it needs too much UPS.
Can you please check if it can be easier just with
Code: Select all
local inventory = entity.get_inventory(defines.inventory.chest)
local slots = inventory.get_slots() -- read only; nil if no inventory
Where slots is just one Lua table such as
Code: Select all
slots = {
[1] = {item_name = "iron-plate", count = 4},
[2] = nil,
[3] = {item_name = "copper-plate", count = 16},
[4] = nil,
[5] = {blocked = true} -- etc.
}
Code: Select all
slots = {
[1] = {item_name = "iron-plate", count = 4},
[2] = nil,
[3] = {item_name = "copper-plate", count = 16},
[4] = {filter = "steel-plate"},
[5] = {blocked = true} -- etc.
}
Reason: The Inventory.get_contents already works.