[Mod] Player Physics API [1.1.0] [playerphysics]

Post Reply
User avatar
Wuzzy
Member
Posts: 4786
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

[Mod] Player Physics API [1.1.0] [playerphysics]

by Wuzzy » Post

Player Physics API

This mod makes it possible for multiple mods to modify player physics (speed, jumping strength, gravity) without conflict.

This mod is an API mod for modders. Players only might need it as dependency.

DOWNLOAD

Git repository and README

The problem
Mods and games in Minetest can set physical attributes of players, such as speed and jump strength (set_physics_override). But this method only can set the raw physical values, overwriting any previous value. So as soon more than 1 mod messes with the same player physics attribute (e.g. speed), all hell breaks loose and hilarity ensues, because each mod now competes for the “correct” physics attribute. In the worst case, speed, jump strength or gravity will go all over the place.

Player Physics API
The Player Physics API resolves this conflict by providing a “common ground” for mods to work together in this regard. It's a very lightweight mod and only has 2 functions.

It introduces the concept of “modifiers”. Any mod can add and remove factors for e.g. speed at any time and the product of all factors will be the final speed. This is a much more convenient and safer solution than to setting the raw speed.

This is basically a mod implementation of https://github.com/minetest/minetest/pull/7269.

Read about how to use this mod in the README!

Showcase
This mod is being used successfully in MineClone 2 and Hades Revisited for a very long time. In MineClone 2, it is used to coordinate the speed changes triggered by soul sand, sprinting, slowdown while firing an arrow and sleeping in bed. This would be impossible would every mod call set_physics_override directly.

IMORTANT WARNING
If you want to adopt this mod, you must be sure that ALL mods that mess with player physics do so by using this mod and not by calling set_physics_override directly. Any mod that calls set_physics_override direclty to change a physical attribute will destroy all benefits of the Player Physics API.

However, I consider that overwriting the raw player physics is never good development practice anyway, the problem is just that the Lua API does not provide any better tools than that.

Spead the word!
I would like to have physics modifiers as used in this mod to become a part of the official Minetest Lua API. Sadly, the discussion of this topic has been long and tiresome with no solution in sight. So in the meantime, we are stuck with a mod-based solution, i.e. the Player Physics API.

Please make modders aware that calling set_physics_override is dangerous and point them to this thread.

I also post this mod as evidence that a modifier-based solution is possible, practical, lightweight, logical, simple to use and something that modders would desperately need. Ideally, I like modders to move away from using set_physics_override and use a safer alternative instead.

Other infos
License of everything: MIT License
Dependencies: None!
Needs Minetest 5.0.0 or later.
Last edited by Wuzzy on Wed Mar 01, 2023 20:54, edited 5 times in total.

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

Re: [Mod] Player Physics API [1.0.0] [playerphysics]

by runs » Post

Yes, this it would be in the official API. I wonder why not yet.

User avatar
TenPlus1
Member
Posts: 3715
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: [Mod] Player Physics API [1.0.0] [playerphysics]

by TenPlus1 » Post

So basically like my POVA mod but using multiplication instead of addition?

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

Re: [Mod] Player Physics API [1.0.0] [playerphysics]

by texmex » Post

Or like player_monoids, LATE, physicsh or player_physics? What's different in yours, Wuzzy?

User avatar
Wuzzy
Member
Posts: 4786
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

Re: [Mod] Player Physics API [1.0.0] [playerphysics]

by Wuzzy » Post

Oh, I'm very sorry for posting a seemingly redundant mod.

Do note that this mod is NOT for generic effects, it only bothers about player physics you can set with set_player_physics.
LATE and player_monoids are for status effects. LATE is still in alpha.
I can not find the POVA mod. I don't know why you would use addition. It does not make sense. You DO know the modifiers in set_physics_override are factors, right? And yes, my mod uses factors.

The mods physcish and player_physics look like direct competitors.
physicsh is cluttered with useless items that should be removed. Also, in the README, it says “This API may change any time”. This automatically disqualifies the mod.
player_physics is very very similar, but it also supports temporary effects. Sadly, it has no forum thread (WHY???).

Basically, the mod search is terrible. :-)

How commonly used is player_physics at the moment? If it is too commonly used, I consider removing my mod.

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

Re: [Mod] Player Physics API [1.0.0] [playerphysics]

by texmex » Post

Sorry if I came off as a bit salty, I didn’t mean it like that at all. I honestly wanted to know the differences of each mod. Your mods are always of a high quality which immediately made me think of supporting it in my several player physics altering mods.

While I fully understand that LATE is also a larger project it internally handles the same problem as your mod, hence the mention. I don’t understand the statement about player_monoids however, as I’m using it for exactly player physics. But I can’t blame you for not having glanced the code of all those mods. :D

MinetestForFun sometimes write great mods but they usually make little effort to spread them in the community.

User avatar
jas
Member
Posts: 593
Joined: Mon Jul 24, 2017 18:15
IRC: Freenode
Location: IRC

Re: [Mod] Player Physics API [1.0.0] [playerphysics]

by jas » Post

Oh, I'm very sorry for posting a seemingly redundant mod.
Why? It's your mod. Who else would have posted it?




:)

User avatar
sorcerykid
Member
Posts: 1841
Joined: Fri Aug 26, 2016 15:36
GitHub: sorcerykid
In-game: Nemo
Location: Illinois, USA

Re: [Mod] Player Physics API [1.0.0] [playerphysics]

by sorcerykid » Post

Rather than a tossing away all your hard work why not do a pull request and incorporate this functionality into builtin? I know you said previous discussions didn't go anywhere, but I think this is project is worth salvaging.

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

