mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-25 16:43:05 +00:00
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:
parent
45bed5cc71
commit
2f98b86c5f
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)
|
local player = minetest.get_player_by_name(name)
|
||||||
|
|
||||||
if mode == "absolute" then
|
if mode == "absolute" then
|
||||||
player:set_physics_override({
|
weac.player_set_physics_override(player,
|
||||||
|
"worldeditadditions_movetool", {
|
||||||
speed = speed,
|
speed = speed,
|
||||||
climb_speed = speed
|
climb_speed = speed
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
-- player:set_physics_override({
|
||||||
|
-- })
|
||||||
elseif mode == "relative" then
|
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_speed = overrides.speed or 1
|
||||||
local src_climb_speed = overrides.climb_speed or 1
|
local src_climb_speed = overrides.climb_speed or 1
|
||||||
player:set_physics_override({
|
weac.player_set_physics_override(player,
|
||||||
|
"worldeditadditions_movetool", {
|
||||||
speed = src_speed + speed,
|
speed = src_speed + speed,
|
||||||
climb_speed = src_climb_speed + speed
|
climb_speed = src_climb_speed + speed
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
-- player:set_physics_override({
|
||||||
|
-- })
|
||||||
else
|
else
|
||||||
return false, "Error: Unknown adjustment mode '"..tostring(mode).."'. This is a bug."
|
return false, "Error: Unknown adjustment mode '"..tostring(mode).."'. This is a bug."
|
||||||
end
|
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
|
local time_taken = weac.get_ms_time() - start_time
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
name = worldeditadditions_core
|
name = worldeditadditions_core
|
||||||
description = worldeditadditions: core components
|
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()))
|
-- /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 =================================================================
|
--- DEPRECATED =================================================================
|
||||||
-- TODO: Refactor commands that use the following functions to use player_dir then delete these functions
|
-- 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 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_speed = overrides.speed or 1
|
||||||
local src_climb_speed = overrides.climb_speed or 1
|
local src_climb_speed = overrides.climb_speed or 1
|
||||||
|
|
||||||
player:set_physics_override({
|
weac.player_set_physics_override(
|
||||||
|
player, "worldeditadditions_movetool", {
|
||||||
speed = math.max(src_speed + offset, 0.5),
|
speed = math.max(src_speed + offset, 0.5),
|
||||||
climb_speed = math.max(src_climb_speed + offset, 0.5)
|
climb_speed = math.max(src_climb_speed + offset, 0.5)
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
-- player:set_physics_override({
|
||||||
|
-- })
|
||||||
|
|
||||||
-- Completely paranoid is me
|
-- 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))
|
worldedit.player_notify(player:get_player_name(), "Movement speed is now x" .. tostring(overrides_after.speed))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue