Detect if chest has items?
Detect if chest has items?
What is the Minetest way of doing this? I would like to get a mesecon line powered if a chest contains any items to start a clock that feeds the items to a furnace by pulsing a filter-injector.
- sorcerykid
- Member
- Posts: 1847
- Joined: Fri Aug 26, 2016 15:36
- GitHub: sorcerykid
- In-game: Nemo
- Location: Illinois, USA
Re: Detect if chest has items?
This is the function from my Chests Redux mod that allows for checking whether a container at any given position is empty (you can also optionally specify the list to check, but by default it uses "main").
Code: Select all
default.is_empty = function ( pos, list )
return minetest.get_meta( pos ):get_inventory( ):is_empty( list or "main" )
end
Re: Detect if chest has items?
Thanks! But, how would you use this to power a mesecon line?
Re: Detect if chest has items?
i think it should work
Code: Select all
minetest.register_node("mod:chest_checker", {
description = "Chest checker",
tiles = {"default_steel_block.png","default_steel_block.png","default_steel_block.png","default_steel_block.png","default_copper_block.png","default_steel_block.png"},
groups = {mesecon=2,snappy = 3},
sounds = default.node_sound_stone_defaults(),
mesecons = {receptor = {state = "off"}},
on_construct = function(pos)
minetest.get_node_timer(pos):start(1)
end,
on_timer = function (pos, elapsed)
local meta=minetest.get_meta(pos)
local dir = minetest.facedir_to_dir(minetest.get_node(pos).param2)
local p = {x=pos.x+dir.x,y=pos.y+dir.y,z=pos.z+dir.z}
if minetest.get_meta(p):get_inventory():is_empty("main") == false then
mesecon.receptor_on(pos)
--minetest.swap_node(pos, {name="mod:chest_checker2"})
--minetest.get_node_timer(pos):start(2)
end
return true
end
})
Who is online
Users browsing this forum: No registered users and 29 guests