[Mod] Hunger NG: A next generation hunger mod (hunger_ng)

User avatar
Linuxdirk
Member
Posts: 3216
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

[Mod] Hunger NG: A next generation hunger mod (hunger_ng)

by Linuxdirk » Post

Abstract

Hunger NG is a mod for Minetest adding a very customizable and easy to extend hunger system.

The mod adds a hunger bar at the position of the breath bar and hides the bar if the breath bar becomes visible so the most important bar is shown without cluttering the UI too much.

Image

Hunger NG works in singleplayer mode as well as on a multiplayer server. It automatically disables itself when damage is disabled and adapts to the used texture pack.

Rationale

“Why yet another hunger mod? Is it a fork?” – No, Hunger NG was written from scratch in code and concept, is not a fork, and is completely self-contained.

The main difference from most (if not all) hunger mods is that hunger points get subtracted directly from the hunger value instead of being calculated to some sort of exhaustion value that’s being used to reduce the hunger. This gives more detailed control over how many hunger a specific action will cause.

Additionally all of the hunger-related information is stored as player meta data or custom item attributes. There are no global tables polluting the mod namespace or held in the mod’s local chunk. It’s all nice and clean stored in players and items.

Hunger NG allows detailed configuration of all aspects of the hunger manipulation. An exhaustive section on that is available in the mod’s README.md file (see GitLab link). There is a chat command that allows setting the hunger for any named player when having the server privilege.

Mod compatibility

By default the hunger bar is in the same position as the breath bar (the bubbles that appear when a player is awash) and disappears if the breath bar becomes visible. Any mod changing the position of the breath bar needs to change the position of the hunger bar as well (the ID is stored as player meta data, too).

Mods that alter or replace food with own versions ignoring custom item attributes will render them unusable for Hunger NG resulting in not being processed by Hunger NG but handled regularly.

Hunger NG is compatible with various mods. Click here for a full list.

Please note that only the current latest official release of Minetest is supported. Other versions than the latest official release of Minetest might work – or might not work. If you encounter issues with older versions of Minetest, or with developer versions of those: please try again with the current non-dev versions.

Obtaining the mod

GitLab: Browse the source, Download latest version, Content DB
Documentation click here for the online documentation
License: GPL Version 3 for source, various for sounds
Dependencies: none
Language Support: English (default), Italian, Spanish, German
Last edited by Linuxdirk on Tue Sep 14, 2021 07:52, edited 16 times in total.

User avatar
Joseph16
Member
Posts: 310
Joined: Tue Dec 06, 2016 05:35
In-game: smb3

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by Joseph16 » Post

wow finally a new hunger mod!
Testin' mines since 1989

User avatar
Linuxdirk
Member
Posts: 3216
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by Linuxdirk » Post

Joseph13 wrote:wow finally a new hunger mod!
And it also has a different concept than all of the other hunger mods :)

Plus: I'm currently redesigning the chat command and will do some balancing tests during the weekend.

User avatar
Stix
Member
Posts: 1385
Joined: Fri Aug 04, 2017 14:19
IRC: nil
In-game: Stix [+alts]
Location: USA

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by Stix » Post

i love how this doesn't take up more space over your hot-bar.
Hey, what can i say? I'm the bad guy.

User avatar
rubenwardy
Moderator
Posts: 6969
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by rubenwardy » Post

Nice! It's good to see a maintained hunger mod which uses player attributes and not a table or inventory stack hacks

BTW: you can use register_on_item_eat to support any food. That's the reason that callback was added. Return true to cancel the default behaviour. You could also override minetest.do_item_eat if you don't want any conflict with callbacks (but you'd need to call callbacks yourself, if you wish)
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
Linuxdirk
Member
Posts: 3216
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by Linuxdirk » Post

rubenwardy wrote:Nice! It's good to see a maintained hunger mod which uses player attributes and not a table or inventory stack hacks
Thanks :) That was the reason I created it.
rubenwardy wrote:BTW: you can use register_on_item_eat to support any food.
I already use this register like so. The only thing that is not done using a “generic” satiation value but specific ones (that will be tweaked over time) mod authors could add to their own foods either by depending on hunger_ng and using the global function after they registered their food or by manually adding the custom item attribute table as described for the function.

User avatar
rubenwardy
Moderator
Posts: 6969
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by rubenwardy » Post

Is there any reason why you didn't decide to guess the correct satiation value for unknown foods? It's better to have an inaccurate value than not support it at all, imo
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

Chem871
Member
Posts: 999
Joined: Sat Aug 19, 2017 21:49
GitHub: Chemguy99
In-game: Chem Nyx
Location: My Basement's Attic

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by Chem871 » Post

I didn't know that some foods were sanitary, good to know.
What is SCP-055?

User avatar
Linuxdirk
Member
Posts: 3216
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by Linuxdirk » Post

