Page 1 of 1

[SOLVED]Is there a mod for count the items?

PostPosted: Mon Mar 21, 2016 12:32
by Onyx
Is there a mod for count the items (e.g. fuel) that come from a chest
(with pipeworks) and they go to a furnace, so that there is no overflow (99)?
If there is no mod, ‎is it possible to create it ?

Re: Is there a mod for count the items?

PostPosted: Mon Mar 21, 2016 15:00
by blackjack
Hi Onyx,

I solved this issue (i.e. furnace overflow) with a wait loop inside the pipes forwarding goods to the furnace.
As long as the input slot of the furnace is not free, the other items will rotate in the wait loop.

Re: Is there a mod for count the items?

PostPosted: Mon Mar 21, 2016 17:56
by Krock
A mod to do that? Not that I would know of.
It's easy to write some code to do this job.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
-- Get the width of the current list
local width = inv:get_width("foobar_list")

local items = {}
for i = 1, width do
   -- Read stack at position 'i'
   local stack = inv:get_stack("foobar_list", i)
   if not items[stack:get_name()] then
      items[stack:get_name()] = stack:get_count()
   else
      items[stack:get_name()] = items[stack:get_name()] + stack:get_count()
   end
end

-- Output the items
print(dump(items))

Re: Is there a mod for count the items?

PostPosted: Tue Mar 22, 2016 09:17
by Onyx
Hi,

Thanks a lot to you two, I will study each of your solutions. ^-^