Implement //speed

This commit is contained in:
Starbeamrainbowlabs 2023-12-26 13:37:19 +00:00
parent 6d81d47a31
commit 0a9c125316
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
4 changed files with 94 additions and 0 deletions

View file

@ -11,6 +11,7 @@ Note to self: See the bottom of this file for the release template text.
- Added [`//nodeapply`](https://worldeditadditions.mooncarrot.space/Reference/#nodeapply), a generalisation of [`//airapply`](https://worldeditadditions.mooncarrot.space/Reference/#airapply) that works with a defined list of nodes. Check out [the reference](https://worldeditadditions.mooncarrot.space/Reference/#nodeapply) - it has some cool tricks to it! (thanks for suggesting, @kliv91 from the Discord server!)
- Added [`//ngroups`](https://worldeditadditions.mooncarrot.space/Reference/#ngroups), which lists the groups that a given node is a member of. Useful when paired with [`//nodeapply`](https://worldeditadditions.mooncarrot.space/Reference/#nodeapply)!
- Added [`//rotate+`](https://worldeditadditions.mooncarrot.space/Reference/#rotate) to rotate regions through arbitrary series of potentially non-axis-aligned rotations.
- Added [`//speed`](https://worldeditadditions.mooncarrot.space/Reference/#rotate) to adjust your own movement speed
### Bugfixes and changes
- Don't warn on failed registration of `//flora` → [`//bonemeal`](https://worldeditadditions.mooncarrot.space/Reference/#bonemeal) if the `bonemeal` mod isn't installed (e.g. in MineClone2) - thanks @VorTechnix in #106

View file

@ -1494,6 +1494,23 @@ This command is intended for development and modding. You will not normally need
-->
### `//speed [<value=1>]`
Adjusts your player movement speed to the specified value. In other words:
```weacmd
//speed 2
```
...will double your movement speed.
This command also takes Minetest's "Fast mode" into account and adjusts accordingly. Relative adjustments can be done by prepending either a `+` to increase or `-` to decrease respectively.
```weacmd
//speed +0.5
//speed -3
```
### `//y`
Confirms the execution of a command if it could potentially affect a large number of nodes and take a while. This is a regular WorldEdit command.

View file

@ -0,0 +1,74 @@
local weac = worldeditadditions_core
local wea = worldeditadditions
local weacmd = worldeditadditions_commands
local Vector3 = weac.Vector3
-- ███████ ██████ ███████ ███████ ██████
-- ██ ██ ██ ██ ██ ██ ██
-- ███████ ██████ █████ █████ ██ ██
-- ██ ██ ██ ██ ██ ██
-- ███████ ██ ███████ ███████ ██████
worldeditadditions_core.register_command("speed", {
params = "[<value=1>]",
description =
"Changes your movement speed. A value of 1 = normal speed. Prepend + or - to add or subtract a given amount from the current value.",
privs = { worldedit = true },
require_pos = 0,
parse = function(params_text)
if not params_text or params_text == "" then
params_text = "1"
end
local speed
local mode = "absolute"
params_text = weac.trim(params_text)
if params_text:sub(1,1) == "+" or params_text:sub(1,1) == "-" then
mode = "relative"
end
speed = tonumber(params_text)
if not speed then return false, "Error: Invalid speed value. The speed value must be a number." end
print("DEBUG:speed/parse PARAMS_TEXT", params_text, "MODE", mode, "SPEED", speed)
return true, mode, speed
end,
nodes_needed = function(name)
return 0
end,
func = function(name, mode, speed)
local start_time = weac.get_ms_time()
print("DEBUG:speed NAME", name, "MODE", mode, "SPEED", speed)
local player = minetest.get_player_by_name(name)
if mode == "absolute" then
player:set_physics_override({
speed = speed,
climb_speed = speed
})
elseif mode == "relative" then
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 = src_speed + speed,
climb_speed = src_climb_speed + speed
})
else
return false, "Error: Unknown adjustment mode '"..tostring(mode).."'. This is a bug."
end
local overrides_after = player:get_physics_override()
local time_taken = weac.get_ms_time() - start_time
return true, "Movement speed is now x"..tostring(overrides_after.speed).."."
end
})

View file

@ -58,6 +58,8 @@ dofile(wea_cmd.modpath.."/commands/wireframe/init.lua")
dofile(wea_cmd.modpath.."/commands/extra/saplingaliases.lua")
dofile(wea_cmd.modpath.."/commands/extra/basename.lua")
dofile(wea_cmd.modpath.."/commands/extra/sculptlist.lua")
dofile(wea_cmd.modpath.."/commands/extra/speed.lua")
-- Don't register the //bonemeal command if the bonemeal mod isn't present
if minetest.global_exists("bonemeal") then