rubenwardy wrote:Is there any reason why you didn't decide to guess the correct satiation value for unknown foods?
Due to concept. Foods need a custom attribute being a table containing the satiation/heal values. So I either need to weaken the concept or opt-depend on everything and iterate over all items trying to detect if they are food and add the custom attribute to them.
rubenwardy wrote:It's better to have an inaccurate value than not support it at all, imo
Unsupported foods work like the mod authors want them to work. So foods that are not supported by (Or do not support - both is possible, the later even without opt-depending!) Hunger NG are not affected at all.

If you think anything is missing (most recent version when posting this message) feel free to suggest adding it or contact the mod's author to add the necessary attribute (this is preferred, the interoperability section should be seen as temporary only).
Chem871 wrote:I didn't know that some foods were sanitary, good to know.
Some very substantial foods give you some health points, yes. Foods that should not be eaten raw (or are otherwise not the best you can eat) will damage you a little like raw chicken or the red mushroom.
Last edited by Linuxdirk on Tue Jun 05, 2018 17:54, edited 1 time in total.

User avatar
Linuxdirk
Member
Posts: 3216
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by Linuxdirk » Post

Did some balancing.
  • Players can walk for a whole accumulated ingame day before their hunger is at 0
  • Placing nodes costs 1 hunger point for 100 nodes (0.01 per node)
  • Digging nodes costs 1 hunger point for 200 nodes (0.005 per node)
  • The basal metabolism takes roughly 10 ingame days to use up the maximum hunger value
  • Starvation results in 1 health point removed every 20 seconds
  • Healing adds 1 health point every 5 seconds
All the values are configurable of course.

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by texmex » Post

Support for this mod added in hbSprint; it now drains satiation 1 unit ("half a bread") per second of sprinting by default.

User avatar
Linuxdirk
Member
Posts: 3216
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by Linuxdirk » Post

Great :) I updated the readme and first post.

User avatar
rubenwardy
Moderator
Posts: 6969
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by rubenwardy » Post

Linuxdirk wrote:opt-depend on everything and iterate over all items trying to detect if they are food and add the custom attribute to them.
You can use minetest.register_on_item_eat, as said. It's better to have a wrongly weighted food item than one that doesn't work consistently as a food
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
Lone_Wolf
Member
Posts: 2575
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: LandarVargan
In-game: LandarVargan

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by Lone_Wolf » Post

THis looks great! Been searching for a hunger mod like this...
My ContentDB -|- Working on CaptureTheFlag -|- Minetest Forums Dark Theme!! (You need it)

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by texmex » Post

Linuxdirk wrote:hbSprint optionally support Hunger NG by setting the raw hunger value on sprinting.
I couldn't get hunger_ng.alter_hunger to work so I just went with your initial recommendation. :)

User avatar
Linuxdirk
Member
Posts: 3216
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by Linuxdirk » Post

texmex wrote:I couldn't get hunger_ng.alter_hunger to work so I just went with your initial recommendation. :)
Why?

You basically just pass the player name (a string that is the name, not the object) and a number value (the hunger change either positive or negative float or int) to the function.

Are there error messages?

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by texmex » Post

Linuxdirk wrote:Why?

You basically just pass the player name (a string that is the name, not the object) and a number value (the hunger change either positive or negative float or int) to the function.

Are there error messages?
I must admit I didn't look into it that deep, circumventing the problem was faster. >:)

User avatar
Linuxdirk
Member
Posts: 3216
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by Linuxdirk » Post

texmex wrote:I must admit I didn't look into it that deep, circumventing the problem was faster. >:)
Actually I just made a copy&paste error and the bug is now fixed. The function now works as documented. (Adn there is a function to get the hunger now, too. In case you still need the value itself – same commit)


And completely unrelated: Item returns basing on additional definition are now fully supported.

https://gitlab.com/4w/hunger_ng/blob/ma ... unger-data

User avatar
Linuxdirk
Member
Posts: 3216
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by Linuxdirk » Post

Hunger NG now has properly working chat commands.

When having the custom manage_hunger privilege set (or, of course, having the server privilege, as usual) players can view and change all hunger values including their own. This is useful if you want admins having this power for their administrative work but do not want to give them the server privilege.

Code: Select all

/hunger set Foobar 10
/hunger set 7.5
/hunger change -10
/hunger change Foobar 15
/hunger get
/hunger get Foobar
The first example sets the hunger value of player “Foobar” to 10 (5 breads). The second example sets the own hunger value to 7.5 (ceiled 8, so this looks like 4 breads). The third example reduces the own hunger value by 10, the fourth example raises Foobar’s hunger value by 15.

The second command is /myhunger without any parameters. This parameter simply returns the current hunger value to the player invoking this command. The interact privilege is needed for that. Since this is THE basic privilege, players actually playing on the server have it.

