forked from VoxeLibre/VoxeLibre
Skybox now fully uses new underwater checks
This commit is contained in:
parent
cebf6b13da
commit
fbe99ef3eb
|
@ -153,7 +153,7 @@ end
|
||||||
flowlib.move_centre = move_centre
|
flowlib.move_centre = move_centre
|
||||||
|
|
||||||
--BEGIN getCornerLevel
|
--BEGIN getCornerLevel
|
||||||
local function get_corner_level(x, z, cur_liquid, neighbors)
|
local function get_corner_level(x, z, c_flowing, c_source, neighbors)
|
||||||
local sum = 0
|
local sum = 0
|
||||||
local count = 0
|
local count = 0
|
||||||
local air_count = 0
|
local air_count = 0
|
||||||
|
@ -163,10 +163,10 @@ local function get_corner_level(x, z, cur_liquid, neighbors)
|
||||||
if neighbor_data.top_is_same_liquid then
|
if neighbor_data.top_is_same_liquid then
|
||||||
return 0.5 --- REPLACE returns
|
return 0.5 --- REPLACE returns
|
||||||
end
|
end
|
||||||
if neighbor_data.content == cur_liquid.c_source then
|
if neighbor_data.content == c_source then
|
||||||
return 0.5
|
return 0.5
|
||||||
end
|
end
|
||||||
if neighbor_data.content == cur_liquid.c_flowing then
|
if neighbor_data.content == c_flowing then
|
||||||
sum = sum + neighbor_data.level
|
sum = sum + neighbor_data.level
|
||||||
count = count + 1
|
count = count + 1
|
||||||
elseif neighbor_data.content == "air" then
|
elseif neighbor_data.content == "air" then
|
||||||
|
@ -198,13 +198,13 @@ local function get_liquid_corner_heights(pos)
|
||||||
|
|
||||||
-- BEGIN prepareLiquidNodeDrawing
|
-- BEGIN prepareLiquidNodeDrawing
|
||||||
cur_liquid.content = node.name
|
cur_liquid.content = node.name
|
||||||
cur_liquid.c_flowing = ndef.liquid_alternative_flowing
|
local c_flowing = ndef.liquid_alternative_flowing
|
||||||
cur_liquid.c_source = ndef.liquid_alternative_source
|
local c_source = ndef.liquid_alternative_source
|
||||||
cur_liquid.top_is_same_liquid = (node_above.name == cur_liquid.c_flowing or node_above.name == cur_liquid.c_source)
|
cur_liquid.top_is_same_liquid = (node_above.name == c_flowing or node_above.name == c_source)
|
||||||
-- cur_liquid.draw_bottom and lighting skipped
|
-- cur_liquid.draw_bottom and lighting skipped
|
||||||
-- END prepareLiquidNodeDrawing
|
-- END prepareLiquidNodeDrawing
|
||||||
|
|
||||||
local c_flowing_ndef = registered_nodes[cur_liquid.c_flowing]
|
local c_flowing_ndef = registered_nodes[c_flowing]
|
||||||
|
|
||||||
--BEGIN getLiquidNeighborhood
|
--BEGIN getLiquidNeighborhood
|
||||||
local range = math.max(1, math.min(c_flowing_ndef.liquid_range, 8))
|
local range = math.max(1, math.min(c_flowing_ndef.liquid_range, 8))
|
||||||
|
@ -215,29 +215,25 @@ local function get_liquid_corner_heights(pos)
|
||||||
}
|
}
|
||||||
for w = -1,1 do
|
for w = -1,1 do
|
||||||
for u = -1,1 do
|
for u = -1,1 do
|
||||||
neighbor = neighbors[w+2][u+2]
|
local neighbor = neighbors[w+2][u+2]
|
||||||
local neighbor_node = get_node({x=pos.x + u, y=pos.y, z=pos.z + w})
|
local neighbor_node = get_node({x=pos.x + u, y=pos.y, z=pos.z + w})
|
||||||
neighbor.content = neighbor_node.name
|
neighbor.content = neighbor_node.name
|
||||||
neighbor.level = -0.5
|
neighbor.level = -0.5
|
||||||
neighbor.is_same_liquid = false
|
neighbor.is_same_liquid = false
|
||||||
neighbor.top_is_same_liquid = false
|
neighbor.top_is_same_liquid = false
|
||||||
|
|
||||||
if neighbor.content == cur_liquid.c_source then
|
if neighbor.content == c_source then
|
||||||
neighbor.is_same_liquid = true
|
neighbor.is_same_liquid = true
|
||||||
neighbor.level = 0.5
|
neighbor.level = 0.5
|
||||||
elseif neighbor.content == cur_liquid.c_flowing then
|
elseif neighbor.content == c_flowing then
|
||||||
neighbor.is_same_liquid = true
|
neighbor.is_same_liquid = true
|
||||||
local liquid_level = bit.band(neighbor_node.param2, 7)
|
local liquid_level = bit.band(neighbor_node.param2, 7)
|
||||||
if liquid_level <= (8 - range) then
|
liquid_level = math.max(liquid_level - (8 - range), 0)
|
||||||
liquid_level = 0
|
|
||||||
else
|
|
||||||
liquid_level = liquid_level - (8 - range)
|
|
||||||
end
|
|
||||||
neighbor.level = (-0.5 + (liquid_level + 0.5) / range)
|
neighbor.level = (-0.5 + (liquid_level + 0.5) / range)
|
||||||
end
|
end
|
||||||
if neighbor.content ~= "ignore" then
|
if neighbor.content ~= "ignore" then
|
||||||
local above_neighbor_node = get_node({x=pos.x + u, y=pos.y + 1, z=pos.z + w})
|
local above_neighbor_node = get_node({x=pos.x + u, y=pos.y + 1, z=pos.z + w})
|
||||||
if above_neighbor_node.name == cur_liquid.c_source or above_neighbor_node.name == cur_liquid.c_flowing then
|
if above_neighbor_node.name == c_source or above_neighbor_node.name == c_flowing then
|
||||||
neighbor.top_is_same_liquid = true
|
neighbor.top_is_same_liquid = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -249,7 +245,7 @@ local function get_liquid_corner_heights(pos)
|
||||||
--BEGIN calculateCornerLevels
|
--BEGIN calculateCornerLevels
|
||||||
for z=1,2 do
|
for z=1,2 do
|
||||||
for x=1,2 do
|
for x=1,2 do
|
||||||
cur_liquid.corner_levels[z][x] = get_corner_level(x, z, cur_liquid, neighbors)
|
cur_liquid.corner_levels[z][x] = get_corner_level(x, z, c_flowing, c_source, neighbors)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--END calculateCornerLevels
|
--END calculateCornerLevels
|
||||||
|
@ -272,11 +268,55 @@ local function get_liquid_corner_heights(pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--first 3 vertices are connected, so are last 3
|
--first 3 vertices are connected, so are last 2 and first
|
||||||
|
|
||||||
--END drawLiquidTop
|
--END drawLiquidTop
|
||||||
return vertices
|
return vertices
|
||||||
end
|
end
|
||||||
|
|
||||||
flowlib.get_liquid_corner_heights = get_liquid_corner_heights
|
local function get_liquid_height(pos_origin, pos_offset)
|
||||||
|
local corner_heights = get_liquid_corner_heights(pos_origin)
|
||||||
|
if corner_heights == nil then return end
|
||||||
|
-- order: -+ ++ +- --
|
||||||
|
minetest.debug("offsets: ", pos_offset.x, pos_offset.z)
|
||||||
|
if pos_offset.x + pos_offset.z > 0 then
|
||||||
|
-- first triangle
|
||||||
|
pos_offset = {x=0.5, y=0, z=0.5} - pos_offset
|
||||||
|
local height_centre = corner_heights[2].y
|
||||||
|
local height_x = corner_heights[1].y
|
||||||
|
local height_z = corner_heights[3].y
|
||||||
|
local height = height_centre + (height_x - height_centre) * pos_offset.x + (height_z - height_centre) * pos_offset.z
|
||||||
|
return height + pos_origin.y
|
||||||
|
else
|
||||||
|
-- second triangle
|
||||||
|
pos_offset = {x=0.5, y=0, z=0.5} + pos_offset
|
||||||
|
local height_centre = corner_heights[4].y
|
||||||
|
local height_x = corner_heights[3].y
|
||||||
|
local height_z = corner_heights[1].y
|
||||||
|
local height = height_centre + (height_x - height_centre) * pos_offset.x + (height_z - height_centre) * pos_offset.z
|
||||||
|
minetest.debug(height_centre, height_x, height_z, pos_offset.x, pos_offset.z, height)
|
||||||
|
return height + pos_origin.y
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function liquid_at_exact(pos, pos_offset)
|
||||||
|
local pos_origin = vector.round(pos)
|
||||||
|
if pos_offset == nil then
|
||||||
|
pos_offset = pos - pos_origin
|
||||||
|
end
|
||||||
|
local liq_height = get_liquid_height(pos_origin, pos_offset)
|
||||||
|
if liq_height == nil then return nil end
|
||||||
|
minetest.debug("lae", d, pos_offset.y, pos_origin.y, liq_height)
|
||||||
|
if liq_height > (pos_offset.y + pos_origin.y) then
|
||||||
|
return minetest.get_node(pos_origin).name
|
||||||
|
else
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
flowlib.get_liquid_corner_heights = get_liquid_corner_heights
|
||||||
|
flowlib.get_liquid_height = get_liquid_height
|
||||||
|
flowlib.liquid_at_exact = liquid_at_exact
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ local mg_name = minetest.get_mapgen_setting("mg_name")
|
||||||
|
|
||||||
function mcl_weather.set_sky_box_clear(player, sky, fog)
|
function mcl_weather.set_sky_box_clear(player, sky, fog)
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
if minetest.get_item_group(minetest.get_node(vector.new(pos.x,pos.y+1.5,pos.z)).name, "water") ~= 0 then return end
|
if mcl_player.is_head_in_water(player) then return end
|
||||||
local sc = {
|
local sc = {
|
||||||
day_sky = "#7BA4FF",
|
day_sky = "#7BA4FF",
|
||||||
day_horizon = "#C0D8FF",
|
day_horizon = "#C0D8FF",
|
||||||
|
@ -39,7 +39,7 @@ end
|
||||||
|
|
||||||
function mcl_weather.set_sky_color(player, def)
|
function mcl_weather.set_sky_color(player, def)
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
if minetest.get_item_group(minetest.get_node(vector.offset(pos, 0, 1.5, 0)).name, "water") ~= 0 then return end
|
if mcl_player.is_head_in_water(player) then return end
|
||||||
player:set_sky({
|
player:set_sky({
|
||||||
type = def.type,
|
type = def.type,
|
||||||
sky_color = def.sky_color,
|
sky_color = def.sky_color,
|
||||||
|
@ -152,13 +152,16 @@ mcl_weather.skycolor = {
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
local dim = mcl_worlds.pos_to_dimension(pos)
|
local dim = mcl_worlds.pos_to_dimension(pos)
|
||||||
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 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))
|
||||||
if mcl_player.is_head_in_water(player) then
|
local name = player:get_player_name()
|
||||||
|
local head_liquid = mcl_playerinfo[name].head_submerged_in
|
||||||
|
minetest.debug("Skycolor update:", 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_index = minetest.get_biome_data(player:get_pos()).biome
|
||||||
local biome_name = minetest.get_biome_name(biome_index)
|
local biome_name = minetest.get_biome_name(biome_index)
|
||||||
local biome = minetest.registered_biomes[biome_name]
|
local biome = minetest.registered_biomes[biome_name]
|
||||||
if biome then water_color = biome._mcl_waterfogcolor end
|
if biome then water_color = biome._mcl_waterfogcolor end
|
||||||
if not biome then water_color = "#3F76E4" end
|
if not biome then water_color = "#3F76E4" end
|
||||||
if checkname == "mclx_core:river_water_source" or checkname == "mclx_core:river_water_flowing" then water_color = "#0084FF" end
|
if head_liquid == "mclx_core:river_water_source" or head_liquid == "mclx_core:river_water_flowing" then water_color = "#0084FF" end
|
||||||
player:set_sky({ type = "regular",
|
player:set_sky({ type = "regular",
|
||||||
sky_color = {
|
sky_color = {
|
||||||
day_sky = water_color,
|
day_sky = water_color,
|
||||||
|
|
|
@ -189,7 +189,11 @@ end
|
||||||
|
|
||||||
|
|
||||||
function mcl_player.is_head_in_water(player)
|
function mcl_player.is_head_in_water(player)
|
||||||
return minetest.get_item_group(mcl_playerinfo[player:get_player_name()].node_head, "water") ~= 0
|
--return minetest.get_item_group(mcl_playerinfo[player:get_player_name()].node_head, "water") ~= 0
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local submerged_liquid = mcl_playerinfo[name].head_submerged_in
|
||||||
|
if submerged_liquid == nil then return end
|
||||||
|
return minetest.get_item_group(submerged_liquid, "water")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Update appearance when the player joins
|
-- Update appearance when the player joins
|
||||||
|
|
|
@ -62,6 +62,8 @@ local function get_player_nodes(player)
|
||||||
|
|
||||||
part_pos = get_playerpart_pos("head", player_pos, collisionbox, eye_height)
|
part_pos = get_playerpart_pos("head", player_pos, collisionbox, eye_height)
|
||||||
infotable.node_head = node_ok(part_pos).name
|
infotable.node_head = node_ok(part_pos).name
|
||||||
|
minetest.debug("head in water:", flowlib.liquid_at_exact(part_pos))
|
||||||
|
infotable.head_submerged_in = flowlib.liquid_at_exact(part_pos)
|
||||||
|
|
||||||
part_pos = get_playerpart_pos("head_top", player_pos, collisionbox, eye_height)
|
part_pos = get_playerpart_pos("head_top", player_pos, collisionbox, eye_height)
|
||||||
infotable.node_head_top = node_ok(part_pos).name
|
infotable.node_head_top = node_ok(part_pos).name
|
||||||
|
@ -69,6 +71,7 @@ local function get_player_nodes(player)
|
||||||
part_pos = get_playerpart_pos("feet", player_pos, collisionbox, eye_height)
|
part_pos = get_playerpart_pos("feet", player_pos, collisionbox, eye_height)
|
||||||
|
|
||||||
local lch = flowlib.get_liquid_corner_heights(part_pos)
|
local lch = flowlib.get_liquid_corner_heights(part_pos)
|
||||||
|
local lh = flowlib.get_liquid_height(vector.round(part_pos), part_pos - vector.round(part_pos))
|
||||||
--infotable.debug_markers = mcl_playerinfo[player:get_player_name()].debug_markers
|
--infotable.debug_markers = mcl_playerinfo[player:get_player_name()].debug_markers
|
||||||
--minetest.debug("Debug markers: ", infotable.debug_markers)
|
--minetest.debug("Debug markers: ", infotable.debug_markers)
|
||||||
if lch then
|
if lch then
|
||||||
|
@ -84,6 +87,9 @@ local function get_player_nodes(player)
|
||||||
if lch then
|
if lch then
|
||||||
minetest.add_entity(vector.add(vector.round(part_pos), vector.divide(lch[i], 1)), "mcl_playerinfo:debug_marker")
|
minetest.add_entity(vector.add(vector.round(part_pos), vector.divide(lch[i], 1)), "mcl_playerinfo:debug_marker")
|
||||||
end
|
end
|
||||||
|
if lh then
|
||||||
|
minetest.add_entity({x=part_pos.x, y=lh, z=part_pos.z}, "mcl_playerinfo:debug_marker")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
infotable.node_feet = node_ok(part_pos).name
|
infotable.node_feet = node_ok(part_pos).name
|
||||||
|
|
Loading…
Reference in New Issue