Re: [Mod] Player Physics API [1.0.0] [playerphysics]

by texmex » Post

Well it was easy adding support for it, I just adapted the player_monoids API call. :)

User avatar
TenPlus1
Member
Posts: 3715
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: [Mod] Player Physics API [1.0.0] [playerphysics]

by TenPlus1 » Post

Pova works similar to your own mod (https://notabug.org/tenplus1/pova) and is already used in 3d_armor, stamina, playerplus, catcommands and a few xanadu specific mods.

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

Re: [Mod] Player Physics API [1.0.0] [playerphysics]

by texmex » Post

TenPlus1 wrote:Pova works similar to your own mod (https://notabug.org/tenplus1/pova) and is already used in 3d_armor, stamina, playerplus, catcommands and a few xanadu specific mods.
Does it also have a C++ based PR pending?

User avatar
TenPlus1
Member
Posts: 3715
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: [Mod] Player Physics API [1.0.0] [playerphysics]

by TenPlus1 » Post


User avatar
Wuzzy
Member
Posts: 4786
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

Re: [Mod] Player Physics API [1.0.0] [playerphysics]

by Wuzzy » Post

Pova works similar to your own mod (https://notabug.org/tenplus1/pova) and is already used in 3d_armor, stamina, playerplus, catcommands and a few xanadu specific mods.
I refuse to use anything for critical infrastructure that has a leading 0 in its version number, nor has been really announced on the forums so far. The risk is just too high, sorry.

User avatar
TenPlus1
Member
Posts: 3715
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: [Mod] Player Physics API [1.0.0] [playerphysics]

by TenPlus1 » Post

Wuzzy: That's ok :) was just pointing out the similarities between mods... Pova has been active on Xanadu for over 10 months with no issue although I forgot to add to forum, only the ContentDB:

https://content.minetest.net/packages/TenPlus1/pova/

User avatar
Wuzzy
Member
Posts: 4786
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

Re: [Mod] Player Physics API [1.0.0] [playerphysics]

by Wuzzy » Post

Well, I guess the main “selling point” of my mod is that it is the most minimalist mod that gets its task done and comes with zero unneccessary cruft. There is nothing left to remove.

It has a proper release model and complete documentation that is readable.
Also, it's very stable. This should make adoption as pain-free as possible.

I don't like POVA's design to be honest, it depends on globalstep, which I think is completely unneccessary. Also, the documentation seems incomplete, it's hard to follow.

It appears that POVA also adds/subtracts instead of multiplies. This is very weird mathematically. Let me explain why. I'm not saying it's wrong, but you should now what you're doing. IMO using factors is just the more “natural” and more straight-forward thing to do. It's much easier to maintain even in a big game.

Remember that the value you put into set_physics_override is not an absolute speed, but a speed factor.
Let's suppose you start with speed 1, then add 1, your effective speed is now 2. It has doubled. Great. But what happens when you add another 1? Then your effective speed changes from 2 to 3, which is now an increase of only 50%. In other words, the effective speed increase depends on your previous speed! There are diminishing returns. No idea if this is intentional. It's at least unexpected and missing in documentation. If it is intentional, great, but then POVA needs polishing.
At least the mod seems to maintain consistency.
There's some other useless cruft included, like a debug message in singleplayer or the test axe.

User avatar
TenPlus1
Member
Posts: 3715
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: [Mod] Player Physics API [1.0.0] [playerphysics]

by TenPlus1 » Post

Thanks for the input wuzzy, yes the addition/subtraction is on purpose to keep values easier and works quite well for most mods, and the globalstep can be disabled if it's not needed, it's only there to recalculate just incase of rogue mods :) The axe is a test example though...

User avatar
Kimapr
Member
Posts: 32
Joined: Fri May 24, 2019 15:53
GitHub: Kimapr
IRC: Kimapr
In-game: Kimapr

Re: [Mod] Player Physics API [1.0.0] [playerphysics]

by Kimapr » Post

Actually you can overwrite the ObjectRef's metatable in case of rogue mods. Minetest uses one metatable for all instances of a class. If you write to metatable of one instance, that affects other too (if you create different table and setmetatable of an instance to that table that won't affect other instances). That way you can find or create a ObjectRef, save set_physics_override for your internal use, then overwrite original one to your liking. It is like an *injection* into minetest API to change behaviour of mods. Then you don't need an API at all. You can inject all of your functions into minetest API
Ek59C88tAsaQuRAw6PCPsGFDozj1FuZ4

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

Re: [Mod] Player Physics API [1.0.0] [playerphysics]

by runs » Post

Brewing uses this.

User avatar
Wuzzy
Member
Posts: 4786
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

Re: [Mod] Player Physics API [1.0.1] [playerphysics]

by Wuzzy » Post

Version 1.0.1 is here!
This mod was outdated and had deprecated function calls (player attributes vs player meta), which causes annoying warnings to appear in "recent" Minetest versions. That's fixed now.

User avatar
Wuzzy
Member
Posts: 4786
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

Version 1.1.0 released!

by Wuzzy » Post

Version 1.1.0 is here!
A new function was added: playerphysics.get_physics_factor.
With this you can now query the value of a given physics factor (if it exists).

User avatar
Wuzzy
Member
Posts: 4786
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

Re: [Mod] Player Physics API [1.1.0] [playerphysics]

by Wuzzy » Post

The Git repository of this mod has been moved to Codeberg.org!

https://codeberg.org/Wuzzy/minetest_playerphysics

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 17 guests