1 -- Keep these for backwards compatibility
2 function hunger
.save_hunger(player
)
3 hunger
.set_hunger(player
)
5 function hunger
.load_hunger(player
)
6 hunger
.get_hunger(player
)
10 local function poisenp(tick
, time
, time_left
, player
)
11 time_left
= time_left
+ tick
12 if time_left
< time
then
13 minetest
.after(tick
, poisenp
, tick
, time
, time_left
, player
)
17 if player
:get_hp()-1 > 0 then
18 player
:set_hp(player
:get_hp()-1)
23 function hunger
.item_eat(hunger_change
, replace_with_item
, poisen
, heal
)
24 return function(itemstack
, user
, pointed_thing
)
25 if itemstack
:take_item() ~= nil and user
~= nil then
26 local name
= user
:get_player_name()
27 local h
= tonumber(hunger
.hunger
[name
])
28 local hp
= user
:get_hp()
31 if h
< 30 and hunger_change
then
33 if h
> 30 then h
= 30 end
34 hunger
.hunger
[name
] = h
35 hunger
.set_hunger(user
)
38 if hp
< 20 and heal
then
40 if hp
> 20 then hp
= 20 end
46 poisenp(1.0, poisen
, 0, user
)
50 itemstack
:add_item(replace_with_item
)
56 local function overwrite(name
, hunger_change
, replace_with_item
, poisen
, heal
)
57 local tab
= minetest
.registered_items
[name
]
58 if tab
== nil then return end
59 tab
.on_use
= hunger
.item_eat(hunger_change
, replace_with_item
, poisen
, heal
)
60 minetest
.registered_items
[name
] = tab
63 if minetest
.get_modpath("default") ~= nil then
64 overwrite("default:apple", 2)
66 if minetest
.get_modpath("farming") ~= nil then
67 overwrite("farming:bread", 4)
70 if minetest
.get_modpath("mobs") ~= nil then
71 if mobs
.mod ~= nil and mobs
.mod == "redo" then
72 overwrite("mobs:cheese", 4)
73 overwrite("mobs:meat", 8)
74 overwrite("mobs:meat_raw", 4)
75 overwrite("mobs:rat_cooked", 4)
76 overwrite("mobs:honey", 2)
77 overwrite("mobs:pork_raw", 3, "", 3)
78 overwrite("mobs:pork_cooked", 8)
79 overwrite("mobs:chicken_cooked", 6)
80 overwrite("mobs:chicken_raw", 2, "", 3)
81 overwrite("mobs:chicken_egg_fried", 2)
82 if minetest
.get_modpath("bucket") then
83 overwrite("mobs:bucket_milk", 3, "bucket:bucket_empty")
86 overwrite("mobs:meat", 6)
87 overwrite("mobs:meat_raw", 3)
88 overwrite("mobs:rat_cooked", 5)
92 if minetest
.get_modpath("moretrees") ~= nil then
93 overwrite("moretrees:coconut_milk", 1)
94 overwrite("moretrees:raw_coconut", 2)
95 overwrite("moretrees:acorn_muffin", 3)
96 overwrite("moretrees:spruce_nuts", 1)
97 overwrite("moretrees:pine_nuts", 1)
98 overwrite("moretrees:fir_nuts", 1)
101 if minetest
.get_modpath("dwarves") ~= nil then
102 overwrite("dwarves:beer", 2)
103 overwrite("dwarves:apple_cider", 1)
104 overwrite("dwarves:midus", 2)
105 overwrite("dwarves:tequila", 2)
106 overwrite("dwarves:tequila_with_lime", 2)
107 overwrite("dwarves:sake", 2)
110 if minetest
.get_modpath("animalmaterials") ~= nil then
111 overwrite("animalmaterials:milk", 2)
112 overwrite("animalmaterials:meat_raw", 3)
113 overwrite("animalmaterials:meat_pork", 3)
114 overwrite("animalmaterials:meat_beef", 3)
115 overwrite("animalmaterials:meat_chicken", 3)
116 overwrite("animalmaterials:meat_lamb", 3)
117 overwrite("animalmaterials:meat_venison", 3)
118 overwrite("animalmaterials:meat_undead", 3, "", 3)
119 overwrite("animalmaterials:meat_toxic", 3, "", 5)
120 overwrite("animalmaterials:meat_ostrich", 3)
121 overwrite("animalmaterials:fish_bluewhite", 2)
122 overwrite("animalmaterials:fish_clownfish", 2)
125 if minetest
.get_modpath("fishing") ~= nil then
126 overwrite("fishing:fish_raw", 2)
127 overwrite("fishing:fish_cooked", 5)
128 overwrite("fishing:sushi", 6)
129 overwrite("fishing:shark", 4)
130 overwrite("fishing:shark_cooked", 8)
131 overwrite("fishing:pike", 4)
132 overwrite("fishing:pike_cooked", 8)
135 if minetest
.get_modpath("glooptest") ~= nil then
136 overwrite("glooptest:kalite_lump", 1)
139 if minetest
.get_modpath("bushes") ~= nil then
140 overwrite("bushes:sugar", 1)
141 overwrite("bushes:strawberry", 2)
142 overwrite("bushes:berry_pie_raw", 3)
143 overwrite("bushes:berry_pie_cooked", 4)
144 overwrite("bushes:basket_pies", 15)
147 if minetest
.get_modpath("bushes_classic") then
148 -- bushes_classic mod, as found in the plantlife modpack
156 for _
, berry
in ipairs(berries
) do
157 if berry
~= "mixed_berry" then
158 overwrite("bushes:"..berry
, 1)
160 overwrite("bushes:"..berry
.."_pie_raw", 2)
161 overwrite("bushes:"..berry
.."_pie_cooked", 5)
162 overwrite("bushes:basket_"..berry
, 15)
166 if minetest
.get_modpath("mushroom") ~= nil then
167 overwrite("mushroom:brown", 1)
168 overwrite("mushroom:red", 1, "", 3)
169 -- mushroom potions: red = strong poison, brown = light restorative
170 if minetest
.get_modpath("vessels") then
171 overwrite("mushroom:brown_essence", 1, "vessels:glass_bottle", nil, 4)
172 overwrite("mushroom:poison", 1, "vessels:glass_bottle", 10)
176 if minetest
.get_modpath("docfarming") ~= nil then
177 overwrite("docfarming:carrot", 3)
178 overwrite("docfarming:cucumber", 2)
179 overwrite("docfarming:corn", 3)
180 overwrite("docfarming:potato", 4)
181 overwrite("docfarming:bakedpotato", 5)
182 overwrite("docfarming:raspberry", 3)
185 if minetest
.get_modpath("farming_plus") ~= nil then
186 overwrite("farming_plus:carrot_item", 3)
187 overwrite("farming_plus:banana", 2)
188 overwrite("farming_plus:orange_item", 2)
189 overwrite("farming:pumpkin_bread", 4)
190 overwrite("farming_plus:strawberry_item", 2)
191 overwrite("farming_plus:tomato_item", 2)
192 overwrite("farming_plus:potato_item", 4)
193 overwrite("farming_plus:rhubarb_item", 2)
196 if minetest
.get_modpath("mtfoods") ~= nil then
197 overwrite("mtfoods:dandelion_milk", 1)
198 overwrite("mtfoods:sugar", 1)
199 overwrite("mtfoods:short_bread", 4)
200 overwrite("mtfoods:cream", 1)
201 overwrite("mtfoods:chocolate", 2)
202 overwrite("mtfoods:cupcake", 2)
203 overwrite("mtfoods:strawberry_shortcake", 2)
204 overwrite("mtfoods:cake", 3)
205 overwrite("mtfoods:chocolate_cake", 3)
206 overwrite("mtfoods:carrot_cake", 3)
207 overwrite("mtfoods:pie_crust", 3)
208 overwrite("mtfoods:apple_pie", 3)
209 overwrite("mtfoods:rhubarb_pie", 2)
210 overwrite("mtfoods:banana_pie", 3)
211 overwrite("mtfoods:pumpkin_pie", 3)
212 overwrite("mtfoods:cookies", 2)
213 overwrite("mtfoods:mlt_burger", 5)
214 overwrite("mtfoods:potato_slices", 2)
215 overwrite("mtfoods:potato_chips", 3)
217 overwrite("mtfoods:casserole", 3)
218 overwrite("mtfoods:glass_flute", 2)
219 overwrite("mtfoods:orange_juice", 2)
220 overwrite("mtfoods:apple_juice", 2)
221 overwrite("mtfoods:apple_cider", 2)
222 overwrite("mtfoods:cider_rack", 2)
225 if minetest
.get_modpath("fruit") ~= nil then
226 overwrite("fruit:apple", 2)
227 overwrite("fruit:pear", 2)
228 overwrite("fruit:bananna", 3)
229 overwrite("fruit:orange", 2)
232 if minetest
.get_modpath("mush45") ~= nil then
233 overwrite("mush45:meal", 4)
236 if minetest
.get_modpath("seaplants") ~= nil then
237 overwrite("seaplants:kelpgreen", 1)
238 overwrite("seaplants:kelpbrown", 1)
239 overwrite("seaplants:seagrassgreen", 1)
240 overwrite("seaplants:seagrassred", 1)
241 overwrite("seaplants:seasaladmix", 6)
242 overwrite("seaplants:kelpgreensalad", 1)
243 overwrite("seaplants:kelpbrownsalad", 1)
244 overwrite("seaplants:seagrassgreensalad", 1)
245 overwrite("seaplants:seagrassgreensalad", 1)
248 if minetest
.get_modpath("mobfcooking") ~= nil then
249 overwrite("mobfcooking:cooked_pork", 6)
250 overwrite("mobfcooking:cooked_ostrich", 6)
251 overwrite("mobfcooking:cooked_beef", 6)
252 overwrite("mobfcooking:cooked_chicken", 6)
253 overwrite("mobfcooking:cooked_lamb", 6)
254 overwrite("mobfcooking:cooked_venison", 6)
255 overwrite("mobfcooking:cooked_fish", 6)
258 if minetest
.get_modpath("creatures") ~= nil then
259 overwrite("creatures:meat", 6)
260 overwrite("creatures:flesh", 3)
261 overwrite("creatures:rotten_flesh", 3, "", 3)
264 if minetest
.get_modpath("ethereal") then
265 overwrite("ethereal:strawberry", 1)
266 overwrite("ethereal:banana", 4)
267 overwrite("ethereal:pine_nuts", 1)
268 overwrite("ethereal:bamboo_sprout", 0, "", 3)
269 overwrite("ethereal:fern_tubers", 1)
270 overwrite("ethereal:banana_bread", 7)
271 overwrite("ethereal:mushroom_plant", 2)
272 overwrite("ethereal:coconut_slice", 2)
273 overwrite("ethereal:golden_apple", 4, "", nil, 10)
274 overwrite("ethereal:wild_onion_plant", 2)
275 overwrite("ethereal:mushroom_soup", 4, "ethereal:bowl")
276 overwrite("ethereal:mushroom_soup_cooked", 6, "ethereal:bowl")
277 overwrite("ethereal:hearty_stew", 6, "ethereal:bowl", 3)
278 overwrite("ethereal:hearty_stew_cooked", 10, "ethereal:bowl")
279 if minetest
.get_modpath("bucket") then
280 overwrite("ethereal:bucket_cactus", 2, "bucket:bucket_empty")
282 overwrite("ethereal:fish_raw", 2)
283 overwrite("ethereal:fish_cooked", 5)
284 overwrite("ethereal:seaweed", 1)
285 overwrite("ethereal:yellowleaves", 1, "", nil, 1)
286 overwrite("ethereal:sashimi", 4)
289 if minetest
.get_modpath("farming") and farming
.mod == "redo" then
290 overwrite("farming:bread", 6)
291 overwrite("farming:potato", 1)
292 overwrite("farming:baked_potato", 6)
293 overwrite("farming:cucumber", 4)
294 overwrite("farming:tomato", 4)
295 overwrite("farming:carrot", 3)
296 overwrite("farming:carrot_gold", 6, "", nil, 8)
297 overwrite("farming:corn", 3)
298 overwrite("farming:corn_cob", 5)
299 overwrite("farming:melon_slice", 2)
300 overwrite("farming:pumpkin_slice", 1)
301 overwrite("farming:pumpkin_bread", 9)
302 overwrite("farming:coffee_cup", 2, "farming:drinking_cup")
303 overwrite("farming:coffee_cup_hot", 3, "farming:drinking_cup", nil, 2)
304 overwrite("farming:cookie", 2)
305 overwrite("farming:chocolate_dark", 3)
306 overwrite("farming:donut", 4)
307 overwrite("farming:donut_chocolate", 6)
308 overwrite("farming:donut_apple", 6)
309 overwrite("farming:raspberries", 1)
310 overwrite("farming:blueberries", 1)
311 overwrite("farming:muffin_blueberry", 4)
312 if minetest
.get_modpath("vessels") then
313 overwrite("farming:smoothie_raspberry", 2, "vessels:drinking_glass")
315 overwrite("farming:rhubarb", 1)
316 overwrite("farming:rhubarb_pie", 6)
319 if minetest
.get_modpath("kpgmobs") ~= nil then
320 overwrite("kpgmobs:uley", 3)
321 overwrite("kpgmobs:meat", 6)
322 overwrite("kpgmobs:rat_cooked", 5)
323 overwrite("kpgmobs:med_cooked", 4)
324 if minetest
.get_modpath("bucket") then
325 overwrite("kpgmobs:bucket_milk", 4, "bucket:bucket_empty")
329 if minetest
.get_modpath("jkfarming") ~= nil then
330 overwrite("jkfarming:carrot", 3)
331 overwrite("jkfarming:corn", 3)
332 overwrite("jkfarming:melon_part", 2)
333 overwrite("jkfarming:cake", 3)
336 if minetest
.get_modpath("jkanimals") ~= nil then
337 overwrite("jkanimals:meat", 6)
340 if minetest
.get_modpath("jkwine") ~= nil then
341 overwrite("jkwine:grapes", 2)
342 overwrite("jkwine:winebottle", 1)
345 if minetest
.get_modpath("cooking") ~= nil then
346 overwrite("cooking:meat_beef_cooked", 4)
347 overwrite("cooking:fish_bluewhite_cooked", 3)
348 overwrite("cooking:fish_clownfish_cooked", 1)
349 overwrite("cooking:meat_chicken_cooked", 2)
350 overwrite("cooking:meat_cooked", 2)
351 overwrite("cooking:meat_pork_cooked", 3)
352 overwrite("cooking:meat_toxic_cooked", -3)
353 overwrite("cooking:meat_venison_cooked", 3)
354 overwrite("cooking:meat_undead_cooked", 1)
357 -- ferns mod of plantlife_modpack
358 if minetest
.get_modpath("ferns") ~= nil then
359 overwrite("ferns:fiddlehead", 1, "", 1)
360 overwrite("ferns:fiddlehead_roasted", 3)
361 overwrite("ferns:ferntuber_roasted", 3)
362 overwrite("ferns:horsetail_01", 1)
365 -- player-action based hunger changes
366 function hunger
.handle_node_actions(pos
, oldnode
, player
, ext
)
367 if not player
or not player
:is_player() then
370 local name
= player
:get_player_name()
371 local exhaus
= hunger
.exhaustion
[name
]
372 local new
= HUNGER_EXHAUST_PLACE
375 new
= HUNGER_EXHAUST_DIG
377 -- assume its send by main timer when movement detected
378 if not pos
and not oldnode
then
379 new
= HUNGER_EXHAUST_MOVE
381 exhaus
= exhaus
+ new
382 if exhaus
> HUNGER_EXHAUST_LVL
then
384 local h
= tonumber(hunger
.hunger
[name
])
386 if h
< 0 then h
= 0 end
387 hunger
.hunger
[name
] = h
388 hunger
.set_hunger(player
)
390 hunger
.exhaustion
[name
] = exhaus
393 minetest
.register_on_placenode(hunger
.handle_node_actions
)
394 minetest
.register_on_dignode(hunger
.handle_node_actions
)