hunger.lua 14.7 KB
Newer Older
TenPlus1's avatar
TenPlus1 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
-- Keep these for backwards compatibility
function hbhunger.save_hunger(player)
	hbhunger.set_hunger(player)
end
function hbhunger.load_hunger(player)
	hbhunger.get_hunger(player)
end

-- Poison player
local function poisenp(tick, time, time_left, player)
	time_left = time_left + tick
	if time_left < time then
		minetest.after(tick, poisenp, tick, time, time_left, player)
	else
		--reset hud image
	end
	if player:get_hp()-1 > 0 then
		player:set_hp(player:get_hp()-1)
	end
	
end

function hbhunger.item_eat(hunger_change, replace_with_item, poisen, heal)
	return function(itemstack, user, pointed_thing)
		if itemstack:take_item() ~= nil and user ~= nil then
			local name = user:get_player_name()
			local h = tonumber(hbhunger.hunger[name])
			local hp = user:get_hp()
TenPlus1's avatar
TenPlus1 committed
29 30 31 32
			minetest.sound_play("hbhunger_eat_generic", {
				object = user,
				max_hear_distance = 10,
				gain = 1.0
TenPlus1's avatar
TenPlus1 committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
			})

			-- Saturation
			if h < 30 and hunger_change then
				h = h + hunger_change
				if h > 30 then h = 30 end
				hbhunger.hunger[name] = h
				hbhunger.set_hunger(user)
			end
			-- Healing
			if hp < 20 and heal then
				hp = hp + heal
				if hp > 20 then hp = 20 end
				user:set_hp(hp)
			end
			-- Poison
			if poisen then
				--set hud-img
				poisenp(1.0, poisen, 0, user)
			end

			if replace_with_item then
				if itemstack:is_empty() then
					itemstack:add_item(replace_with_item)
				else
					local inv = user:get_inventory()
					if inv:room_for_item("main", {name = replace_with_item}) then
						inv:add_item("main", replace_with_item)
					else
						local pos = user:getpos()
						pos.y = math.floor(pos.y + 0.5)
						core.add_item(pos, replace_with_item)
					end
				end
			end

		end
		return itemstack
	end
end

local function overwrite(name, hunger_change, replace_with_item, poisen, heal)
	local tab = minetest.registered_items[name]
	if tab == nil then return end
	tab.on_use = hbhunger.item_eat(hunger_change, replace_with_item, poisen, heal)
	minetest.registered_items[name] = tab
end

if minetest.get_modpath("default") ~= nil then
	overwrite("default:apple", 2)
end
if minetest.get_modpath("farming") ~= nil then
	overwrite("farming:bread", 4)
86
    overwrite("farming:strawberry", 2)
TenPlus1's avatar
TenPlus1 committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
end
if minetest.get_modpath("flowers") ~= nil then
	overwrite("flowers:mushroom_brown", 2)
	overwrite("flowers:mushroom_red", 0, "", 6)
end

if minetest.get_modpath("mobs") ~= nil then
	if mobs.mod ~= nil and mobs.mod == "redo" then
		overwrite("mobs:cheese", 4)
		overwrite("mobs:meat", 8)
		overwrite("mobs:meat_raw", 4)
		overwrite("mobs:rat_cooked", 4)
		overwrite("mobs:honey", 2)
		overwrite("mobs:pork_raw", 3, "", 3)
		overwrite("mobs:pork_cooked", 8)
		overwrite("mobs:chicken_cooked", 6)
		overwrite("mobs:chicken_raw", 2, "", 3)
		overwrite("mobs:chicken_egg_fried", 2)
		if minetest.get_modpath("bucket") then 
			overwrite("mobs:bucket_milk", 3, "bucket:bucket_empty")
		end
	else
		overwrite("mobs:meat", 6)
		overwrite("mobs:meat_raw", 3)
		overwrite("mobs:rat_cooked", 5)
	end
end

if minetest.get_modpath("moretrees") ~= nil then
	overwrite("moretrees:coconut_milk", 1)
	overwrite("moretrees:raw_coconut", 2)
	overwrite("moretrees:acorn_muffin", 3)
	overwrite("moretrees:spruce_nuts", 1)
	overwrite("moretrees:pine_nuts", 1)
	overwrite("moretrees:fir_nuts", 1)
end

if minetest.get_modpath("dwarves") ~= nil then
	overwrite("dwarves:beer", 2)
	overwrite("dwarves:apple_cider", 1)
	overwrite("dwarves:midus", 2)
	overwrite("dwarves:tequila", 2)
	overwrite("dwarves:tequila_with_lime", 2)
	overwrite("dwarves:sake", 2)
end

if minetest.get_modpath("animalmaterials") ~= nil then
	overwrite("animalmaterials:milk", 2)
	overwrite("animalmaterials:meat_raw", 3)
	overwrite("animalmaterials:meat_pork", 3)
	overwrite("animalmaterials:meat_beef", 3)
	overwrite("animalmaterials:meat_chicken", 3)
	overwrite("animalmaterials:meat_lamb", 3)
	overwrite("animalmaterials:meat_venison", 3)
	overwrite("animalmaterials:meat_undead", 3, "", 3)
	overwrite("animalmaterials:meat_toxic", 3, "", 5)
	overwrite("animalmaterials:meat_ostrich", 3)
	overwrite("animalmaterials:fish_bluewhite", 2)
	overwrite("animalmaterials:fish_clownfish", 2)
end

if minetest.get_modpath("fishing") ~= nil then
	overwrite("fishing:fish_raw", 2)
	overwrite("fishing:fish_cooked", 5)
	overwrite("fishing:sushi", 6)
	overwrite("fishing:shark", 4)
	overwrite("fishing:shark_cooked", 8)
	overwrite("fishing:pike", 4)
	overwrite("fishing:pike_cooked", 8)
end

if minetest.get_modpath("glooptest") ~= nil then
	overwrite("glooptest:kalite_lump", 1)
end

if minetest.get_modpath("bushes") ~= nil then
	overwrite("bushes:sugar", 1)
	overwrite("bushes:strawberry", 2)
Milan's avatar
Milan committed
165
	overwrite("bushes:berry_pie_raw", 8)
Milan's avatar
Milan committed
166 167
	overwrite("bushes:berry_pie_cooked", 15)
	overwrite("bushes:basket_pies", 20)
TenPlus1's avatar
TenPlus1 committed
168 169 170 171 172 173 174 175 176 177 178
end

if minetest.get_modpath("bushes_classic") then
	-- bushes_classic mod, as found in the plantlife modpack
	local berries = {
		"strawberry",
		"blackberry",
		"blueberry",
		"raspberry",
		"gooseberry",
		"mixed_berry"}
TenPlus1's avatar
TenPlus1 committed
179
	for _, berry in pairs(berries) do
TenPlus1's avatar
TenPlus1 committed
180 181 182
		if berry ~= "mixed_berry" then
			overwrite("bushes:"..berry, 1)
		end
Milan's avatar
Milan committed
183
        overwrite("bushes:"..berry.."_pie_slice", 4)
Milan's avatar
Milan committed
184 185 186
		overwrite("bushes:"..berry.."_pie_raw", 8)
		overwrite("bushes:"..berry.."_pie_cooked", 15)
		overwrite("bushes:basket_"..berry, 20)
TenPlus1's avatar
TenPlus1 committed
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
	end
end

if minetest.get_modpath("mushroom") ~= nil then
	overwrite("mushroom:brown", 1)
	overwrite("mushroom:red", 1, "", 3)
	-- mushroom potions: red = strong poison, brown = light restorative
	if minetest.get_modpath("vessels") then
		overwrite("mushroom:brown_essence", 1, "vessels:glass_bottle", nil, 4)
		overwrite("mushroom:poison", 1, "vessels:glass_bottle", 10)
	end
end

if minetest.get_modpath("docfarming") ~= nil then
	overwrite("docfarming:carrot", 3)
	overwrite("docfarming:cucumber", 2)
	overwrite("docfarming:corn", 3)
	overwrite("docfarming:potato", 4)
	overwrite("docfarming:bakedpotato", 5)
	overwrite("docfarming:raspberry", 3)
end

if minetest.get_modpath("farming_plus") ~= nil then
	overwrite("farming_plus:carrot_item", 3)
	overwrite("farming_plus:banana", 2)
	overwrite("farming_plus:orange_item", 2)
	overwrite("farming:pumpkin_bread", 4)
	overwrite("farming_plus:strawberry_item", 2)
	overwrite("farming_plus:tomato_item", 2)
	overwrite("farming_plus:potato_item", 4)
	overwrite("farming_plus:rhubarb_item", 2)
end

if minetest.get_modpath("mtfoods") ~= nil then
	overwrite("mtfoods:dandelion_milk", 1)
	overwrite("mtfoods:sugar", 1)
	overwrite("mtfoods:short_bread", 4)
	overwrite("mtfoods:cream", 1)
	overwrite("mtfoods:chocolate", 2)
	overwrite("mtfoods:cupcake", 2)
	overwrite("mtfoods:strawberry_shortcake", 2)
	overwrite("mtfoods:cake", 3)
	overwrite("mtfoods:chocolate_cake", 3)
	overwrite("mtfoods:carrot_cake", 3)
	overwrite("mtfoods:pie_crust", 3)
	overwrite("mtfoods:apple_pie", 3)
	overwrite("mtfoods:rhubarb_pie", 2)
	overwrite("mtfoods:banana_pie", 3)
	overwrite("mtfoods:pumpkin_pie", 3)
	overwrite("mtfoods:cookies", 2)
	overwrite("mtfoods:mlt_burger", 5)
	overwrite("mtfoods:potato_slices", 2)
	overwrite("mtfoods:potato_chips", 3)
	--mtfoods:medicine
	overwrite("mtfoods:casserole", 3)
	overwrite("mtfoods:glass_flute", 2)
	overwrite("mtfoods:orange_juice", 2)
	overwrite("mtfoods:apple_juice", 2)
	overwrite("mtfoods:apple_cider", 2)
	overwrite("mtfoods:cider_rack", 2)
end

if minetest.get_modpath("fruit") ~= nil then
	overwrite("fruit:apple", 2)
	overwrite("fruit:pear", 2)
	overwrite("fruit:bananna", 3)
	overwrite("fruit:orange", 2)
end

if minetest.get_modpath("mush45") ~= nil then
	overwrite("mush45:meal", 4)
end

if minetest.get_modpath("seaplants") ~= nil then
	overwrite("seaplants:kelpgreen", 1)
	overwrite("seaplants:kelpbrown", 1)
	overwrite("seaplants:seagrassgreen", 1)
	overwrite("seaplants:seagrassred", 1)
	overwrite("seaplants:seasaladmix", 6)
	overwrite("seaplants:kelpgreensalad", 1)
	overwrite("seaplants:kelpbrownsalad", 1)
	overwrite("seaplants:seagrassgreensalad", 1)
	overwrite("seaplants:seagrassgreensalad", 1)
end

if minetest.get_modpath("mobfcooking") ~= nil then
	overwrite("mobfcooking:cooked_pork", 6)
	overwrite("mobfcooking:cooked_ostrich", 6)
	overwrite("mobfcooking:cooked_beef", 6)
	overwrite("mobfcooking:cooked_chicken", 6)
	overwrite("mobfcooking:cooked_lamb", 6)
	overwrite("mobfcooking:cooked_venison", 6)
	overwrite("mobfcooking:cooked_fish", 6)
end

if minetest.get_modpath("creatures") ~= nil then
	overwrite("creatures:meat", 6)
	overwrite("creatures:flesh", 3)
	overwrite("creatures:rotten_flesh", 3, "", 3)
end

Milan's avatar
Milan committed
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
if minetest.get_modpath("ethereal") then

	overwrite("ethereal:strawberry", 1)
	overwrite("ethereal:banana", 4)
	overwrite("ethereal:pine_nuts", 1)
	overwrite("ethereal:bamboo_sprout", 0, "", 3)
	overwrite("ethereal:fern_tubers", 1)
	overwrite("ethereal:banana_bread", 7)
	overwrite("ethereal:mushroom_plant", 2)
	overwrite("ethereal:coconut_slice", 2)
	overwrite("ethereal:golden_apple", 4, "", nil, 10)
	overwrite("ethereal:wild_onion_plant", 2)
	overwrite("ethereal:mushroom_soup", 5, "ethereal:bowl")
	overwrite("ethereal:hearty_stew", 10, "ethereal:bowl")

	if minetest.get_modpath("bucket") then

		overwrite("ethereal:bucket_cactus", 2, "bucket:bucket_empty")
	end

	overwrite("ethereal:fish_raw", 2)
	overwrite("ethereal:fish_cooked", 5)
	overwrite("ethereal:seaweed", 1)
	overwrite("ethereal:yellowleaves", 1, "", nil, 1)
	overwrite("ethereal:sashimi", 4)
	overwrite("ethereal:orange", 2)
end

316 317 318 319 320
if minetest.get_modpath("illuna_ethereal") then
    overwrite("illuna_ethereal:candyfloss_white")
    overwrite("illuna_ethereal:candyfloss_pink")
end

TenPlus1's avatar
TenPlus1 committed
321 322 323 324
if minetest.get_modpath("farming") and farming.mod == "redo" then
	overwrite("farming:bread", 6)
	overwrite("farming:potato", 1)
	overwrite("farming:baked_potato", 6)
325 326
    overwrite("farming:banana", 4)
    overwrite("farming:cucumber", 4)
TenPlus1's avatar
TenPlus1 committed
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
	overwrite("farming:tomato", 4)
	overwrite("farming:carrot", 3)
	overwrite("farming:carrot_gold", 6, "", nil, 8)
	overwrite("farming:corn", 3)
	overwrite("farming:corn_cob", 5)
	overwrite("farming:melon_slice", 2)
	overwrite("farming:pumpkin_slice", 1)
	overwrite("farming:pumpkin_bread", 9)
	overwrite("farming:coffee_cup", 2, "farming:drinking_cup")
	overwrite("farming:coffee_cup_hot", 3, "farming:drinking_cup", nil, 2)
	overwrite("farming:cookie", 2)
	overwrite("farming:chocolate_dark", 3)
	overwrite("farming:donut", 4)
	overwrite("farming:donut_chocolate", 6)
	overwrite("farming:donut_apple", 6)
342
    overwrite("farming:orange_item", 4)
TenPlus1's avatar
TenPlus1 committed
343 344 345 346 347 348 349 350 351
	overwrite("farming:raspberries", 1)
	overwrite("farming:blueberries", 1)
	overwrite("farming:muffin_blueberry", 4)
	if minetest.get_modpath("vessels") then
		overwrite("farming:smoothie_raspberry", 2, "vessels:drinking_glass")
	end
	overwrite("farming:rhubarb", 1)
	overwrite("farming:rhubarb_pie", 6)
	overwrite("farming:beans", 1)
TenPlus1's avatar
TenPlus1 committed
352
	overwrite("farming:grapes", 2)
TenPlus1's avatar
TenPlus1 committed
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
end

if minetest.get_modpath("kpgmobs") ~= nil then
	overwrite("kpgmobs:uley", 3)
	overwrite("kpgmobs:meat", 6)
	overwrite("kpgmobs:rat_cooked", 5)
	overwrite("kpgmobs:med_cooked", 4)
	if minetest.get_modpath("bucket") then
		overwrite("kpgmobs:bucket_milk", 4, "bucket:bucket_empty")
	end
end

if minetest.get_modpath("jkfarming") ~= nil then
	overwrite("jkfarming:carrot", 3)
	overwrite("jkfarming:corn", 3)
	overwrite("jkfarming:melon_part", 2)
	overwrite("jkfarming:cake", 3)
end

if minetest.get_modpath("jkanimals") ~= nil then
	overwrite("jkanimals:meat", 6)
end

if minetest.get_modpath("jkwine") ~= nil then
	overwrite("jkwine:grapes", 2)
	overwrite("jkwine:winebottle", 1)
end

if minetest.get_modpath("cooking") ~= nil then
	overwrite("cooking:meat_beef_cooked", 4)
	overwrite("cooking:fish_bluewhite_cooked", 3)
	overwrite("cooking:fish_clownfish_cooked", 1)
	overwrite("cooking:meat_chicken_cooked", 2)
	overwrite("cooking:meat_cooked", 2)
	overwrite("cooking:meat_pork_cooked", 3)
	overwrite("cooking:meat_toxic_cooked", -3)
	overwrite("cooking:meat_venison_cooked", 3)
	overwrite("cooking:meat_undead_cooked", 1)
end

-- ferns mod of plantlife_modpack
if minetest.get_modpath("ferns") ~= nil then
	overwrite("ferns:fiddlehead", 1, "", 1)
	overwrite("ferns:fiddlehead_roasted", 3)
	overwrite("ferns:ferntuber_roasted", 3)
	overwrite("ferns:horsetail_01", 1)
end

-- Xanadu server only
402
if minetest.get_modpath("wine") then
TenPlus1's avatar
TenPlus1 committed
403 404 405 406
	overwrite("wine:glass_wine", 2)
	overwrite("wine:glass_beer", 2)
	overwrite("wine:glass_mead", 2)
	overwrite("wine:glass_cider", 2)
407 408 409 410 411 412 413 414 415
end

if  minetest.get_modpath("mobs_sea") then
    overwrite("mobs:clownfish_raw", 2)
    overwrite("mobs:bluefish_raw", 2)
end

if minetest.get_modpath("xdecor") then
    overwrite("xdecor:bowl_soup", 20)
Milan's avatar
Milan committed
416
    overwrite("xdecor:honey", 2)
TenPlus1's avatar
TenPlus1 committed
417 418
end

419 420 421 422
if minetest.get_modpath("loud_walking") then
    overwrite("loud_walking:mushroom_steak", 5)
end

Milan's avatar
Milan committed
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
if minetest.get_modpath("mtcandy") then
    overwrite("mtcandy:sugar_block", 4)
    overwrite("mtcandy:caramel", 4)
    overwrite("mtcandy:crosscandy", 4)
    overwrite("mtcandy:candyrec_bluecyan", 4)
    overwrite("mtcandy:candyrec_magenta", 4)
    overwrite("mtcandy:candyrec_orange", 4)
    overwrite("mtcandy:candyrec_yellow", 4)
    overwrite("mtcandy:dotted_green", 4)
    overwrite("mtcandy:dotted_red", 4)
    overwrite("mtcandy:dotted_pink", 4)
    overwrite("mtcandy:dotted_orange", 4)
    overwrite("mtcandy:dotted_yellow", 4)
    overwrite("mtcandy:peppermint", 4)
    overwrite("mtcandy:peppermint_red", 4)
    overwrite("mtcandy:peppermint_cyan_top", 4)
    overwrite("mtcandy:peppermint_green_top", 4)
    overwrite("mtcandy:peppermint_orange_top", 4)
    overwrite("mtcandy:peppermint_magenta_top", 4)
    overwrite("mtcandy:peppermint_yellow_top", 4)
    overwrite("mtcandy:spiral_blue", 4)
    overwrite("mtcandy:spiral_purple", 4)
    overwrite("mtcandy:spiral_yellow", 4)
    overwrite("mtcandy:striped_pink_brown", 4)
    overwrite("mtcandy:striped_pink_white", 4)
    overwrite("mtcandy:striped_pink_yellow", 4)
    overwrite("mtcandy:striped_purple_green", 4)
    overwrite("mtcandy:milk_choco", 4)
    overwrite("mtcandy:white_choco", 4)
    overwrite("mtcandy:orange", 4)
    overwrite("mtcandy:pcorn_side", 4)
    overwrite("mtcandy:daisy", 4)
    overwrite("mtcandy:heart_candy", 4)
    overwrite("mtcandy:emenems", 4)
end

TenPlus1's avatar
TenPlus1 committed
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
-- player-action based hunger changes
function hbhunger.handle_node_actions(pos, oldnode, player, ext)
	if not player or not player:is_player() then
		return
	end
	local name = player:get_player_name()
	local exhaus = hbhunger.exhaustion[name]
	if exhaus == nil then return end
	local new = HUNGER_EXHAUST_PLACE
	-- placenode event
	if not ext then
		new = HUNGER_EXHAUST_DIG
	end
	-- assume its send by main timer when movement detected
	if not pos and not oldnode then
		new = HUNGER_EXHAUST_MOVE
	end
	exhaus = exhaus + new
	if exhaus > HUNGER_EXHAUST_LVL then
		exhaus = 0
		local h = tonumber(hbhunger.hunger[name])
		h = h - 1
		if h < 0 then h = 0 end
		hbhunger.hunger[name] = h
		hbhunger.set_hunger(player)
	end
	hbhunger.exhaustion[name] = exhaus
end

TenPlus1's avatar
TenPlus1 committed
488
--minetest.register_on_placenode(hbhunger.handle_node_actions)
TenPlus1's avatar
TenPlus1 committed
489
minetest.register_on_dignode(hbhunger.handle_node_actions)