------------------------------------------------------------
--             _____ _    _        _                      --
--            |_   _| |_ (_)_ _ __| |_ _  _               --
--              | | | ' \| | '_(_-<  _| || |              --
--              |_| |_||_|_|_| /__/\__|\_, |              --
--                                     |__/               --
------------------------------------------------------------
--        Thirsty mod [interoperability function]         --
------------------------------------------------------------
--       because I'm lazy and like small code blocks      --
------------------------------------------------------------

thirsty.register_food_drink = function(item_name, satiate_value, heal_value, hyd_value, hyd_max, rtn_item_name)
	if (core.registered_items[item_name] ~= nil) then
 	local def = table.copy(core.registered_items[item_name])
  local is_hunger_ng = false
 	local is_hbhunger = false
	 if core.get_modpath("hunger_ng") then is_hunger_ng = true end
 	if core.get_modpath("hbhunger") then is_hbhunger = true end

	 if is_hunger_ng then
		 hunger_ng.add_hunger_data(item_name, {
		 	satiates = satiate_value,
	 		heals = heal_value,
	 		returns = nil,
		 	timeout = nil
		 })
	 end

	 if is_hbhunger then
		 hbhunger.register_food(item_name, satiate_value)
	 end

 	def.on_use = function(itemstack, player, pointed_thing)
		 thirsty.drink(player, hyd_value, hyd_max, rtn_item_name)

		 if core.registered_items[item_name]._hunger_ng then
		 	core.sound_play("hunger_ng_eat", { to_player = player:get_player_name(), gain = 2.0 })
		 	hunger_ng.alter_hunger(player:get_player_name(), satiate_value, "from:thirsty-" .. item_name)
			 player:set_hp(player:get_hp() + heal_value)
			 itemstack:take_item()
		 	return itemstack
		 else
			 core.do_item_eat(satiate_value, nil, itemstack:take_item(), player, pointed_thing)
			 return itemstack
 		end
	 end

	 if def.type == "node" then
		 core.register_node(":" .. item_name, def)
 	else
		 core.register_craftitem(":" .. item_name, def)
	 end
 else
  core.log('warning', '[thirsty] item '.. item_name .. ' is not registered.')
 end
end
