From 2f98b86c5faac6af1ff5063dff033eba1344c531 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sat, 30 Dec 2023 13:12:10 +0000 Subject: [PATCH] movetool, //speed: add optdepend on pova pova is a physics_override manager mod, so it's important we have support for it to ensure we play nice with other mods Ref https://content.minetest.net/packages/TenPlus1/pova/ --- .../commands/extra/speed.lua | 33 ++++++++++----- worldeditadditions_core/mod.conf | 2 +- worldeditadditions_core/utils/player.lua | 41 +++++++++++++++++++ worldeditadditions_farwand/lib/movetool.lua | 24 ++++++++--- 4 files changed, 83 insertions(+), 17 deletions(-) diff --git a/worldeditadditions_commands/commands/extra/speed.lua b/worldeditadditions_commands/commands/extra/speed.lua index e66c279..66ad836 100644 --- a/worldeditadditions_commands/commands/extra/speed.lua +++ b/worldeditadditions_commands/commands/extra/speed.lua @@ -49,23 +49,36 @@ worldeditadditions_core.register_command("speed", { local player = minetest.get_player_by_name(name) if mode == "absolute" then - player:set_physics_override({ - speed = speed, - climb_speed = speed - }) + weac.player_set_physics_override(player, + "worldeditadditions_movetool", { + speed = speed, + climb_speed = speed + } + ) + -- player:set_physics_override({ + -- }) elseif mode == "relative" then - local overrides = player:get_physics_override() + local overrides = weac.player_get_physics_override( + player, "worldeditadditions_movetool" + ) local src_speed = overrides.speed or 1 local src_climb_speed = overrides.climb_speed or 1 - player:set_physics_override({ - speed = src_speed + speed, - climb_speed = src_climb_speed + speed - }) + weac.player_set_physics_override(player, + "worldeditadditions_movetool", { + speed = src_speed + speed, + climb_speed = src_climb_speed + speed + } + ) + -- player:set_physics_override({ + -- }) else return false, "Error: Unknown adjustment mode '"..tostring(mode).."'. This is a bug." end - local overrides_after = player:get_physics_override() + local overrides_after = weac.player_get_physics_override( + player, "worldeditadditions_movetool" + ) + -- local overrides_after = player:get_physics_override() local time_taken = weac.get_ms_time() - start_time diff --git a/worldeditadditions_core/mod.conf b/worldeditadditions_core/mod.conf index 38d5e0d..cc078ef 100644 --- a/worldeditadditions_core/mod.conf +++ b/worldeditadditions_core/mod.conf @@ -1,3 +1,3 @@ name = worldeditadditions_core description = worldeditadditions: core components -optional_depends = worldedit, worldedit_commands, worldedit_shortcommands +optional_depends = worldedit, worldedit_commands, worldedit_shortcommands, pova diff --git a/worldeditadditions_core/utils/player.lua b/worldeditadditions_core/utils/player.lua index 5483a0f..73a86b1 100644 --- a/worldeditadditions_core/utils/player.lua +++ b/worldeditadditions_core/utils/player.lua @@ -37,6 +37,47 @@ end -- /lua print(Vector3.clone(minetest.get_player_by_name(myname):get_look_dir())) +function wea_c.player_get_physics_override(player, purpose_str) + if type(player) == "string" then + player = minetest.get_player_by_name(player) + end + + if minetest.global_exists("pova") then + return pova.get_override(player:get_player_name(), purpose_str) + else + return minetest.get_physics_override(player:get_player_name()) + end +end + +function wea_c.player_set_physics_override(player, purpose_str, overrides) + if type(player) == "string" then + player = minetest.get_player_by_name(player) + end + local player_name = player:get_player_name() + + if minetest.global_exists("pova") then + local overrides_old = wea_c.player_get_physics_override(player, purpose_str) + local do_set = false + + if overrides_old == nil then + overrides_old = {} + do_set = true + end + + for key, value in pairs(overrides) do + overrides_old[key] = value + end + + -- Only set if this is the first time adding an override with this purpose_str for this player. On subsequent alterations, we update the existing overrides table + if do_set then + pova.add_override(player:get_player_name(), purpose_str, overrides_old) + end + pova.do_override(player) + else + minetest.set_physics_override(player_name, overrides) + end +end + --- DEPRECATED ================================================================= -- TODO: Refactor commands that use the following functions to use player_dir then delete these functions diff --git a/worldeditadditions_farwand/lib/movetool.lua b/worldeditadditions_farwand/lib/movetool.lua index 5acfd20..d91528c 100644 --- a/worldeditadditions_farwand/lib/movetool.lua +++ b/worldeditadditions_farwand/lib/movetool.lua @@ -1,16 +1,28 @@ +local weac = worldeditadditions_core + local function adjust_speed_relative(player, offset) - local overrides = player:get_physics_override() + local overrides = weac.player_get_physics_override( + player, "worldeditadditions_movetool" + ) + if overrides == nil then overrides = {} end + -- local overrides = player:get_physics_override() local src_speed = overrides.speed or 1 local src_climb_speed = overrides.climb_speed or 1 - player:set_physics_override({ - speed = math.max(src_speed + offset, 0.5), - climb_speed = math.max(src_climb_speed + offset, 0.5) - }) + weac.player_set_physics_override( + player, "worldeditadditions_movetool", { + speed = math.max(src_speed + offset, 0.5), + climb_speed = math.max(src_climb_speed + offset, 0.5) + } + ) + -- player:set_physics_override({ + -- }) -- Completely paranoid is me - local overrides_after = player:get_physics_override() + local overrides_after = weac.player_get_physics_override( + player, "worldeditadditions_movetool" + ) worldedit.player_notify(player:get_player_name(), "Movement speed is now x" .. tostring(overrides_after.speed)) end