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/
This commit is contained in:
Starbeamrainbowlabs 2023-12-30 13:12:10 +00:00
parent 45bed5cc71
commit 2f98b86c5f
No known key found for this signature in database
GPG Key ID: 1BE5172E637709C2
4 changed files with 83 additions and 17 deletions

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

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

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

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