Removed bad code in mcl_playerplus in favour of new submerged checking, moved sumberged calculation from mcl_playerinfo to mcl_playerplus

This commit is contained in:
WillConker 2024-06-09 18:20:04 +01:00
parent e0f7d9f1ee
commit b01710ccc5
3 changed files with 49 additions and 53 deletions

View File

@ -154,7 +154,6 @@ mcl_weather.skycolor = {
local has_weather = (mcl_worlds.has_weather(pos) and (mcl_weather.state == "snow" or mcl_weather.state =="rain" or mcl_weather.state == "thunder") and mcl_weather.has_snow(pos)) or ((mcl_weather.state =="rain" or mcl_weather.state == "thunder") and mcl_weather.has_rain(pos))
local name = player:get_player_name()
local head_liquid = mcl_playerinfo[name].head_submerged_in
minetest.debug("updating sky color for liquid:", head_liquid)
if head_liquid and minetest.get_item_group(head_liquid, "water") > 0 then
local biome_index = minetest.get_biome_data(player:get_pos()).biome
local biome_name = minetest.get_biome_name(biome_index)

View File

@ -44,62 +44,26 @@ end
local time = 0
local function get_head_submerged_node(head_pos)
local true_liquid = flowlib.liquid_at_exact(head_pos)
-- If player is on the edge of a liquid node, they should not be in it
-- This is to allow water columns to be climbed without drowning
-- Would be better if this were implemented in minetest i.e. players climbing outside of liquids
local pos_origin = vector.round(head_pos)--{x=math.floor(head_pos.x + 0.5), y=head_pos.y, z=math.floor(head_pos.z + 0.5)}
-- Amount in nodes to allow player to be inside liquid without being inside liquid
local inside_liquid_leeway = 0.06
local adjacent_liquid
if head_pos.x - pos_origin.x > 0.5 - inside_liquid_leeway then
adjacent_liquid = flowlib.liquid_at_exact({x=pos_origin.x+1, y=pos_origin.y, z=pos_origin.z}, {x=-0.5, y=head_pos.y - pos_origin.y, z=0})
elseif pos_origin.x - head_pos.x > 0.5 - inside_liquid_leeway then
adjacent_liquid = flowlib.liquid_at_exact({x=pos_origin.x-1, y=pos_origin.y, z=pos_origin.z}, {x= 0.5, y=head_pos.y - pos_origin.y, z=0})
elseif head_pos.z - pos_origin.z > 0.5 - inside_liquid_leeway then
adjacent_liquid = flowlib.liquid_at_exact({x=pos_origin.x, y=pos_origin.y, z=pos_origin.z+1}, {x=0, y=head_pos.y - pos_origin.y, z=-0.5})
elseif pos_origin.z - head_pos.z > 0.5 - inside_liquid_leeway then
adjacent_liquid = flowlib.liquid_at_exact({x=pos_origin.x, y=pos_origin.y, z=pos_origin.z-1}, {x=0, y=head_pos.y - pos_origin.y, z=0.5})
else
return true_liquid
end
-- Only use the adjacent node if it is air
if adjacent_liquid == nil then
return adjacent_liquid
else
return true_liquid
end
end
local function get_player_nodes(player)
local player_pos = player:get_pos()
local collisionbox = player:get_properties().collisionbox
local eye_height = player:get_properties().eye_height
local infotable = {
player_pos = player_pos,
collisionbox = collisionbox,
eye_height = eye_height,
}
local function get_player_nodes(player, infotable)
infotable.player_pos = player:get_pos()
infotable.collisionbox = player:get_properties().collisionbox
infotable.eye_height = player:get_properties().eye_height
local part_pos
part_pos = get_playerpart_pos("stand", player_pos, collisionbox, eye_height)
part_pos = get_playerpart_pos("stand", infotable.player_pos, infotable.collisionbox, infotable.eye_height)
infotable.node_stand = node_ok(part_pos).name
part_pos = get_playerpart_pos("head", player_pos, collisionbox, eye_height)
part_pos = get_playerpart_pos("head", infotable.player_pos, infotable.collisionbox, infotable.eye_height)
infotable.node_head = node_ok(part_pos).name
infotable.head_submerged_in = get_head_submerged_node(part_pos)
minetest.debug("Head in:", infotable.head_submerged_in)
part_pos = get_playerpart_pos("head_top", player_pos, collisionbox, eye_height)
part_pos = get_playerpart_pos("head_top", infotable.player_pos, infotable.collisionbox, infotable.eye_height)
infotable.node_head_top = node_ok(part_pos).name
part_pos = get_playerpart_pos("feet", player_pos, collisionbox, eye_height)
part_pos = get_playerpart_pos("feet", infotable.player_pos, infotable.collisionbox, infotable.eye_height)
infotable.node_feet = node_ok(part_pos).name
part_pos = get_playerpart_pos("stand_below", player_pos, collisionbox, eye_height)
part_pos = get_playerpart_pos("stand_below", infotable.player_pos, infotable.collisionbox, infotable.eye_height)
infotable.node_stand_below = node_ok(part_pos).name
return infotable
@ -123,7 +87,7 @@ minetest.register_globalstep(function(dtime)
for _,player in pairs(minetest.get_connected_players()) do
local name = player:get_player_name()
mcl_playerinfo[name] = get_player_nodes(player)
get_player_nodes(player, mcl_playerinfo[name])
end
end)

View File

@ -178,6 +178,35 @@ local player_props_normal = {
nametag_color = { r = 225, b = 225, a = 225, g = 225 }
}
local function get_head_submerged_node(head_pos)
local true_liquid = flowlib.liquid_at_exact(head_pos)
-- If player is on the edge of a liquid node, they should not be in it
-- This is to allow water columns to be climbed without drowning
-- Would be better if this were implemented in minetest i.e. players climbing outside of liquids
local pos_origin = vector.round(head_pos)--{x=math.floor(head_pos.x + 0.5), y=head_pos.y, z=math.floor(head_pos.z + 0.5)}
-- Amount in nodes to allow player to be inside liquid without being inside liquid
local inside_liquid_leeway = 0.06
local adjacent_liquid
if head_pos.x - pos_origin.x > 0.5 - inside_liquid_leeway then
adjacent_liquid = flowlib.liquid_at_exact({x=pos_origin.x+1, y=pos_origin.y, z=pos_origin.z}, {x=-0.5, y=head_pos.y - pos_origin.y, z=0})
elseif pos_origin.x - head_pos.x > 0.5 - inside_liquid_leeway then
adjacent_liquid = flowlib.liquid_at_exact({x=pos_origin.x-1, y=pos_origin.y, z=pos_origin.z}, {x= 0.5, y=head_pos.y - pos_origin.y, z=0})
elseif head_pos.z - pos_origin.z > 0.5 - inside_liquid_leeway then
adjacent_liquid = flowlib.liquid_at_exact({x=pos_origin.x, y=pos_origin.y, z=pos_origin.z+1}, {x=0, y=head_pos.y - pos_origin.y, z=-0.5})
elseif pos_origin.z - head_pos.z > 0.5 - inside_liquid_leeway then
adjacent_liquid = flowlib.liquid_at_exact({x=pos_origin.x, y=pos_origin.y, z=pos_origin.z-1}, {x=0, y=head_pos.y - pos_origin.y, z=0.5})
else
return true_liquid
end
-- Only use the adjacent node if it is air
if adjacent_liquid == nil then
return adjacent_liquid
else
return true_liquid
end
end
minetest.register_globalstep(function(dtime)
time = time + dtime
@ -407,13 +436,17 @@ minetest.register_globalstep(function(dtime)
set_bone_pos(player,"Body_Control", nil, vector.new(0, -player_vel_yaw + yaw, 0))
end
local underwater
if get_item_group(mcl_playerinfo[name].node_head, "water") ~= 0 and underwater ~= true then
local player_pos = player:get_pos()
local collisionbox = player:get_properties().collisionbox
local eye_height = player:get_properties().eye_height
local player_head_pos = mcl_playerinfo.get_playerpart_pos("head", player_pos, collisionbox, eye_height)
local current_head_submerged_node = get_head_submerged_node(player_head_pos)
if current_head_submerged_node ~= mcl_playerinfo[name].head_submerged_in then
mcl_playerinfo[name].head_submerged_in = current_head_submerged_node
-- force update skycolor when head liquid changes
mcl_weather.skycolor.update_sky_color()
local underwater = true
elseif get_item_group(mcl_playerinfo[name].node_head, "water") == 0 and underwater == true then
mcl_weather.skycolor.update_sky_color()
local underwater = false
else
mcl_playerinfo[name].head_submerged_in = current_head_submerged_node
end
elytra.last_yaw = player:get_look_horizontal()