Merge branch 'master' of https://git.minetest.land/MineClone2/MineClone2 into commands-refactoring-1

This commit is contained in:
AFCMS 2021-03-05 09:50:07 +01:00
commit 71353ac934
3 changed files with 39 additions and 2 deletions

View File

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

View File

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

View File

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