diff --git a/builtin/game/default_physics.lua b/builtin/game/default_physics.lua new file mode 100644 index 000000000..e596bc8bf --- /dev/null +++ b/builtin/game/default_physics.lua @@ -0,0 +1,29 @@ +-- Minetest: builtin/game/default_physics.lua + +-- DEFAULT_PHYSICS variable of a player +core.DEFAULT_PHYSICS = { + speed = 1, + speed_walk = 1, + speed_climb = 1, + speed_crouch = 1, + speed_fast = 1, + + jump = 1, + gravity = 1, + + liquid_fluidity = 1, + liquid_fluidity_smooth = 1, + liquid_sink = 1, + + acceleration_default = 1, + acceleration_air = 1, + acceleration_fast = 1, + + sneak = true, + sneak_glitch = false, + new_move = true, +} + +core.register_on_joinplayer(function(player) + player:set_physics_override(core.DEFAULT_PHYSICS) +end) diff --git a/builtin/game/init.lua b/builtin/game/init.lua index b3c64e729..208c1c50a 100644 --- a/builtin/game/init.lua +++ b/builtin/game/init.lua @@ -30,6 +30,7 @@ dofile(commonpath .. "chatcommands.lua") dofile(gamepath .. "chat.lua") dofile(commonpath .. "information_formspecs.lua") dofile(gamepath .. "static_spawn.lua") +dofile(gamepath .. "default_physics.lua") dofile(gamepath .. "detached_inventory.lua") assert(loadfile(gamepath .. "falling.lua"))(builtin_shared) dofile(gamepath .. "features.lua") diff --git a/doc/lua_api.md b/doc/lua_api.md index 438769085..1924dd509 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -8706,6 +8706,7 @@ child will follow movement and rotation of that bone. * Returns `0` (no bits set) if the object is not a player. * `set_physics_override(override_table)` * Overrides the physics attributes of the player + * `core.DEFAULT_PHYSICS` contains the default values. * `override_table` is a table with the following fields: * `speed`: multiplier to *all* movement speed (`speed_*`) and acceleration (`acceleration_*`) values (default: `1`) diff --git a/games/devtest/mods/unittests/player.lua b/games/devtest/mods/unittests/player.lua index f8945f320..c319346f9 100644 --- a/games/devtest/mods/unittests/player.lua +++ b/games/devtest/mods/unittests/player.lua @@ -204,3 +204,17 @@ local function run_player_hotbar_clamp_tests(player) player:hud_set_hotbar_itemcount(old_bar_size) end unittests.register("test_player_hotbar_clamp", run_player_hotbar_clamp_tests, {player=true}) + +-- +-- Player defaults physics +-- +core.DEFAULT_PHYSICS.speed = 2 -- Slightly change +local function run_player_default_physics_tests(player) + local player_overrides = player:get_physics_override() + assert(player_overrides.speed == 2) + -- Revert everything + core.DEFAULT_PHYSICS.speed = 1 + player_overrides.speed = 1 + player:set_physics_override(player_overrides) +end +unittests.register("test_player_default_physics", run_player_default_physics_tests, {player=true})