From e4c7d575fcc52d492a38b0a8084814bc9dd553fe Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Sun, 17 Jul 2022 21:46:36 +1000 Subject: [PATCH 1/6] take no damage when swimming near roof, no ability to no-clip through roof when swimming --- mods/PLAYER/mcl_playerinfo/init.lua | 10 ++++++++-- mods/PLAYER/mcl_playerplus/init.lua | 28 ++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/mods/PLAYER/mcl_playerinfo/init.lua b/mods/PLAYER/mcl_playerinfo/init.lua index 9c5d1433f3..e37d6750b9 100644 --- a/mods/PLAYER/mcl_playerinfo/init.lua +++ b/mods/PLAYER/mcl_playerinfo/init.lua @@ -34,10 +34,14 @@ local function get_player_nodes(player_pos) work_pos.y = work_pos.y + 1.5 -- head level local node_head = node_ok(work_pos) + work_pos.y = work_pos.y + 2.2 -- above head level + local node_above_head = node_ok(work_pos) + work_pos.y = work_pos.y - 2.2 -- above head level + work_pos.y = work_pos.y - 1.2 -- feet level local node_feet = node_ok(work_pos) - return node_stand, node_stand_below, node_head, node_feet + return node_stand, node_stand_below, node_head, node_feet, node_above_head end minetest.register_globalstep(function(dtime) @@ -62,11 +66,12 @@ minetest.register_globalstep(function(dtime) local pos = player:get_pos() -- what is around me? - local node_stand, node_stand_below, node_head, node_feet = get_player_nodes(pos) + local node_stand, node_stand_below, node_head, node_feet, node_above_head = get_player_nodes(pos) mcl_playerinfo[name].node_stand = node_stand mcl_playerinfo[name].node_stand_below = node_stand_below mcl_playerinfo[name].node_head = node_head mcl_playerinfo[name].node_feet = node_feet + mcl_playerinfo[name].node_above_head = node_above_head end @@ -81,6 +86,7 @@ minetest.register_on_joinplayer(function(player) node_feet = "", node_stand = "", node_stand_below = "", + node_above_head = "", } end) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 924b60c97d..bb6734a8d7 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -118,7 +118,8 @@ function limit_vel_yaw(player_vel_yaw, yaw) return player_vel_yaw end -local node_stand, node_stand_below, node_head, node_feet +local node_stand, node_stand_below, node_head, node_feet, node_above_head +local is_swimming -- This following part is 2 wrapper functions for player:set_bones -- and player:set_properties preventing them from being resent on @@ -370,13 +371,15 @@ minetest.register_globalstep(function(dtime) set_bone_position_conditional(player,"Body_Control", vector.new(0,6.3,0), vector.new(0, -player_vel_yaw + yaw, 0)) elseif get_item_group(mcl_playerinfo[name].node_head, "water") ~= 0 and is_sprinting(name) == true then -- set head pitch and yaw when swimming + is_swimming = true set_bone_position_conditional(player,"Head_Control", vector.new(0,6.3,0), vector.new(pitch-degrees(dir_to_pitch(player_velocity)),player_vel_yaw - yaw,0)) -- sets eye height, and nametag color accordingly set_properties_conditional(player,{collisionbox = {-0.312,0,-0.312,0.312,0.8,0.312}, eye_height = 0.5, nametag_color = { r = 225, b = 225, a = 225, g = 225 }}) -- control body bone when swimming set_bone_position_conditional(player,"Body_Control", vector.new(0,6.3,0), vector.new(degrees(dir_to_pitch(player_velocity)) - 90,-player_vel_yaw + yaw + 180,0)) - else + elseif is_swimming and mcl_playerinfo[name].node_head == "air" or get_item_group(mcl_playerinfo[name].node_head, "water") ~= 0 then -- sets eye height, and nametag color accordingly + is_swimming = false set_properties_conditional(player,{collisionbox = {-0.312,0,-0.312,0.312,1.8,0.312}, eye_height = 1.5, nametag_color = { r = 225, b = 225, a = 225, g = 225 }}) set_bone_position_conditional(player,"Head_Control", vector.new(0,6.3,0), vector.new(pitch, player_vel_yaw - yaw, 0)) @@ -397,11 +400,16 @@ minetest.register_globalstep(function(dtime) node_stand = mcl_playerinfo[name].node_stand node_stand_below = mcl_playerinfo[name].node_stand_below node_head = mcl_playerinfo[name].node_head + node_above_head = mcl_playerinfo[name].node_above_head node_feet = mcl_playerinfo[name].node_feet - if not node_stand or not node_stand_below or not node_head or not node_feet then + if not node_stand or not node_stand_below or not node_head or not node_feet or not node_above_head then return end - if not minetest.registered_nodes[node_stand] or not minetest.registered_nodes[node_stand_below] or not minetest.registered_nodes[node_head] or not minetest.registered_nodes[node_feet] then + if (not minetest.registered_nodes[node_stand] + or not minetest.registered_nodes[node_stand_below] + or not minetest.registered_nodes[node_head] + or not minetest.registered_nodes[node_feet] + or not minetest.registered_nodes[node_above_head]) then return end @@ -459,8 +467,9 @@ minetest.register_globalstep(function(dtime) local node_stand = mcl_playerinfo[name].node_stand local node_stand_below = mcl_playerinfo[name].node_stand_below local node_head = mcl_playerinfo[name].node_head + local node_above_head = mcl_playerinfo[name].node_above_head local node_feet = mcl_playerinfo[name].node_feet - if not node_stand or not node_stand_below or not node_head or not node_feet then + if not node_stand or not node_stand_below or not node_head or not node_feet or not node_above_head then return end @@ -493,9 +502,16 @@ minetest.register_globalstep(function(dtime) -- Is player suffocating inside node? (Only for solid full opaque cube type nodes -- without group disable_suffocation=1) - local ndef = minetest.registered_nodes[node_head] + local ndef = nil + if is_swimming then + ndef = minetest.registered_nodes[node_feet] + -- mcl_util.deal_damage(player, 1, {type = "in_wall"}) + else + ndef = minetest.registered_nodes[node_head] + end if (ndef.walkable == nil or ndef.walkable == true) + or not is_swimming and (ndef.collision_box == nil or ndef.collision_box.type == "regular") and (ndef.node_box == nil or ndef.node_box.type == "regular") and (ndef.groups.disable_suffocation ~= 1) From 2e06e22d7082854d3c9e02f6c483cb2e80b9e8dd Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Sun, 17 Jul 2022 21:50:22 +1000 Subject: [PATCH 2/6] removed unnecessary node_above_head variable --- mods/PLAYER/mcl_playerinfo/init.lua | 10 ++-------- mods/PLAYER/mcl_playerplus/init.lua | 11 ++++------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/mods/PLAYER/mcl_playerinfo/init.lua b/mods/PLAYER/mcl_playerinfo/init.lua index e37d6750b9..9c5d1433f3 100644 --- a/mods/PLAYER/mcl_playerinfo/init.lua +++ b/mods/PLAYER/mcl_playerinfo/init.lua @@ -34,14 +34,10 @@ local function get_player_nodes(player_pos) work_pos.y = work_pos.y + 1.5 -- head level local node_head = node_ok(work_pos) - work_pos.y = work_pos.y + 2.2 -- above head level - local node_above_head = node_ok(work_pos) - work_pos.y = work_pos.y - 2.2 -- above head level - work_pos.y = work_pos.y - 1.2 -- feet level local node_feet = node_ok(work_pos) - return node_stand, node_stand_below, node_head, node_feet, node_above_head + return node_stand, node_stand_below, node_head, node_feet end minetest.register_globalstep(function(dtime) @@ -66,12 +62,11 @@ minetest.register_globalstep(function(dtime) local pos = player:get_pos() -- what is around me? - local node_stand, node_stand_below, node_head, node_feet, node_above_head = get_player_nodes(pos) + local node_stand, node_stand_below, node_head, node_feet = get_player_nodes(pos) mcl_playerinfo[name].node_stand = node_stand mcl_playerinfo[name].node_stand_below = node_stand_below mcl_playerinfo[name].node_head = node_head mcl_playerinfo[name].node_feet = node_feet - mcl_playerinfo[name].node_above_head = node_above_head end @@ -86,7 +81,6 @@ minetest.register_on_joinplayer(function(player) node_feet = "", node_stand = "", node_stand_below = "", - node_above_head = "", } end) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index bb6734a8d7..713a079da2 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -118,7 +118,7 @@ function limit_vel_yaw(player_vel_yaw, yaw) return player_vel_yaw end -local node_stand, node_stand_below, node_head, node_feet, node_above_head +local node_stand, node_stand_below, node_head, node_feet local is_swimming -- This following part is 2 wrapper functions for player:set_bones @@ -400,16 +400,14 @@ minetest.register_globalstep(function(dtime) node_stand = mcl_playerinfo[name].node_stand node_stand_below = mcl_playerinfo[name].node_stand_below node_head = mcl_playerinfo[name].node_head - node_above_head = mcl_playerinfo[name].node_above_head node_feet = mcl_playerinfo[name].node_feet - if not node_stand or not node_stand_below or not node_head or not node_feet or not node_above_head then + if not node_stand or not node_stand_below or not node_head or not node_feet then return end if (not minetest.registered_nodes[node_stand] or not minetest.registered_nodes[node_stand_below] or not minetest.registered_nodes[node_head] - or not minetest.registered_nodes[node_feet] - or not minetest.registered_nodes[node_above_head]) then + or not minetest.registered_nodes[node_feet]) then return end @@ -467,9 +465,8 @@ minetest.register_globalstep(function(dtime) local node_stand = mcl_playerinfo[name].node_stand local node_stand_below = mcl_playerinfo[name].node_stand_below local node_head = mcl_playerinfo[name].node_head - local node_above_head = mcl_playerinfo[name].node_above_head local node_feet = mcl_playerinfo[name].node_feet - if not node_stand or not node_stand_below or not node_head or not node_feet or not node_above_head then + if not node_stand or not node_stand_below or not node_head or not node_feet then return end From 4738834ddd31cd4e960d8def3d3facd92d51efed Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Sun, 17 Jul 2022 22:40:33 +1000 Subject: [PATCH 3/6] remove unecessary code --- mods/PLAYER/mcl_playerplus/init.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 713a079da2..37e7ea60c1 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -377,7 +377,7 @@ minetest.register_globalstep(function(dtime) set_properties_conditional(player,{collisionbox = {-0.312,0,-0.312,0.312,0.8,0.312}, eye_height = 0.5, nametag_color = { r = 225, b = 225, a = 225, g = 225 }}) -- control body bone when swimming set_bone_position_conditional(player,"Body_Control", vector.new(0,6.3,0), vector.new(degrees(dir_to_pitch(player_velocity)) - 90,-player_vel_yaw + yaw + 180,0)) - elseif is_swimming and mcl_playerinfo[name].node_head == "air" or get_item_group(mcl_playerinfo[name].node_head, "water") ~= 0 then + elseif mcl_playerinfo[name].node_head == "air" or get_item_group(mcl_playerinfo[name].node_head, "water") ~= 0 then -- sets eye height, and nametag color accordingly is_swimming = false set_properties_conditional(player,{collisionbox = {-0.312,0,-0.312,0.312,1.8,0.312}, eye_height = 1.5, nametag_color = { r = 225, b = 225, a = 225, g = 225 }}) @@ -503,12 +503,10 @@ minetest.register_globalstep(function(dtime) local ndef = nil if is_swimming then ndef = minetest.registered_nodes[node_feet] - -- mcl_util.deal_damage(player, 1, {type = "in_wall"}) else ndef = minetest.registered_nodes[node_head] end if (ndef.walkable == nil or ndef.walkable == true) - or not is_swimming and (ndef.collision_box == nil or ndef.collision_box.type == "regular") and (ndef.node_box == nil or ndef.node_box.type == "regular") and (ndef.groups.disable_suffocation ~= 1) From a41cbb7ebf45e2ac0216cc11d6297695b7062828 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Sun, 17 Jul 2022 22:50:22 +1000 Subject: [PATCH 4/6] added comment and removed unnecessary code --- mods/PLAYER/mcl_playerplus/init.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 37e7ea60c1..48b09adae4 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -499,12 +499,10 @@ minetest.register_globalstep(function(dtime) -- Is player suffocating inside node? (Only for solid full opaque cube type nodes -- without group disable_suffocation=1) - - local ndef = nil + -- if swimming, check the feet node instead, because the head node will be above the player when swimming + local ndef = minetest.registered_nodes[node_head] if is_swimming then ndef = minetest.registered_nodes[node_feet] - else - ndef = minetest.registered_nodes[node_head] end if (ndef.walkable == nil or ndef.walkable == true) and (ndef.collision_box == nil or ndef.collision_box.type == "regular") From 9062a6e22efe6d8199c07cda82caf656fb322ce9 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Sun, 17 Jul 2022 23:14:24 +1000 Subject: [PATCH 5/6] add node_head_top to check to make sure you won't clip through blocks before going out of swim / fly mode --- mods/PLAYER/mcl_playerinfo/init.lua | 9 +++++++-- mods/PLAYER/mcl_playerplus/init.lua | 14 ++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/mods/PLAYER/mcl_playerinfo/init.lua b/mods/PLAYER/mcl_playerinfo/init.lua index 9c5d1433f3..1f1b847499 100644 --- a/mods/PLAYER/mcl_playerinfo/init.lua +++ b/mods/PLAYER/mcl_playerinfo/init.lua @@ -33,11 +33,14 @@ local function get_player_nodes(player_pos) work_pos.y = work_pos.y + 1.5 -- head level local node_head = node_ok(work_pos) + work_pos.y = work_pos.y + 0.5 -- top of head level, at collision box height + local node_head_top = node_ok(work_pos) + work_pos.y = work_pos.y - 0.5 work_pos.y = work_pos.y - 1.2 -- feet level local node_feet = node_ok(work_pos) - return node_stand, node_stand_below, node_head, node_feet + return node_stand, node_stand_below, node_head, node_feet, node_head_top end minetest.register_globalstep(function(dtime) @@ -62,11 +65,12 @@ minetest.register_globalstep(function(dtime) local pos = player:get_pos() -- what is around me? - local node_stand, node_stand_below, node_head, node_feet = get_player_nodes(pos) + local node_stand, node_stand_below, node_head, node_feet, node_head_top = get_player_nodes(pos) mcl_playerinfo[name].node_stand = node_stand mcl_playerinfo[name].node_stand_below = node_stand_below mcl_playerinfo[name].node_head = node_head mcl_playerinfo[name].node_feet = node_feet + mcl_playerinfo[name].node_head_top = node_head_top end @@ -81,6 +85,7 @@ minetest.register_on_joinplayer(function(player) node_feet = "", node_stand = "", node_stand_below = "", + node_head_top = "", } end) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 48b09adae4..cdee0b7984 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -118,7 +118,7 @@ function limit_vel_yaw(player_vel_yaw, yaw) return player_vel_yaw end -local node_stand, node_stand_below, node_head, node_feet +local node_stand, node_stand_below, node_head, node_feet, node_head_top local is_swimming -- This following part is 2 wrapper functions for player:set_bones @@ -377,7 +377,10 @@ minetest.register_globalstep(function(dtime) set_properties_conditional(player,{collisionbox = {-0.312,0,-0.312,0.312,0.8,0.312}, eye_height = 0.5, nametag_color = { r = 225, b = 225, a = 225, g = 225 }}) -- control body bone when swimming set_bone_position_conditional(player,"Body_Control", vector.new(0,6.3,0), vector.new(degrees(dir_to_pitch(player_velocity)) - 90,-player_vel_yaw + yaw + 180,0)) - elseif mcl_playerinfo[name].node_head == "air" or get_item_group(mcl_playerinfo[name].node_head, "water") ~= 0 then + elseif (mcl_playerinfo[name].node_head_top == "air" -- make sure the collision box is not going to clip through the ceiling + or get_item_group(mcl_playerinfo[name].node_head_top, "water") ~= 0) + and (mcl_playerinfo[name].node_head == "air" + or get_item_group(mcl_playerinfo[name].node_head, "water") ~= 0) then -- sets eye height, and nametag color accordingly is_swimming = false set_properties_conditional(player,{collisionbox = {-0.312,0,-0.312,0.312,1.8,0.312}, eye_height = 1.5, nametag_color = { r = 225, b = 225, a = 225, g = 225 }}) @@ -401,13 +404,15 @@ minetest.register_globalstep(function(dtime) node_stand_below = mcl_playerinfo[name].node_stand_below node_head = mcl_playerinfo[name].node_head node_feet = mcl_playerinfo[name].node_feet + node_head_top = mcl_playerinfo[name].node_head_top if not node_stand or not node_stand_below or not node_head or not node_feet then return end if (not minetest.registered_nodes[node_stand] or not minetest.registered_nodes[node_stand_below] or not minetest.registered_nodes[node_head] - or not minetest.registered_nodes[node_feet]) then + or not minetest.registered_nodes[node_feet] + or not minetest.registered_nodes[node_head_top]) then return end @@ -466,7 +471,8 @@ minetest.register_globalstep(function(dtime) local node_stand_below = mcl_playerinfo[name].node_stand_below local node_head = mcl_playerinfo[name].node_head local node_feet = mcl_playerinfo[name].node_feet - if not node_stand or not node_stand_below or not node_head or not node_feet then + local node_head_top = mcl_playerinfo[name].node_head_top + if not node_stand or not node_stand_below or not node_head or not node_feet or not node_head_top then return end From de0a78012de18968db9e2d0ea849c73bf1d143b5 Mon Sep 17 00:00:00 2001 From: SumianVoice Date: Mon, 18 Jul 2022 10:09:04 +1000 Subject: [PATCH 6/6] fix getting stuck under non-opaque blocks --- mods/PLAYER/mcl_playerplus/init.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index cdee0b7984..c3876269c4 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -377,10 +377,8 @@ minetest.register_globalstep(function(dtime) set_properties_conditional(player,{collisionbox = {-0.312,0,-0.312,0.312,0.8,0.312}, eye_height = 0.5, nametag_color = { r = 225, b = 225, a = 225, g = 225 }}) -- control body bone when swimming set_bone_position_conditional(player,"Body_Control", vector.new(0,6.3,0), vector.new(degrees(dir_to_pitch(player_velocity)) - 90,-player_vel_yaw + yaw + 180,0)) - elseif (mcl_playerinfo[name].node_head_top == "air" -- make sure the collision box is not going to clip through the ceiling - or get_item_group(mcl_playerinfo[name].node_head_top, "water") ~= 0) - and (mcl_playerinfo[name].node_head == "air" - or get_item_group(mcl_playerinfo[name].node_head, "water") ~= 0) then + elseif get_item_group(mcl_playerinfo[name].node_head, "opaque") == 0 + and get_item_group(mcl_playerinfo[name].node_head_top, "opaque") == 0 then -- sets eye height, and nametag color accordingly is_swimming = false set_properties_conditional(player,{collisionbox = {-0.312,0,-0.312,0.312,1.8,0.312}, eye_height = 1.5, nametag_color = { r = 225, b = 225, a = 225, g = 225 }})