From 3118efdf1c8b628e8035522f3d7edbe506d7bee7 Mon Sep 17 00:00:00 2001 From: 1F616EMO Date: Sun, 15 Jun 2025 22:59:43 +0800 Subject: [PATCH] Add default physics variables Co-authored-by: Yoruma <168607605+Mahoyomu@users.noreply.github.com> --- builtin/game/default_physics.lua | 29 +++++++++++++++++++++++++ builtin/game/init.lua | 1 + doc/lua_api.md | 1 + games/devtest/mods/unittests/player.lua | 14 ++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 builtin/game/default_physics.lua 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 303ce04ab..97cb3d5f4 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -8513,6 +8513,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})