You shoud use minetest.get_item_group() here.