Page 1 of 4

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

Posted: Sat Feb 17, 2018 01:33
by Linuxdirk

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

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

Posted: Wed Feb 21, 2018 20:04
by Joseph16
wow finally a new hunger mod!

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

Posted: Thu Feb 22, 2018 06:24
by Linuxdirk
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.

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

Posted: Thu Feb 22, 2018 16:23
by Stix
i love how this doesn't take up more space over your hot-bar.

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

Posted: Thu Feb 22, 2018 17:16
by rubenwardy
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)

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

Posted: Thu Feb 22, 2018 17:53
by Linuxdirk
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.

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

Posted: Thu Feb 22, 2018 18:02
by rubenwardy
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

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

Posted: Thu Feb 22, 2018 19:26
by Chem871
I didn't know that some foods were sanitary, good to know.

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

Posted: Fri Feb 23, 2018 06:12
by Linuxdirk
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.

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

Posted: Sat Feb 24, 2018 14:18
by Linuxdirk
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.

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

Posted: Sun Feb 25, 2018 21:40
by texmex
Support for this mod added in hbSprint; it now drains satiation 1 unit ("half a bread") per second of sprinting by default.

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

Posted: Sun Feb 25, 2018 22:23
by Linuxdirk
Great :) I updated the readme and first post.

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

Posted: Sun Feb 25, 2018 22:35
by rubenwardy
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

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

Posted: Mon Feb 26, 2018 01:21
by Lone_Wolf
THis looks great! Been searching for a hunger mod like this...

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

Posted: Mon Feb 26, 2018 11:25
by texmex
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. :)

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

Posted: Mon Feb 26, 2018 17:47
by Linuxdirk
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?

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

Posted: Mon Feb 26, 2018 20:34
by texmex
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. >:)

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

Posted: Wed Apr 04, 2018 17:21
by Linuxdirk
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

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

Posted: Wed Oct 24, 2018 21:05
by Linuxdirk
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.

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

Posted: Thu Nov 01, 2018 18:10
by LMD
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.

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

Posted: Sat Nov 24, 2018 23:11
by Linuxdirk
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.

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

Posted: Wed Feb 06, 2019 20:39
by Linuxdirk
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.

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

Posted: Wed Feb 06, 2019 20:59
by Lone_Wolf
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

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

Posted: Wed Feb 06, 2019 22:07
by Linuxdirk
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.

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

Posted: Thu Feb 07, 2019 23:11
by runs
I get an error for the cause of hudbars. How to configure do?