The execution of both commands is properly logged. Examples:

Code: Select all

2018-10-24 22:59:05: ACTION[Server]: [hunger_ng] Foobar sets own hunger to 20
2018-10-24 22:58:57: ACTION[Server]: [hunger_ng] Foobar gets own hunger value
2018-10-24 23:01:45: ACTION[Server]: [hunger_ng] Foobar changes hunger for Blergh by -5
1: /hunger set 20
2: /myhunger
3: /hunger set Blergh -5

Just get the latest version from GitLab and restart your server.

User avatar
LMD
Member
Posts: 1385
Joined: Sat Apr 08, 2017 08:16
GitHub: appgurueu
IRC: appguru[eu]
In-game: LMD
Location: Germany
Contact:

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by LMD » Post

Actually, a great idea to always switch between breath and hunger.
I was inspired by this design concept so I made this :
Image

It works similar to yours but with a regen bar(which actually got nothing to do with eating).
Also, it uses (a modified version of) hudbars.
Attachments
hiding_regen.gif
hiding_regen.gif (15.14 KiB) Viewed 3162 times
My stuff: Projects - Mods - Website

User avatar
Linuxdirk
Member
Posts: 3216
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by Linuxdirk » Post

A small update was just released.

Modders can control Hunger NG provided hunger management by setting the custom player attribute hunger_ng:hunger_disabled to a true value (1, "true", etc.) to disable it and to a falsy value like `false` to enable it. In a future release the might be an API call and a chat command for that but right now there are no plans for that. It is just there so you can use it :)

In addition to that hunger is now also disabled when a player does not have the interact privilege (most servers to not grant them automatically when joining the server so players might starve without the chance to obtain edible stuff).

Online documentation was updated accordingly. Just get the latest version on GitLab. Content DB will get the new release soon.

User avatar
Linuxdirk
Member
Posts: 3216
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by Linuxdirk » Post

Since Minetest 5.0.0 will be released soon™ the default Hunger NG now is for 5.0.0 only. See link to the tagged source if you need a version compatible with 0.4.17 versions. No backports of newer functionality will be made.

I adapted the code to the 5.0.0 API changes based on the available pre-release version and I white-box tested the functionality. All tests were successful in my testing environment. Old hunger values and timestamps are ignored. Everyone starts with fresh values.

I try to keep breakage as low as possible. If you already upgraded to the latest Git version but still use 0.4.17 simply check out the tag I created.

Code: Select all

git checkout v0.4.17-latest
To get back to the must current version when you upgraded your Minetest simply check out master.

Code: Select all

git checkout master
Properly flagged versions will hit the CDB very soon. Feel free to report issues on GitLab (link in first post). Make sure to use the latest version of the mod and any Minetest 5.0.0 version and not being on the tagged version of the mod’s code when reporting bugs or using older Minetest versions.

User avatar
Lone_Wolf
Member
Posts: 2575
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: LandarVargan
In-game: LandarVargan

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by Lone_Wolf » Post

Linuxdirk wrote:Since Minetest 5.0.0 will be released soon™ the default Hunger NG now is for 5.0.0 only. See link to the tagged source if you need a version compatible with 0.4.17 versions. No backports of newer functionality will be made.

I adapted the code to the 5.0.0 API changes based on the available pre-release version and I white-box tested the functionality. All tests were successful in my testing environment. Old hunger values and timestamps are ignored. Everyone starts with fresh values.

I try to keep breakage as low as possible. If you already upgraded to the latest Git version but still use 0.4.17 simply check out the tag I created.

Code: Select all

git checkout v0.4.17-latest
To get back to the must current version when you upgraded your Minetest simply check out master.

Code: Select all

git checkout master
Properly flagged versions will hit the CDB very soon. Feel free to report issues on GitLab (link in first post). Make sure to use the latest version of the mod and any Minetest 5.0.0 version and not being on the tagged version of the mod’s code when reporting bugs or using older Minetest versions.
Awesome. I've been using this mod in my 5.0 singleplayer world
My ContentDB -|- Working on CaptureTheFlag -|- Minetest Forums Dark Theme!! (You need it)

User avatar
Linuxdirk
Member
Posts: 3216
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by Linuxdirk » Post

Lone_Wolf wrote:Awesome. I've been using this mod in my 5.0 singleplayer world
Glad you like it. I hope everything still works (mushrooms seem not to be edible right now, I"ll check that later).

Just translated the hunger data info on items and the chat command returns. Log messages remain English for easier support.

Will do some more work tomorrow and maybe during the weekend. There’s a lot of stuff that should be reworked and optimized.

User avatar
runs
Member
Posts: 3225
Joined: Sat Oct 27, 2018 08:32

Re: [Mod] Hunger NG: A next generation hunger mod (hunger_ng

by runs » Post

I get an error for the cause of hudbars. How to configure do?

Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 14 guests