1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00
This commit is contained in:
1F616EMO~nya 2025-06-26 23:01:18 +08:00 committed by GitHub
commit cc6b91ff7b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 45 additions and 0 deletions

View file

@ -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)

View file

@ -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")

View file

@ -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`)

View file

@ -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})