minetest-mods / stamina

Adds hunger (stamina) to minetest.
17 stars 18 forks source link

Created an API #26

Closed fluxionary closed 5 years ago

fluxionary commented 5 years ago

I've created an API for stamina.

The motivation for doing this was to allow other mods to affect how stamina is drained - in particular, the special armor additions for the terumet mod (see https://github.com/Terumoc/terumet/issues/31).

See the API.txt file for info on how to use it.

I've also included the other 2 pending PRs (#19 #25), as this PR changed most individual lines of code.

Additionally, this PR creates proper settings for the various parameters, so that a server admin can tweak these without editing source files.

fluxionary commented 5 years ago

Is there anything more this PR is waiting on? I'm currently happy with how it behaves. We've been using this branch on the Blocky Survival server for the last week without issue.

SmallJoker commented 5 years ago
2019-07-30 19:55:58: WARNING[Server]: Deprecated call to get_attribute, use MetaDataRef methods instead. (at /data/Minetest/run/bin/../mods/stamina/init.lua:483)
2019-07-30 19:55:58: WARNING[Server]: Deprecated call to set_attribute, use MetaDataRef methods instead. (at /data/Minetest/run/bin/../mods/stamina/init.lua:495)
2019-07-30 19:55:58: WARNING[Server]: Deprecated call to get_attribute, use MetaDataRef methods instead. (at /data/Minetest/run/bin/../mods/stamina/init.lua:495)
2019-07-30 19:55:58: WARNING[Server]: Deprecated call to set_attribute, use MetaDataRef methods instead. (at ...Minetest/run/bin/../builtin/profiler/instrumentation.lua:106)
2019-07-30 19:55:58: WARNING[Server]: Deprecated call to get_attribute, use MetaDataRef methods instead. (at /data/Minetest/run/bin/../mods/stamina/init.lua:498)
2019-07-30 19:55:58: WARNING[Server]: Deprecated call to set_attribute, use MetaDataRef methods instead. (at /data/Minetest/run/bin/../mods/stamina/init.lua:498)
2019-07-30 19:55:59: WARNING[Server]: Call to deprecated function 'getpos', please use 'get_pos' at /data/Minetest/run/bin/../mods/wield3d/init.lua:19
2019-07-30 19:55:59: WARNING[Server]: Deprecated call to get_attribute, use MetaDataRef methods instead. (at /data/Minetest/run/bin/../mods/stamina/init.lua:355)
2019-07-30 19:55:59: WARNING[Server]: Deprecated call to get_attribute, use MetaDataRef methods instead. (at /data/Minetest/run/bin/../mods/stamina/init.lua:363)
2019-07-30 19:55:59: WARNING[Server]: Deprecated call to get_attribute, use MetaDataRef methods instead. (at /data/Minetest/run/bin/../mods/stamina/init.lua:216)
2019-07-30 19:55:59: WARNING[Server]: Deprecated call to get_attribute, use MetaDataRef methods instead. (at /data/Minetest/run/bin/../mods/stamina/init.lua:122)
2019-07-30 19:55:59: WARNING[Server]: Deprecated call to get_attribute, use MetaDataRef methods instead. (at /data/Minetest/run/bin/../mods/stamina/init.lua:104)
...

Breaks compatibility to 0.4.16-0.4.17.1, though.

EDIT: Tested the PR in gameplay and it works well. Approval soon.

fluxionary commented 5 years ago

2019-07-30 19:55:59: WARNING[Server]: Deprecated call to get_attribute, use MetaDataRef methods instead. (at /data/Minetest/run/bin/../mods/stamina/init.lua:104)

Hm. After looking at this a little, my understanding is that get_attribute and set_attribute are deprecated in 5.1+, but the new API (get_meta()) is incompatible with 0.4.* I could do a version check and abstract these calls to use the appropriate API now, or that can be future work.

SmallJoker commented 5 years ago

If you intend to keep 0.4.x compatibility for now it's fine to use the code as-is. It can still be changed to a later time.

ahkok commented 5 years ago

Go ahead.