Page 1 of 5

[Mod] Hunger with HUD bar [1.1.4] [hbhunger]

Posted: Fri Feb 27, 2015 06:47
by Wuzzy
This mod adds a simple hunger mechanic (plus HUD bar) to the game.
Eat food to avoid starvation, be sated to regenerate health.

Screenshot of the HUD bar:
Image

The mod introduces satiation and food poisoning and changes how healing and eating works.

Satiation and healing: Each player has a new attribute called “satiation”. This attribute is represented by a brown HUD bar. Quick overview:
  • Satiation is a whole number between 0 and 30
  • New players start with a satiation of 20
  • Health increases at a satiation of 16 or higher
  • Health decreases at a satiation of 1 or lower
  • Mining, building and movement will slowly decrease satiation
  • Players lose 1 satiation point every 800 seconds no matter what
Eating: Players have to eat food such as apples to restore satiation. Food will no longer directly restore one's health!
In other words, the hunger mechanic works exactly like in the “Better HUD” mod from BlockMen. Note that in BlockMen's mod, satiation can go up to 30, too. But satiation levels 20-30 are always displayed as 10 bread symbols. This mod, however, always shows the actual satiation.
Food poisoning: Very simple. When you eat poisoned food like a red mushroom, you lose health points for a few seconds (but your health can never go below 1 with food poisoning).



This mod is a fork of the “Better HUD” [hud] mod by BlockMen version 1.4.0, but made to work to use the HUD bars mod instead, and all features not needed for the hunger mechanic stripped off.
It has been updated to support the same foods as of version 2.x.1 of said mod.

Download: https://codeberg.org/Wuzzy/minetest_hbh ... /1.1.4.zip
Supported food:
All food items which use the standard minetest.item_eat function are automatically supported.
Spoiler
- Apple, Blueberries [default]
- Red and brown mushroom [flowers]
- Bread [farming]

- [animalmaterials] (Mob Framework (mobf modpack))
- Bushes [bushes]
- [bushes_classic]
- Creatures [creatures]
- [dwarves] (beer and such)
- Docfarming [docfarming]
- Ethereal [ethereal]
- Farming [farming] from Minetest Game
- Farming Redo [farming] by TenPlus1
- Farming plus [farming_plus]
- Ferns [ferns]
- Fishing [fishing]
- [fruit]
- Glooptest [glooptest]
- JKMod ([jkanimals], [jkfarming], [jkwine])
- [kpgmobs]
- [mobfcooking]
- [mooretrees]
- [mtfoods]
- [mushroom]
- [mush45]
- Seaplants [sea]
- Simple mobs [mobs]
- Pizza [pizza]
- Not so simple mobs [nssm]

Supported mods without optional dependency (mods provide their own support):
- Food [food]
- Sweet Foods [food_sweet]


This mod is incompatible with:

Re: [Mod] Hunger with HUD bar [0.1.0] [hbhunger]

Posted: Fri Feb 27, 2015 08:45
by rubenwardy
Why "saturation"?

Also the namespace should be "hphunger" no "hunger" in your mod (ie: the global table)

Re: [Mod] Hunger with HUD bar [0.1.0] [hbhunger]

Posted: Fri Feb 27, 2015 09:51
by Wuzzy
rubenwardy wrote:Why "saturation"?
What's wrong with that word? Anyways, I am not a native English speaker, so please forgive me if it's wrong.
Also, the word comes from the “Better HUD” mod, where the readme tells something about “saturation points”.

I need a word for “how ‘full’ you are”, as in “negation of hunger”. A full bar means the player character is “full”, an empty bar means the player character is starving.

From looking into a dictionary, I narrowed possible words down to these:
  • saturation
  • satiety
  • satiation
  • repletion
Could some native English speaker tell me which word I should use?
Also the namespace should be "hphunger" no "hunger" in your mod (ie: the global table)
Probably I just make the main table local, there is no API, so there is actually no good reason to put anything into global space.

Re: [Mod] Hunger with HUD bar [0.1.0] [hbhunger]

Posted: Fri Feb 27, 2015 10:02
by TenPlus1
Nice mod but the hunger.lua code you are using from BetterHUD mod is out of date and has had many bug fixes and improvements since the version you are using... Could you update...

Re: [Mod] Hunger with HUD bar [0.1.0] [hbhunger]

