diff --git a/API.md b/API.md index d29115d..99a8a09 100644 --- a/API.md +++ b/API.md @@ -46,6 +46,19 @@ Removes the physics factor of the given ID and updates the player's physics. #### Parameters Same as in `playerphysics.add_physics_factor`, except there is no `value` argument. + + +### `playerphysics.get_physics_factor(player, attribute, id)` +Returns the current physics factor of the given ID, if it exists. +If the ID exists, returns a number. If it does not exist, returns nil. + +Note a missing physics factor is mathematically equivalent to a factor of 1. + +#### Parameters +Same as in `playerphysics.add_physics_factor`, except there is no `value` argument. + + + ## Examples ### Speed changes Let's assume this mod is used by 3 different mods all trying to change the speed: diff --git a/init.lua b/init.lua index 50d6454..b410b02 100644 --- a/init.lua +++ b/init.lua @@ -43,3 +43,15 @@ function playerphysics.remove_physics_factor(player, attribute, id) local raw_value = calculate_attribute_product(player, attribute) player:set_physics_override({[attribute] = raw_value}) end + +function playerphysics.get_physics_factor(player, attribute, id) + local meta = player:get_meta() + local a = minetest.deserialize(meta:get_string("playerphysics:physics")) + if a == nil then + return nil + elseif a[attribute] == nil then + return nil + else + return a[attribute][id] + end +end