1
0
Fork 0

take no damage when swimming near roof, no ability to no-clip through roof when swimming

wood_api
Sumyjkl 2022-07-17 21:46:36 +10:00
parent 5d2ffb36f2
commit e4c7d575fc
2 changed files with 30 additions and 8 deletions

View File

@ -34,10 +34,14 @@ local function get_player_nodes(player_pos)
work_pos.y = work_pos.y + 1.5 -- head level work_pos.y = work_pos.y + 1.5 -- head level
local node_head = node_ok(work_pos) 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 work_pos.y = work_pos.y - 1.2 -- feet level
local node_feet = node_ok(work_pos) 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 end
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
@ -62,11 +66,12 @@ minetest.register_globalstep(function(dtime)
local pos = player:get_pos() local pos = player:get_pos()
-- what is around me? -- 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 = node_stand
mcl_playerinfo[name].node_stand_below = node_stand_below mcl_playerinfo[name].node_stand_below = node_stand_below
mcl_playerinfo[name].node_head = node_head mcl_playerinfo[name].node_head = node_head
mcl_playerinfo[name].node_feet = node_feet mcl_playerinfo[name].node_feet = node_feet
mcl_playerinfo[name].node_above_head = node_above_head
end end
@ -81,6 +86,7 @@ minetest.register_on_joinplayer(function(player)
node_feet = "", node_feet = "",
node_stand = "", node_stand = "",
node_stand_below = "", node_stand_below = "",
node_above_head = "",
} }
end) end)

View File

@ -118,7 +118,8 @@ function limit_vel_yaw(player_vel_yaw, yaw)
return player_vel_yaw return player_vel_yaw
end 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 -- This following part is 2 wrapper functions for player:set_bones
-- and player:set_properties preventing them from being resent on -- 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)) 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 elseif get_item_group(mcl_playerinfo[name].node_head, "water") ~= 0 and is_sprinting(name) == true then
-- set head pitch and yaw when swimming -- 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)) 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 -- 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 }}) 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 -- 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)) 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 -- 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_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)) 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 = mcl_playerinfo[name].node_stand
node_stand_below = mcl_playerinfo[name].node_stand_below node_stand_below = mcl_playerinfo[name].node_stand_below
node_head = mcl_playerinfo[name].node_head node_head = mcl_playerinfo[name].node_head
node_above_head = mcl_playerinfo[name].node_above_head
node_feet = mcl_playerinfo[name].node_feet 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 return
end 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 return
end end
@ -459,8 +467,9 @@ minetest.register_globalstep(function(dtime)
local node_stand = mcl_playerinfo[name].node_stand local node_stand = mcl_playerinfo[name].node_stand
local node_stand_below = mcl_playerinfo[name].node_stand_below local node_stand_below = mcl_playerinfo[name].node_stand_below
local node_head = mcl_playerinfo[name].node_head 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 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 return
end end
@ -493,9 +502,16 @@ minetest.register_globalstep(function(dtime)
-- Is player suffocating inside node? (Only for solid full opaque cube type nodes -- Is player suffocating inside node? (Only for solid full opaque cube type nodes
-- without group disable_suffocation=1) -- 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) 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.collision_box == nil or ndef.collision_box.type == "regular")
and (ndef.node_box == nil or ndef.node_box.type == "regular") and (ndef.node_box == nil or ndef.node_box.type == "regular")
and (ndef.groups.disable_suffocation ~= 1) and (ndef.groups.disable_suffocation ~= 1)