From 0a9c125316854716515e5945e0442c39d002eb43 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Tue, 26 Dec 2023 13:37:19 +0000 Subject: [PATCH] Implement //speed --- CHANGELOG.md | 1 + Chat-Command-Reference.md | 17 +++++ .../commands/extra/speed.lua | 74 +++++++++++++++++++ worldeditadditions_commands/init.lua | 2 + 4 files changed, 94 insertions(+) create mode 100644 worldeditadditions_commands/commands/extra/speed.lua diff --git a/CHANGELOG.md b/CHANGELOG.md index 373cf2c..82f3125 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Chat-Command-Reference.md b/Chat-Command-Reference.md index fc66d35..aa52275 100644 --- a/Chat-Command-Reference.md +++ b/Chat-Command-Reference.md @@ -1494,6 +1494,23 @@ This command is intended for development and modding. You will not normally need --> +### `//speed []` +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. diff --git a/worldeditadditions_commands/commands/extra/speed.lua b/worldeditadditions_commands/commands/extra/speed.lua new file mode 100644 index 0000000..e66c279 --- /dev/null +++ b/worldeditadditions_commands/commands/extra/speed.lua @@ -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 = "[]", + 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 +}) diff --git a/worldeditadditions_commands/init.lua b/worldeditadditions_commands/init.lua index 5b00164..fa57a68 100644 --- a/worldeditadditions_commands/init.lua +++ b/worldeditadditions_commands/init.lua @@ -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