hunger.lua 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. -- Keep these for backwards compatibility
  2. function hbhunger.save_hunger(player)
  3. hbhunger.save_hunger(player)
  4. end
  5. function hbhunger.load_hunger(player)
  6. hbhunger.get_hunger_raw(player)
  7. end
  8. -- wrapper for minetest.item_eat (this way we make sure other mods can't break this one)
  9. local org_eat = core.do_item_eat
  10. core.do_item_eat = function(hp_change, replace_with_item, itemstack, user, pointed_thing)
  11. local old_itemstack = itemstack
  12. itemstack = hbhunger.eat(hp_change, replace_with_item, itemstack, user, pointed_thing)
  13. for _, callback in pairs(core.registered_on_item_eats) do
  14. local result = callback(hp_change, replace_with_item, itemstack, user, pointed_thing, old_itemstack)
  15. if result then
  16. return result
  17. end
  18. end
  19. return itemstack
  20. end
  21. -- food functions
  22. local food = hbhunger.food
  23. function hbhunger.register_food(name, hunger_change, replace_with_item, poisen, heal, sound)
  24. food[name] = {}
  25. food[name].saturation = hunger_change -- hunger points added
  26. food[name].replace = replace_with_item -- what item is given back after eating
  27. food[name].poisen = poisen -- time its poisening
  28. food[name].healing = heal -- amount of HP
  29. food[name].sound = sound -- special sound that is played when eating
  30. end
  31. function hbhunger.eat(hp_change, replace_with_item, itemstack, user, pointed_thing)
  32. local item = itemstack:get_name()
  33. local def = food[item]
  34. if not def then
  35. def = {}
  36. if type(hp_change) ~= "number" then
  37. hp_change = 1
  38. core.log("error", "Wrong on_use() definition for item '" .. item .. "'")
  39. end
  40. def.saturation = hp_change * 1.3
  41. def.replace = replace_with_item
  42. end
  43. local func = hbhunger.item_eat(def.saturation, def.replace, def.poisen, def.healing, def.sound)
  44. return func(itemstack, user, pointed_thing)
  45. end
  46. -- Poison player
  47. local function poisenp(tick, time, time_left, player)
  48. -- First check if player is still there
  49. if not player:is_player() then
  50. return
  51. end
  52. time_left = time_left + tick
  53. if time_left < time then
  54. minetest.after(tick, poisenp, tick, time, time_left, player)
  55. else
  56. hbhunger.poisonings[player:get_player_name()] = hbhunger.poisonings[player:get_player_name()] - 1
  57. if hbhunger.poisonings[player:get_player_name()] <= 0 then
  58. -- Reset HUD bar color
  59. hb.change_hudbar(player, "health", nil, nil, "hudbars_icon_health.png", nil, "hudbars_bar_health.png")
  60. end
  61. end
  62. if player:get_hp()-1 > 0 then
  63. player:set_hp(player:get_hp()-1)
  64. end
  65. end
  66. function hbhunger.item_eat(hunger_change, replace_with_item, poisen, heal, sound)
  67. return function(itemstack, user, pointed_thing)
  68. if itemstack:take_item() ~= nil and user ~= nil then
  69. local name = user:get_player_name()
  70. local h = tonumber(hbhunger.hunger[name])
  71. local max_sat = tonumber(hbhunger.max[name])
  72. local hp = user:get_hp()
  73. if h == nil or hp == nil then
  74. return
  75. end
  76. minetest.sound_play(
  77. {name = sound or "hbhunger_eat_generic",
  78. gain = 1},
  79. {object=user,
  80. max_hear_distance = 16,
  81. pitch = 1 + math.random(-10, 10)*0.005,}
  82. )
  83. -- Saturation
  84. if h < max_sat and hunger_change then
  85. h = h + hunger_change
  86. if h > max_sat then h = max_sat end
  87. hbhunger.hunger[name] = h
  88. hbhunger.save_hunger(user)
  89. end
  90. -- Healing
  91. if hp < 20 and heal then
  92. hp = hp + heal
  93. if hp > 20 then hp = 20 end
  94. user:set_hp(hp)
  95. end
  96. -- Poison
  97. if poisen then
  98. -- Set poison bar
  99. hb.change_hudbar(user, "health", nil, nil, "hbhunger_icon_health_poison.png", nil, "hbhunger_bar_health_poison.png")
  100. hbhunger.poisonings[name] = hbhunger.poisonings[name] + 1
  101. poisenp(1, poisen, 0, user)
  102. end
  103. if itemstack:get_count() == 0 then
  104. itemstack:add_item(replace_with_item)
  105. else
  106. local inv = user:get_inventory()
  107. if inv:room_for_item("main", replace_with_item) then
  108. inv:add_item("main", replace_with_item)
  109. else
  110. minetest.add_item(user:getpos(), replace_with_item)
  111. end
  112. end
  113. end
  114. return itemstack
  115. end
  116. end
  117. if minetest.get_modpath("default") ~= nil then
  118. hbhunger.register_food("default:apple", 2)
  119. end
  120. if minetest.get_modpath("flowers") ~= nil then
  121. hbhunger.register_food("flowers:mushroom_brown", 1)
  122. hbhunger.register_food("flowers:mushroom_red", 1, "", 3)
  123. end
  124. if minetest.get_modpath("farming") ~= nil then
  125. hbhunger.register_food("farming:bread", 4)
  126. end
  127. if minetest.get_modpath("mobs") ~= nil then
  128. if mobs.mod ~= nil and mobs.mod == "redo" then
  129. hbhunger.register_food("mobs:cheese", 4)
  130. hbhunger.register_food("mobs:meat", 8)
  131. hbhunger.register_food("mobs:meat_raw", 4)
  132. hbhunger.register_food("mobs:rat_cooked", 4)
  133. hbhunger.register_food("mobs:honey", 2)
  134. hbhunger.register_food("mobs:pork_raw", 3, "", 3)
  135. hbhunger.register_food("mobs:pork_cooked", 8)
  136. hbhunger.register_food("mobs:chicken_cooked", 6)
  137. hbhunger.register_food("mobs:chicken_raw", 2, "", 3)
  138. hbhunger.register_food("mobs:chicken_egg_fried", 2)
  139. if minetest.get_modpath("bucket") then
  140. hbhunger.register_food("mobs:bucket_milk", 3, "bucket:bucket_empty")
  141. end
  142. else
  143. hbhunger.register_food("mobs:meat", 6)
  144. hbhunger.register_food("mobs:meat_raw", 3)
  145. hbhunger.register_food("mobs:rat_cooked", 5)
  146. end
  147. end
  148. if minetest.get_modpath("moretrees") ~= nil then
  149. hbhunger.register_food("moretrees:coconut_milk", 1)
  150. hbhunger.register_food("moretrees:raw_coconut", 2)
  151. hbhunger.register_food("moretrees:acorn_muffin", 3)
  152. hbhunger.register_food("moretrees:spruce_nuts", 1)
  153. hbhunger.register_food("moretrees:pine_nuts", 1)
  154. hbhunger.register_food("moretrees:fir_nuts", 1)
  155. end
  156. if minetest.get_modpath("dwarves") ~= nil then
  157. hbhunger.register_food("dwarves:beer", 2)
  158. hbhunger.register_food("dwarves:apple_cider", 1)
  159. hbhunger.register_food("dwarves:midus", 2)
  160. hbhunger.register_food("dwarves:tequila", 2)
  161. hbhunger.register_food("dwarves:tequila_with_lime", 2)
  162. hbhunger.register_food("dwarves:sake", 2)
  163. end
  164. if minetest.get_modpath("animalmaterials") ~= nil then
  165. hbhunger.register_food("animalmaterials:milk", 2)
  166. hbhunger.register_food("animalmaterials:meat_raw", 3)
  167. hbhunger.register_food("animalmaterials:meat_pork", 3)
  168. hbhunger.register_food("animalmaterials:meat_beef", 3)
  169. hbhunger.register_food("animalmaterials:meat_chicken", 3)
  170. hbhunger.register_food("animalmaterials:meat_lamb", 3)
  171. hbhunger.register_food("animalmaterials:meat_venison", 3)
  172. hbhunger.register_food("animalmaterials:meat_undead", 3, "", 3)
  173. hbhunger.register_food("animalmaterials:meat_toxic", 3, "", 5)
  174. hbhunger.register_food("animalmaterials:meat_ostrich", 3)
  175. hbhunger.register_food("animalmaterials:fish_bluewhite", 2)
  176. hbhunger.register_food("animalmaterials:fish_clownfish", 2)
  177. end
  178. if minetest.get_modpath("fishing") ~= nil then
  179. hbhunger.register_food("fishing:fish_raw", 2)
  180. hbhunger.register_food("fishing:fish_cooked", 5)
  181. hbhunger.register_food("fishing:sushi", 6)
  182. hbhunger.register_food("fishing:shark", 4)
  183. hbhunger.register_food("fishing:shark_cooked", 8)
  184. hbhunger.register_food("fishing:pike", 4)
  185. hbhunger.register_food("fishing:pike_cooked", 8)
  186. end
  187. if minetest.get_modpath("glooptest") ~= nil then
  188. hbhunger.register_food("glooptest:kalite_lump", 1)
  189. end
  190. if minetest.get_modpath("bushes") ~= nil then
  191. hbhunger.register_food("bushes:sugar", 1)
  192. hbhunger.register_food("bushes:strawberry", 2)
  193. hbhunger.register_food("bushes:berry_pie_raw", 3)
  194. hbhunger.register_food("bushes:berry_pie_cooked", 4)
  195. hbhunger.register_food("bushes:basket_pies", 15)
  196. end
  197. if minetest.get_modpath("bushes_classic") then
  198. -- bushes_classic mod, as found in the plantlife modpack
  199. local berries = {
  200. "strawberry",
  201. "blackberry",
  202. "blueberry",
  203. "raspberry",
  204. "gooseberry",
  205. "mixed_berry"}
  206. for _, berry in ipairs(berries) do
  207. if berry ~= "mixed_berry" then
  208. hbhunger.register_food("bushes:"..berry, 1)
  209. end
  210. hbhunger.register_food("bushes:"..berry.."_pie_raw", 2)
  211. hbhunger.register_food("bushes:"..berry.."_pie_cooked", 5)
  212. hbhunger.register_food("bushes:basket_"..berry, 15)
  213. end
  214. end
  215. if minetest.get_modpath("mushroom") ~= nil then
  216. hbhunger.register_food("mushroom:brown", 1)
  217. hbhunger.register_food("mushroom:red", 1, "", 3)
  218. -- mushroom potions: red = strong poison, brown = light restorative
  219. if minetest.get_modpath("vessels") then
  220. hbhunger.register_food("mushroom:brown_essence", 1, "vessels:glass_bottle", nil, 4)
  221. hbhunger.register_food("mushroom:poison", 1, "vessels:glass_bottle", 10)
  222. end
  223. end
  224. if minetest.get_modpath("docfarming") ~= nil then
  225. hbhunger.register_food("docfarming:carrot", 3)
  226. hbhunger.register_food("docfarming:cucumber", 2)
  227. hbhunger.register_food("docfarming:corn", 3)
  228. hbhunger.register_food("docfarming:potato", 4)
  229. hbhunger.register_food("docfarming:bakedpotato", 5)
  230. hbhunger.register_food("docfarming:raspberry", 3)
  231. end
  232. if minetest.get_modpath("farming_plus") ~= nil then
  233. hbhunger.register_food("farming_plus:carrot_item", 3)
  234. hbhunger.register_food("farming_plus:banana", 2)
  235. hbhunger.register_food("farming_plus:orange_item", 2)
  236. hbhunger.register_food("farming:pumpkin_bread", 4)
  237. hbhunger.register_food("farming_plus:strawberry_item", 2)
  238. hbhunger.register_food("farming_plus:tomato_item", 2)
  239. hbhunger.register_food("farming_plus:potato_item", 4)
  240. hbhunger.register_food("farming_plus:rhubarb_item", 2)
  241. end
  242. if minetest.get_modpath("mtfoods") ~= nil then
  243. hbhunger.register_food("mtfoods:dandelion_milk", 1)
  244. hbhunger.register_food("mtfoods:sugar", 1)
  245. hbhunger.register_food("mtfoods:short_bread", 4)
  246. hbhunger.register_food("mtfoods:cream", 1)
  247. hbhunger.register_food("mtfoods:chocolate", 2)
  248. hbhunger.register_food("mtfoods:cupcake", 2)
  249. hbhunger.register_food("mtfoods:strawberry_shortcake", 2)
  250. hbhunger.register_food("mtfoods:cake", 3)
  251. hbhunger.register_food("mtfoods:chocolate_cake", 3)
  252. hbhunger.register_food("mtfoods:carrot_cake", 3)
  253. hbhunger.register_food("mtfoods:pie_crust", 3)
  254. hbhunger.register_food("mtfoods:apple_pie", 3)
  255. hbhunger.register_food("mtfoods:rhubarb_pie", 2)
  256. hbhunger.register_food("mtfoods:banana_pie", 3)
  257. hbhunger.register_food("mtfoods:pumpkin_pie", 3)
  258. hbhunger.register_food("mtfoods:cookies", 2)
  259. hbhunger.register_food("mtfoods:mlt_burger", 5)
  260. hbhunger.register_food("mtfoods:potato_slices", 2)
  261. hbhunger.register_food("mtfoods:potato_chips", 3)
  262. --mtfoods:medicine
  263. hbhunger.register_food("mtfoods:casserole", 3)
  264. hbhunger.register_food("mtfoods:glass_flute", 2)
  265. hbhunger.register_food("mtfoods:orange_juice", 2)
  266. hbhunger.register_food("mtfoods:apple_juice", 2)
  267. hbhunger.register_food("mtfoods:apple_cider", 2)
  268. hbhunger.register_food("mtfoods:cider_rack", 2)
  269. end
  270. if minetest.get_modpath("fruit") ~= nil then
  271. hbhunger.register_food("fruit:apple", 2)
  272. hbhunger.register_food("fruit:pear", 2)
  273. hbhunger.register_food("fruit:bananna", 3)
  274. hbhunger.register_food("fruit:orange", 2)
  275. end
  276. if minetest.get_modpath("mush45") ~= nil then
  277. hbhunger.register_food("mush45:meal", 4)
  278. end
  279. if minetest.get_modpath("seaplants") ~= nil then
  280. hbhunger.register_food("seaplants:kelpgreen", 1)
  281. hbhunger.register_food("seaplants:kelpbrown", 1)
  282. hbhunger.register_food("seaplants:seagrassgreen", 1)
  283. hbhunger.register_food("seaplants:seagrassred", 1)
  284. hbhunger.register_food("seaplants:seasaladmix", 6)
  285. hbhunger.register_food("seaplants:kelpgreensalad", 1)
  286. hbhunger.register_food("seaplants:kelpbrownsalad", 1)
  287. hbhunger.register_food("seaplants:seagrassgreensalad", 1)
  288. hbhunger.register_food("seaplants:seagrassgreensalad", 1)
  289. end
  290. if minetest.get_modpath("mobfcooking") ~= nil then
  291. hbhunger.register_food("mobfcooking:cooked_pork", 6)
  292. hbhunger.register_food("mobfcooking:cooked_ostrich", 6)
  293. hbhunger.register_food("mobfcooking:cooked_beef", 6)
  294. hbhunger.register_food("mobfcooking:cooked_chicken", 6)
  295. hbhunger.register_food("mobfcooking:cooked_lamb", 6)
  296. hbhunger.register_food("mobfcooking:cooked_venison", 6)
  297. hbhunger.register_food("mobfcooking:cooked_fish", 6)
  298. end
  299. if minetest.get_modpath("creatures") ~= nil then
  300. hbhunger.register_food("creatures:meat", 6)
  301. hbhunger.register_food("creatures:flesh", 3)
  302. hbhunger.register_food("creatures:rotten_flesh", 3, "", 3)
  303. end
  304. if minetest.get_modpath("ethereal") then
  305. hbhunger.register_food("ethereal:strawberry", 1)
  306. hbhunger.register_food("ethereal:banana", 4)
  307. hbhunger.register_food("ethereal:pine_nuts", 1)
  308. hbhunger.register_food("ethereal:bamboo_sprout", 0, "", 3)
  309. hbhunger.register_food("ethereal:fern_tubers", 1)
  310. hbhunger.register_food("ethereal:banana_bread", 7)
  311. hbhunger.register_food("ethereal:mushroom_plant", 2)
  312. hbhunger.register_food("ethereal:coconut_slice", 2)
  313. hbhunger.register_food("ethereal:golden_apple", 4, "", nil, 10)
  314. hbhunger.register_food("ethereal:wild_onion_plant", 2)
  315. hbhunger.register_food("ethereal:mushroom_soup", 4, "ethereal:bowl")
  316. hbhunger.register_food("ethereal:mushroom_soup_cooked", 6, "ethereal:bowl")
  317. hbhunger.register_food("ethereal:hearty_stew", 6, "ethereal:bowl", 3)
  318. hbhunger.register_food("ethereal:hearty_stew_cooked", 10, "ethereal:bowl")
  319. if minetest.get_modpath("bucket") then
  320. hbhunger.register_food("ethereal:bucket_cactus", 2, "bucket:bucket_empty")
  321. end
  322. hbhunger.register_food("ethereal:fish_raw", 2)
  323. hbhunger.register_food("ethereal:fish_cooked", 5)
  324. hbhunger.register_food("ethereal:seaweed", 1)
  325. hbhunger.register_food("ethereal:yellowleaves", 1, "", nil, 1)
  326. hbhunger.register_food("ethereal:sashimi", 4)
  327. hbhunger.register_food("ethereal:orange", 2)
  328. end
  329. if minetest.get_modpath("farming") and farming.mod == "redo" then
  330. hbhunger.register_food("farming:bread", 6)
  331. hbhunger.register_food("farming:potato", 1)
  332. hbhunger.register_food("farming:baked_potato", 6)
  333. hbhunger.register_food("farming:cucumber", 4)
  334. hbhunger.register_food("farming:tomato", 4)
  335. hbhunger.register_food("farming:carrot", 3)
  336. hbhunger.register_food("farming:carrot_gold", 20, "", nil, 8)
  337. hbhunger.register_food("farming:corn", 3)
  338. hbhunger.register_food("farming:corn_cob", 5)
  339. hbhunger.register_food("farming:melon_slice", 2)
  340. hbhunger.register_food("farming:pumpkin_slice", 1)
  341. hbhunger.register_food("farming:pumpkin_bread", 9)
  342. hbhunger.register_food("farming:coffee_cup", 2, "farming:drinking_cup")
  343. hbhunger.register_food("farming:coffee_cup_hot", 3, "farming:drinking_cup", nil, 2)
  344. hbhunger.register_food("farming:cookie", 2)
  345. hbhunger.register_food("farming:chocolate_dark", 3)
  346. hbhunger.register_food("farming:chocolate_block", 27)
  347. hbhunger.register_food("farming:donut", 4)
  348. hbhunger.register_food("farming:donut_chocolate", 6)
  349. hbhunger.register_food("farming:donut_apple", 6)
  350. hbhunger.register_food("farming:raspberries", 1)
  351. hbhunger.register_food("farming:blueberries", 1)
  352. hbhunger.register_food("farming:muffin_blueberry", 4)
  353. if minetest.get_modpath("vessels") then
  354. hbhunger.register_food("farming:smoothie_raspberry", 2, "vessels:drinking_glass")
  355. end
  356. hbhunger.register_food("farming:rhubarb", 1)
  357. hbhunger.register_food("farming:rhubarb_pie", 6)
  358. hbhunger.register_food("farming:beans", 1)
  359. end
  360. if minetest.get_modpath("kpgmobs") ~= nil then
  361. hbhunger.register_food("kpgmobs:uley", 3)
  362. hbhunger.register_food("kpgmobs:meat", 6)
  363. hbhunger.register_food("kpgmobs:rat_cooked", 5)
  364. hbhunger.register_food("kpgmobs:med_cooked", 4)
  365. if minetest.get_modpath("bucket") then
  366. hbhunger.register_food("kpgmobs:bucket_milk", 4, "bucket:bucket_empty")
  367. end
  368. end
  369. if minetest.get_modpath("jkfarming") ~= nil then
  370. hbhunger.register_food("jkfarming:carrot", 3)
  371. hbhunger.register_food("jkfarming:corn", 3)
  372. hbhunger.register_food("jkfarming:melon_part", 2)
  373. hbhunger.register_food("jkfarming:cake", 3)
  374. end
  375. if minetest.get_modpath("jkanimals") ~= nil then
  376. hbhunger.register_food("jkanimals:meat", 6)
  377. end
  378. if minetest.get_modpath("jkwine") ~= nil then
  379. hbhunger.register_food("jkwine:grapes", 2)
  380. hbhunger.register_food("jkwine:winebottle", 1)
  381. end
  382. if minetest.get_modpath("cooking") ~= nil then
  383. hbhunger.register_food("cooking:meat_beef_cooked", 4)
  384. hbhunger.register_food("cooking:fish_bluewhite_cooked", 3)
  385. hbhunger.register_food("cooking:fish_clownfish_cooked", 1)
  386. hbhunger.register_food("cooking:meat_chicken_cooked", 2)
  387. hbhunger.register_food("cooking:meat_cooked", 2)
  388. hbhunger.register_food("cooking:meat_pork_cooked", 3)
  389. hbhunger.register_food("cooking:meat_toxic_cooked", -3)
  390. hbhunger.register_food("cooking:meat_venison_cooked", 3)
  391. hbhunger.register_food("cooking:meat_undead_cooked", 1)
  392. end
  393. -- ferns mod of plantlife_modpack
  394. if minetest.get_modpath("ferns") ~= nil then
  395. hbhunger.register_food("ferns:fiddlehead", 1, "", 1)
  396. hbhunger.register_food("ferns:fiddlehead_roasted", 3)
  397. hbhunger.register_food("ferns:ferntuber_roasted", 3)
  398. hbhunger.register_food("ferns:horsetail_01", 1)
  399. end
  400. if minetest.get_modpath("pizza") ~= nil then
  401. hbhunger.register_food("pizza:pizza", 30, "", nil, 30)
  402. hbhunger.register_food("pizza:pizzaslice", 5, "", nil, 5)
  403. end
  404. if minetest.get_modpath("nssm") then
  405. hbhunger.register_food("nssm:werewolf_leg", 3)
  406. hbhunger.register_food("nssm:heron_leg", 2)
  407. hbhunger.register_food("nssm:chichibios_heron_leg", 4)
  408. hbhunger.register_food("nssm:crocodile_tail", 3)
  409. hbhunger.register_food("nssm:duck_legs", 1)
  410. hbhunger.register_food("nssm:ant_leg", 1)
  411. hbhunger.register_food("nssm:spider_leg", 1)
  412. hbhunger.register_food("nssm:tentacle", 2)
  413. hbhunger.register_food("nssm:worm_flesh", 2, "", 2) -- poisonous
  414. hbhunger.register_food("nssm:amphibian_heart", 1)
  415. hbhunger.register_food("nssm:raw_scrausics_wing", 1)
  416. -- superfoods
  417. hbhunger.register_food("nssm:phoenix_nuggets", 20, "", nil, 20)
  418. hbhunger.register_food("nssm:phoenix_tear", 20, "", nil, 20)
  419. end
  420. -- player-action based hunger changes
  421. function hbhunger.handle_node_actions(pos, oldnode, player, ext)
  422. -- is_fake_player comes from the pipeworks, we are not interested in those
  423. if not player or not player:is_player() or player.is_fake_player == true then
  424. return
  425. end
  426. local name = player:get_player_name()
  427. local exhaus = hbhunger.exhaustion[name]
  428. if exhaus == nil then return end
  429. local new = hbhunger.EXHAUST_PLACE
  430. -- placenode event
  431. if not ext then
  432. new = hbhunger.EXHAUST_DIG
  433. end
  434. -- assume its send by main timer when movement detected
  435. if not pos and not oldnode then
  436. new = hbhunger.EXHAUST_MOVE
  437. end
  438. exhaus = exhaus + new
  439. if exhaus > hbhunger.EXHAUST_LVL then
  440. exhaus = 0
  441. local h = tonumber(hbhunger.hunger[name])
  442. h = h - 1
  443. if h < 0 then h = 0 end
  444. hbhunger.hunger[name] = h
  445. hbhunger.save_hunger(player)
  446. end
  447. hbhunger.exhaustion[name] = exhaus
  448. end
  449. minetest.register_on_placenode(hbhunger.handle_node_actions)
  450. minetest.register_on_dignode(hbhunger.handle_node_actions)