Posted: Fri Feb 27, 2015 10:21
by Wuzzy
@TenPlus1:
diff of hunger.lua, hud vs hbhunger wrote: 2,3c2,3
< function hbhunger.save_hunger(player)
< hbhunger.set_hunger(player)
---
> function hud.save_hunger(player)
> hud.set_hunger(player)
5,6c5,6
< function hbhunger.load_hunger(player)
< hbhunger.get_hunger(player)
---
> function hud.load_hunger(player)
> hud.get_hunger(player)
23c23
< function hbhunger.item_eat(hunger_change, replace_with_item, poisen, heal)
---
> function hud.item_eat(hunger_change, replace_with_item, poisen, heal)
27c27
< local h = tonumber(hbhunger.hunger[name])
---
> local h = tonumber(hud.hunger[name])
34,35c34,35
< hbhunger.hunger[name] = h
< hbhunger.set_hunger(user)
---
> hud.hunger[name] = h
> hud.set_hunger(user)
59c59
< tab.on_use = hbhunger.item_eat(hunger_change, replace_with_item, poisen, heal)
---
> tab.on_use = hud.item_eat(hunger_change, replace_with_item, poisen, heal)
63,65c63
< if minetest.get_modpath("default") ~= nil then
< overwrite("default:apple", 2)
< end
---
> overwrite("default:apple", 2)
366c364
< function hbhunger.handle_node_actions(pos, oldnode, player, ext)
---
> function hud.handle_node_actions(pos, oldnode, player, ext)
371,372c369,370
< local exhaus = hbhunger.exhaustion[name]
< local new = HUNGER_EXHAUST_PLACE
---
> local exhaus = hud.exhaustion[name]
> local new = HUD_HUNGER_EXHAUST_PLACE
375c373
< new = HUNGER_EXHAUST_DIG
---
> new = HUD_HUNGER_EXHAUST_DIG
379c377
< new = HUNGER_EXHAUST_MOVE
---
> new = HUD_HUNGER_EXHAUST_MOVE
382c380
< if exhaus > HUNGER_EXHAUST_LVL then
---
> if exhaus > HUD_HUNGER_EXHAUST_LVL then
384c382
< local h = tonumber(hbhunger.hunger[name])
---
> local h = tonumber(hud.hunger[name])
387,388c385,386
< hbhunger.hunger[name] = h
< hbhunger.set_hunger(player)
---
> hud.hunger[name] = h
> hud.set_hunger(player)
390c388
< hbhunger.exhaustion[name] = exhaus
---
> hud.exhaustion[name] = exhaus
393,394c391,392
< minetest.register_on_placenode(hbhunger.handle_node_actions)
< minetest.register_on_dignode(hbhunger.handle_node_actions)
---
> minetest.register_on_placenode(hud.handle_node_actions)
> minetest.register_on_dignode(hud.handle_node_actions)
I don't know what you're talking about.

Re: [Mod] Hunger with HUD bar [0.1.0] [hbhunger]

Posted: Fri Feb 27, 2015 10:44
by rubenwardy
Hunger is used quite a lot in video games inversely, lower bars is more hungry. But meh.

It is an API, my food mod supports you using hunger.item_eat(). I don't want to make a pull request everytime I add a food.

You should use minetest.register_on_item_eat, anyway. It is what it is meant for.

Re: [Mod] Hunger with HUD bar [0.1.0] [hbhunger]

Posted: Fri Feb 27, 2015 11:05
by TenPlus1
The following is the latest functions which stop players over-eating when saturation or health is full and returns bowls/buckets from a food stack without replacing the whole stack:

Code: Select all

-- Keep these for backwards compatibility
function hud.save_hunger(player)
	hud.set_hunger(player)
end
function hud.load_hunger(player)
	hud.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)
	end
	if player:get_hp()-1 > 0 then
		player:set_hp(player:get_hp()-1)
	end
	
end

function hud.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(hud.hunger[name])
			local hp = user:get_hp()
			local rm = false
			local msg = nil

			-- Healing
			if hp < 20 and heal then
				hp = hp + heal
				if hp > 20 then hp = 20 end
				user:set_hp(hp)
				rm = true
				msg = ""
			elseif hp == 20 and heal then
				msg = "You already have full health"
			end

			-- Hunger
			if h < 30 and hunger_change then
				h = h + hunger_change
				if h > 30 then h = 30 end
				hud.hunger[name]=h
				hud.set_hunger(user)
				rm = true
			elseif h>= 30 and hunger_change and not msg then
				msg = "Cannot eat, not hungry"
			end
			
			if msg then minetest.chat_send_player(user:get_player_name(), msg) end
			
			-- Poison
			if poisen then
				poisenp(1.0, poisen, 0, user)
			end

--			minetest.sound_play("chomp", {pos=pos, gain = 1.0, max_hear_distance = 2,})

			-- if item eaten and replace_with_item, check if inventory full, add/drop replacement
			if rm then
				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

				return itemstack
			end
			
		end
	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 = hud.item_eat(hunger_change, replace_with_item, poisen, heal)
	minetest.registered_items[name] = tab
end

Re: [Mod] Hunger with HUD bar [0.1.0] [hbhunger]

Posted: Fri Feb 27, 2015 11:18
by Wuzzy
@rubenwardy: Whoops, indeed there is that function. I have renamed the table to hbhunger then.

Yeah, this is still a fresh fork from 1.4.0 from Better HUD (now updated to 1.4.1), so I don't know my “own” mod very well. :D

Basically I wanted to completely bissect the Better HUD mod, I guess I have achieved this goal for now. So I have not made much work on the actual gameplay mechanics or architecture. It seems this must be reworked.

As for minetest.register_on_item_eat: Good idea, but is it a good idea to transform the value which was intended for health initially into a “saturation” value? Would I get sane results; wouldn't some manual balancing/tweaking be needed at least?

@TenPlus1: Now this code is indeed different from my code. Where did you get that code? For me, the most recent version of Better HUD [hud] is 1.4.1, and according to GitHub, there have been 0 updates since then on the master branch. https://github.com/BlockMen/hud
Please give me the URL of the repository from which you got that code, so I can merge.
stop players over-eating when saturation or health is full
When I think about it, maybe I don't want to merge this. This sucks. When I have full health, there is still reason to eat to fill up the saturation bar.

Re: [Mod] Hunger with HUD bar [0.1.0] [hbhunger]

Posted: Tue Mar 03, 2015 02:08
by SpaghettiToastBook
Wuzzy wrote:
rubenwardy wrote:Why "saturation"?
What's wrong with that word? Anyways, I am not a native English speaker, so please forgive me if it's wrong.
Also, the word comes from the “Better HUD” mod, where the readme tells something about “saturation points”.

I need a word for “how ‘full’ you are”, as in “negation of hunger”. A full bar means the player character is “full”, an empty bar means the player character is starving.

From looking into a dictionary, I narrowed possible words down to these:
  • saturation
  • satiety
  • satiation
  • repletion
Could some native English speaker tell me which word I should use?
I think the word you should use is definitely "satiation". The other three don't have quite the right meaning.

Release: 0.2.0

Posted: Tue Mar 03, 2015 02:33
by Wuzzy
OK, here's release 0.2.0.

Changelog:
  • Change “saturation” to “satiation” throughout the mod
  • Rename global table to “hbhunger” to avoid possible naming collisions
  • General cleanup

Re: [Mod] Hunger with HUD bar [0.2.0] [hbhunger]

Posted: Wed Mar 04, 2015 19:35
by mahmutelmas06
How about to trigger eating sound when punched with food ?

Re: [Mod] Hunger with HUD bar [0.2.0] [hbhunger]

Posted: Sun Mar 08, 2015 03:25
by SpaghettiToastBook
Could you support food_sweet?

Re: [Mod] Hunger with HUD bar [0.2.0] [hbhunger]

Posted: Sun Mar 08, 2015 08:27
by rubenwardy
Food sweet should automatically support it if you have the latest version of food.

Edit: actually, I did a typo so it doesn't. I'll fix that.

Release 0.3.0

Posted: Sun Mar 08, 2015 09:12
by Wuzzy
mahmutelmas06 wrote:How about to trigger eating sound when punched with food ?
Done in version 0.3.0, which I have just released.

It's a simple sound but I think it gets the job done.

Re: [Mod] Hunger with HUD bar [0.3.0] [hbhunger]

Posted: Sun Mar 08, 2015 15:46
by mahmutelmas06
Good job, thanks

Re: [Mod] Hunger with HUD bar [0.3.0] [hbhunger]

Posted: Mon Mar 09, 2015 11:58
by mahmutelmas06
I have edited some to get sound only if you are hungry.

Delete

Code: Select all

			minetest.sound_play({name = "hbhunger_eat_generic", gain = 1}, {pos=user:getpos(), max_hear_distance = 16})


Replace

Code: Select all

			--sound:eat
            if h < 30 and hunger_change then
			minetest.sound_play({name = "hbhunger_eat_generic", gain = 1}, {pos=user:getpos(), max_hear_distance = 16})
			itemstack:add_item(replace_with_item)
		   end   

Re: [Mod] Hunger with HUD bar [0.3.0] [hbhunger]

Posted: Mon Apr 06, 2015 16:56
by H4Mm3r
Hello,

Really love this mod, thanks !

Just have a little problem, nothing is happening when eating ethereal food, is it a known issue ?
2015-04-06 18:54:23: ACTION[ServerThread]: H4Mm3r uses farming:rhubarb, pointing at [node under=-163,2,-336 above=-163,3,-336]
=> Satiation UP
2015-04-06 18:55:00: ACTION[ServerThread]: H4Mm3r uses ethereal:orange, pointing at [nothing]
=> Nothing

H4Mm3r

Re: [Mod] Hunger with HUD bar [0.3.0] [hbhunger]

Posted: Mon Apr 06, 2015 17:56
by TenPlus1
It seems that their is a missing line in hunger.lua for ethereal orange:

overwrite("ethereal:orange", 4)

Re: [Mod] Hunger with HUD bar [0.3.0] [hbhunger]

Posted: Mon Apr 06, 2015 18:05
by H4Mm3r
TenPlus1 wrote:It seems that their is a missing line in hunger.lua for ethereal orange:

overwrite("ethereal:orange", 4)
Oh yes ! Added this line (but with "2" hunger change, like other mod's oranges). Will apply it if some other fruits are missing.

Thanks a lot !!!

H4Mm3r

Re: [Mod] Hunger with HUD bar [0.3.0] [hbhunger]

Posted: Sun Jun 28, 2015 11:35
by Minetestforfun
Maybe this bugfix will interrest you ?
https://github.com/Ombridride/minetest- ... 5918da9aa3

Bugfix updates

Posted: Sun Jun 28, 2015 12:35
by Wuzzy
I have applied both bug fixes now, see in version 0.3.1.

Edit: There was another crash bug, should be fixed in version 0.3.2. Thanks to Ombridride.

GitHub?

Posted: Fri Jul 31, 2015 21:32
by Sane
Could you please put this mod up on GitHub?
Please, pretty please?
And also the hudbars?
Uhm ... well and while you are at it the hbarmor too?

Re: [Mod] Hunger with HUD bar [0.3.2] [hbhunger]

Posted: Sat Aug 01, 2015 11:49
by Wuzzy
No. I prefer to use repo.or.cz instead of GitHub.
But I have just uploaded the Git repositories of hbhunger and hbarmor to repo.or.cz. The HUD Bars mod repository was already uploaded on repo.or.cz.

If you really insist on having the repositories on GitHub instead, you have to do it yourselves. I'm pretty sure you can easily import existing repositories. I don't know whether they allow mirroring. On the other hand, I don't think the repository provider should actually matter that much as long as the repository is online.

Re: [Mod] Hunger with HUD bar [0.3.2] [hbhunger]

Posted: Sat Aug 01, 2015 13:48
by Sane
Wuzzy wrote:No. I prefer to use repo.or.cz instead of GitHub.
But I have just uploaded the Git repositories of hbhunger and hbarmor to repo.or.cz. The HUD Bars mod repository was already uploaded on repo.or.cz.
Thanks.
Wuzzy wrote:If you really insist on having the repositories on GitHub instead, ...
Nah, it was not about GitHub. Just wanted the mods as a git repository. repo.or.cz is fine (althoug it's design seems to be from the last melenium).
---

Great mods these hud bars!
What i like about the bars is their floating point approach, also I think the optics look better than BlockMan's bars.
hbhunger because it does not hide saturation. All 30 points are shown.
Thank you.

Re: [Mod] Hunger with HUD bar [0.3.2] [hbhunger]

Posted: Sat Aug 01, 2015 20:02
by Minetestforfun
Hi,

Many bugfiws in your mod recently https://github.com/MinetestForFun/minet ... s/hbhunger

Feel free to take it :)