1
0
Fork 0

Merge pull request 'better water visuals' (#2960) from better_visuals_water into master

Reviewed-on: MineClone2/MineClone2#2960
Reviewed-by: cora <cora@noreply.git.minetest.land>
This commit is contained in:
cora 2022-11-16 16:14:38 +00:00
commit 661424ad23
4 changed files with 83 additions and 13 deletions

View File

@ -1,7 +1,11 @@
local mods_loaded = false
local NIGHT_VISION_RATIO = 0.45
local water_color = "#0b4880"
function mcl_weather.set_sky_box_clear(player)
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
player:set_sky({
type = "regular",
sky_color = {
@ -16,6 +20,16 @@ function mcl_weather.set_sky_box_clear(player)
})
end
function mcl_weather.set_sky_color(player, def)
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
player:set_sky({
type = def.type,
sky_color = def.sky_color,
clouds = def.clouds,
})
end
mcl_weather.skycolor = {
-- Should be activated before do any effect.
active = true,
@ -96,6 +110,19 @@ mcl_weather.skycolor = {
local pos = player:get_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))
if minetest.get_item_group(minetest.get_node(vector.new(pos.x,pos.y+1.5,pos.z)).name, "water") ~= 0 then
player:set_sky({ type = "regular",
sky_color = {
day_sky = water_color,
day_horizon = water_color,
dawn_sky = water_color,
dawn_horizon = water_color,
night_sky = water_color,
night_horizon = water_color,
},
clouds = true,
})
end
if dim == "overworld" then
if (mcl_weather.state == "none") then
-- Clear weather
@ -108,7 +135,8 @@ mcl_weather.skycolor = {
local day_color = mcl_weather.skycolor.get_sky_layer_color(0.15)
local dawn_color = mcl_weather.skycolor.get_sky_layer_color(0.27)
local night_color = mcl_weather.skycolor.get_sky_layer_color(0.1)
player:set_sky({ type = "regular",
mcl_weather.set_sky_color(player, {
type = "regular",
sky_color = {
day_sky = day_color,
day_horizon = day_color,
@ -127,7 +155,8 @@ mcl_weather.skycolor = {
local day_color = mcl_weather.skycolor.get_sky_layer_color(0.5)
local dawn_color = mcl_weather.skycolor.get_sky_layer_color(0.75)
local night_color = mcl_weather.skycolor.get_sky_layer_color(0)
player:set_sky({ type = "regular",
mcl_weather.set_sky_color(player, {
type = "regular",
sky_color = {
day_sky = day_color,
day_horizon = day_color,
@ -178,7 +207,7 @@ mcl_weather.skycolor = {
}
local biometint = nether_sky[minetest.get_biome_name(minetest.get_biome_data(player:get_pos()).biome)]
player:set_sky({
mcl_weather.set_sky_color(player, {
type = "regular",
sky_color = {
day_sky = "#300808",

View File

@ -50,7 +50,7 @@ minetest.register_node("mcl_core:water_flowing", {
liquid_viscosity = WATER_VISC,
liquid_range = 7,
waving = 3,
post_effect_color = {a=209, r=0x03, g=0x3C, b=0x5C},
post_effect_color = {a=20, r=0x03, g=0x3C, b=0x5C},
groups = { water=3, liquid=3, puts_out_fire=1, not_in_creative_inventory=1, freezes=1, melt_around=1, dig_by_piston=1},
_mcl_blast_resistance = 100,
-- Hardness intentionally set to infinite instead of 100 (Minecraft value) to avoid problems in creative mode
@ -95,7 +95,7 @@ S("• When water is directly below lava, the water turns into stone."),
liquid_alternative_source = "mcl_core:water_source",
liquid_viscosity = WATER_VISC,
liquid_range = 7,
post_effect_color = {a=209, r=0x03, g=0x3C, b=0x5C},
post_effect_color = {a=60, r=0x03, g=0x3C, b=0x5C},
stack_max = 64,
groups = { water=3, liquid=3, puts_out_fire=1, freezes=1, not_in_creative_inventory=1, dig_by_piston=1},
_mcl_blast_resistance = 100,

View File

@ -3,6 +3,8 @@ mcl_playerplus = {
is_pressing_jump = {},
}
local hud_water = {}
local get_connected_players = minetest.get_connected_players
local dir_to_yaw = minetest.dir_to_yaw
local get_item_group = minetest.get_item_group
@ -25,6 +27,26 @@ local mcl_playerplus_internal = {}
local time = 0
local look_pitch = 0
local function calculate_water_depth(pos)
for i=1, 50 do
if get_item_group(minetest.get_node(vector.new(pos.x,pos.y+i,pos.z)).name, "water") == 0 then
return i
end
end
return 50
end
local function remove_water_hud(player)
if hud_water[player] then
mcl_weather.skycolor.update_sky_color()
for i=1, #hud_water[player] do
player:hud_remove(hud_water[player][i])
end
hud_water[player] = nil
end
end
local function player_collision(player)
local pos = player:get_pos()
@ -349,16 +371,16 @@ minetest.register_globalstep(function(dtime)
-- set head pitch and yaw when flying
local head_rot = vector.new(pitch - degrees(dir_to_pitch(player_velocity)) + 50, player_vel_yaw - yaw, 0)
set_bone_pos(player,"Head_Control", nil, head_rot)
-- sets eye height, and nametag color accordingly
set_properties(player, player_props_elytra)
-- control body bone when flying
local body_rot = vector.new((75 - degrees(dir_to_pitch(player_velocity))), -player_vel_yaw + yaw, 0)
set_bone_pos(player, "Body_Control", nil, body_rot)
elseif parent then
set_properties(player, player_props_riding)
local parent_yaw = degrees(parent:get_yaw())
local head_rot = vector.new(pitch, -limit_vel_yaw(yaw, parent_yaw) + parent_yaw, 0)
set_bone_pos(player, "Head_Control", nil, head_rot)
@ -367,10 +389,10 @@ minetest.register_globalstep(function(dtime)
-- controls head pitch when sneaking
local head_rot = vector.new(pitch, player_vel_yaw - yaw, player_vel_yaw - yaw)
set_bone_pos(player, "Head_Control", nil, head_rot)
-- sets eye height, and nametag color accordingly
set_properties(player, player_props_sneaking)
-- sneaking body conrols
set_bone_pos(player, "Body_Control", nil, 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
@ -378,10 +400,10 @@ minetest.register_globalstep(function(dtime)
is_swimming = true
local head_rot = vector.new(pitch - degrees(dir_to_pitch(player_velocity)) + 20, player_vel_yaw - yaw, 0)
set_bone_pos(player, "Head_Control", nil, head_rot)
-- sets eye height, and nametag color accordingly
set_properties(player, player_props_swimming)
-- control body bone when swimming
local body_rot = vector.new((75 + degrees(dir_to_pitch(player_velocity))), player_vel_yaw - yaw, 180)
set_bone_pos(player,"Body_Control", nil, body_rot)
@ -395,6 +417,25 @@ minetest.register_globalstep(function(dtime)
set_bone_pos(player,"Body_Control", nil, vector.new(0, -player_vel_yaw + yaw, 0))
end
if get_item_group(mcl_playerinfo[name].node_head, "water") ~= 0 then
if not hud_water[player] or hud_water[player] and calculate_water_depth(player:get_pos()) ~= #hud_water[player] then
remove_water_hud(player)
hud_water[player] = {}
for i=1, calculate_water_depth(player:get_pos()) do
table.insert(hud_water[player], player:hud_add({
hud_elem_type = "image",
text = "mcl_playerplus_water.png",
position = {x = 0.5, y = 0.5},
scale = {x = 32, y = 16},
offset = {x = 0, y = 0},
z_index = -1002,
}))
end
end
else
remove_water_hud(player)
end
elytra.last_yaw = player:get_look_horizontal()
-- Update jump status immediately since we need this info in real time.
-- WARNING: This section is HACKY as hell since it is all just based on heuristics.
@ -639,7 +680,7 @@ minetest.register_on_joinplayer(function(player)
jump_cooldown = -1, -- Cooldown timer for jumping, we need this to prevent the jump exhaustion to increase rapidly
}
mcl_playerplus.elytra[player] = {active = false, rocketing = 0, speed = 0}
-- Minetest bug: get_bone_position() returns all zeros vectors.
-- Workaround: call set_bone_position() one time first.
player:set_bone_position("Head_Control", vector.new(0, 6.75, 0))

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB