From 31441a02e51ce12366cbeac92b8dea90a6e7c929 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Fri, 5 Mar 2021 09:26:13 +0100 Subject: [PATCH 1/2] Add CSM sprinting with double tap forward --- minetest.conf | 5 +++++ mods/PLAYER/mcl_sprint/init.lua | 22 ++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/minetest.conf b/minetest.conf index 90539659c..14344ef21 100644 --- a/minetest.conf +++ b/minetest.conf @@ -33,3 +33,8 @@ mgvalleys_spflags = noaltitude_chill,noaltitude_dry,nohumid_rivers,vary_river_de keepInventory = false dedicated_server_step = 0.001 + +# Clientmodding to support official client +enable_client_modding = true +csm_restriction_flags = 0 +enable_mod_channels = true diff --git a/mods/PLAYER/mcl_sprint/init.lua b/mods/PLAYER/mcl_sprint/init.lua index 2ef5be685..f3ea42f2c 100644 --- a/mods/PLAYER/mcl_sprint/init.lua +++ b/mods/PLAYER/mcl_sprint/init.lua @@ -31,9 +31,11 @@ minetest.register_on_joinplayer(function(player) sprinting = false, timeOut = 0, shouldSprint = false, + clientSprint = false, lastPos = player:get_pos(), sprintDistance = 0, - fov = 1.0 + fov = 1.0, + channel = minetest.mod_channel_join("mcl_sprint:" .. playerName), } end) minetest.register_on_leaveplayer(function(player) @@ -41,6 +43,11 @@ minetest.register_on_leaveplayer(function(player) players[playerName] = nil end) +local function cancelClientSprinting(name) + players[name].channel:send_all("") + players[name].clientSprint = false +end + local function setSprinting(playerName, sprinting) --Sets the state of a player (0=stopped/moving, 1=sprinting) local player = minetest.get_player_by_name(playerName) if players[playerName] then @@ -97,6 +104,16 @@ local function get_top_node_tile(param2, paramtype2) end end +minetest.register_on_modchannel_message(function(channel_name, sender, message) + if channel_name == "mcl_sprint:" .. sender then + players[sender].clientSprint = minetest.is_yes(message) + end +end) + +minetest.register_on_respawnplayer(function(player) + cancelClientSprinting(player:get_player_name()) +end) + minetest.register_globalstep(function(dtime) --Get the gametime local gameTime = minetest.get_gametime() @@ -107,7 +124,7 @@ minetest.register_globalstep(function(dtime) if player ~= nil then local ctrl = player:get_player_control() --Check if the player should be sprinting - if ctrl.aux1 and ctrl.up and not ctrl.sneak then + if players[playerName]["clientSprint"] or ctrl.aux1 and ctrl.up and not ctrl.sneak then players[playerName]["shouldSprint"] = true else players[playerName]["shouldSprint"] = false @@ -160,6 +177,7 @@ minetest.register_globalstep(function(dtime) -- Prevent sprinting if hungry or sleeping if (mcl_hunger.active and mcl_hunger.get_hunger(player) <= 6) or (player:get_meta():get_string("mcl_beds:sleeping") == "true") then sprinting = false + cancelClientSprinting(playerName) else sprinting = true end From 09671b7ac92351e7a7d46c5723c84798111e1787 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Fri, 5 Mar 2021 09:37:27 +0100 Subject: [PATCH 2/2] Add simple color validator / parser --- mods/CORE/mcl_util/init.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index 6c63c21ab..ec2aa3017 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -405,3 +405,17 @@ function mcl_util.get_object_center(obj) pos.y = pos.y + (ymax - ymin) / 2.0 return pos end + +function mcl_util.get_color(colorstr) + local mc_color = mcl_colors[colorstr:upper()] + if mc_color then + return mc_color + end + if #colorstr ~= 7 or colorstr:sub(1, 1) ~= "#"then + return + end + local hex = tonumber(colorstr:sub(2, 7), 16) + if hex then + return colorstr, hex + end +end