add snow accumulation and such

master
Jordach 2019-05-18 00:44:56 +01:00
parent 50ff69eb31
commit 749c23770a
12 changed files with 384 additions and 75 deletions

View File

@ -13,7 +13,7 @@ atmos.cloud = {}
atmos.cloud.density = {} -- overall cloud density
atmos.cloud.density.min = 0
atmos.cloud.density.max = 1
atmos.cloud.density.now = 0.6
atmos.cloud.density.now = 0.59
atmos.cloud.thicc = {}
atmos.cloud.thicc.min = 1 -- thiccness in nodes
@ -34,13 +34,40 @@ atmos.cloud.colour.alp = {} -- tune this when clouds get thiccer
atmos.cloud.colour.alp.min = 25
atmos.cloud.colour.alp.max = 229
function atmos.wind_to_vector(rads, mult) -- forwards only
function atmos.wind_to_vector(rads, mult)
local z2 = math.cos(rads) * mult
local x2 = (math.sin(rads) * -1) * mult
return {x=x2, z=z2}
end
atmos.current_weather = 3
function atmos.get_weather(pos)
local temp = mcore.get_heat_humidity_pos(pos)
local result
if atmos.cloud.density.now < 0.11 then
result = "clear"
elseif atmos.cloud.density.now >= 0.11 and atmos.cloud.density.now < 0.21 then
result = "light_cloud"
elseif atmos.cloud.density.now >= 0.21 and atmos.cloud.density.now < 0.36 then
result = "medium_cloud"
elseif atmos.cloud.density.now >= 0.36 and atmos.cloud.density.now < 0.61 then
result = "large_cloud"
elseif atmos.cloud.density.now >= 0.61 and atmos.cloud.density.now < 0.71 then
result = "cloudy"
elseif atmos.cloud.density.now >= 0.71 and atmos.cloud.density.now < 0.86 then
if temp < 3.3 then
result = "snow"
else
result = "rain"
end
else
if temp < 2 then
result = "hail"
else
result = "storm"
end
end
return result
end
-- load data into atmos2 from .atm configuration files:
local atmos_clear_weather = {}

View File

@ -72,6 +72,12 @@ minetest.register_abm({
if minetest.get_node_or_nil(pos).name ~= "core:snow" then
pos.y = pos.y - 1
minetest.add_node(pos,{name="core:grass"})
elseif minetest.get_node_or_nil(pos).name ~= "core:snow_medium" then
pos.y = pos.y - 1
minetest.add_node(pos,{name="core:grass"})
elseif minetest.get_node_or_nil(pos).name ~= "core:snowblock" then
pos.y = pos.y - 1
minetest.add_node(pos,{name="core:grass"})
end
end,
})

View File

@ -189,8 +189,7 @@ minetest.register_node("core:snow", {
{-0.5, -0.5, -0.5, 0.5, -0.25, 0.5},
},
},
groups = {crumbly = 3, falling_node = 1, puts_out_fire = 1, slippery=1},
groups = {crumbly=3, falling_node=1, puts_out_fire=1, slippery=1},
sounds = mcore.sound_snow;
walkable = false,
on_construct = function(pos)

View File

@ -449,6 +449,81 @@ function mcore.get_heat_humidity(player)
return nval_temp, nval_humid, latch
end
function mcore.get_heat_humidity_pos(pos)
local pposx = math.floor(pos.x)
local pposz = math.floor(pos.z)
local nobj_temp = nobj_temp or minetest.get_perlin(np_temp)
local nobj_humid = nobj_humid or minetest.get_perlin(np_humid)
local nval_temp = nobj_temp:get2d({x = pposx, y = pposz})
local nval_humid = nobj_humid:get2d({x = pposx, y = pposz})
local latch = false
if nval_humid > 100 then
nval_humid = 100
elseif nval_humid < 0 then
nval_humid = 0
end
nval_humid = math.floor(100 * (nval_humid/100))
nval_temp = math.floor(45 * (nval_temp/100)) + (nval_humid * 0.02)
if hudclock.month == 1 then
nval_temp = nval_temp - 20
elseif hudclock.month == 2 then
nval_temp = nval_temp - 15
elseif hudclock.month == 3 then
nval_temp = nval_temp - 10
elseif hudclock.month == 4 then
nval_temp = nval_temp - 5
elseif hudclock.month == 5 then
nval_temp = nval_temp + 0
elseif hudclock.month == 6 then
nval_temp = nval_temp + 5
elseif hudclock.month == 7 then
nval_temp = nval_temp + 5
elseif hudclock.month == 8 then
nval_temp = nval_temp + 0
elseif hudclock.month == 9 then
nval_temp = nval_temp - 5
elseif hudclock.month == 10 then
nval_temp = nval_temp - 10
elseif hudclock.month == 11 then
nval_temp = nval_temp - 15
elseif hudclock.month == 12 then
nval_temp = nval_temp - 20
end
local y = math.abs(pos.y) / 50000
-- altitude changes heat and humidity
if pos.y < 0.5 then -- heading into the underground increases heat
nval_temp = nval_temp + (10000 * y)
else -- going into the atmosphere reduces heat
nval_temp = nval_temp + (-1556 * y)
end
nval_humid = nval_humid + (-600 * y)
if nval_temp < -271 then
nval_temp = -271
nval_humid = 0
elseif nval_temp > 3000 then
nval_temp = 3000
nval_humid = 0
end
if nval_humid > 100 then
nval_humid = 100
elseif nval_humid < 0 then
nval_humid = 0
end
if nval_temp <= 4 then
latch = true
end
return nval_temp, nval_humid, latch
end
-- dofiles for loading files required by "core"
dofile(minetest.get_modpath("core").."/abm_timer.lua")
dofile(minetest.get_modpath("core").."/sounds.lua")

2
mods/environ/depends.txt Normal file
View File

@ -0,0 +1,2 @@
core
atmos

153
mods/environ/init.lua Normal file
View File

@ -0,0 +1,153 @@
-- A simple and straightfowards mod to add those little biome touches that don't exactly fit elsewhere
environ = {}
function environ.register_node_snow(lightname, medname, fullname, override, modname, lightmesh, medmesh, fullmesh)
end
function environ.register_nodebox_snow(lightname, medname, fullname, override, modname, lightbox, medbox, fullbox)
end
minetest.register_abm({
nodenames = {"group:snow_accum", "group:solid"},
interval = 45, --tick once every 45 seconds
chance = 10, -- do it to every 1/3 nodes
action = function(pos, node)
-- check if the local area is capable of having snowfall:
local weather = atmos.get_weather(pos)
if weather == "snow" or weather == "hail" then
-- get node registry of the node that snow will settle on
local nnode = minetest.registered_nodes[minetest.get_node(pos).name]
-- pre-init the variables we need to set information into
local slight, smed, sfull
local sdir = 0
-- where snow is going to fall position
local spos = table.copy(pos)
spos.y = spos.y + 1
-- get the name of the node so we can replace it with snow, or do nothing
local snode = minetest.get_node(spos).name
-- check if node can see the sky:
local light = minetest.get_node_light(spos, 0.5)
-- don't let snow fall since we can't actually get to the sky
if light == nil then
return
elseif light < 13 then
return
end
-- set some default snow, in case the node with either solid or snow_accum doesn't have a set node
slight = "core:snow"
smed = "core:snow_medium"
sfull = "core:snowblock"
-- replace the previous snow nodes if the node contains a replacement
if nnode._snow_layer_light ~= nil then
slight = nnode._snow_layer_light
end
if nnode._snow_layer_med ~= nil then
smed = nnode._snow_layer_med
end
if nnode._snow_layer_full ~= nil then
sfull = nnode._snow_layer_full
end
-- for nodes with facedir and nodeboxes or meshes, we want the fallen snow to match the rotation of the node,
-- but only for nodes with a matching facedir
if nnode._snow_facedir_whitelist ~= nil then
local fnode = minetest.get_node(pos).param2
if minetest.registered_nodes[slight].paramtype2 == "facedir" then
for k, v in pairs(nnode._snow_facedir_whitelist) do
if v == fnode then
sdir = fnode
end
end
elseif minetest.registered_nodes[smed].paramtype2 == "facedir" then
for k, v in pairs(nnode._snow_facedir_whitelist) do
if v == fnode then
sdir = fnode
end
end
elseif minetest.registered_nodes[sfull].paramtype2 == "facedir" then
for k, v in pairs(nnode._snow_facedir_whitelist) do
if v == fnode then
sdir = fnode
end
end
end
end
-- level each snow layer over time, help spread out the ABM overload
if snode == "air" then
minetest.after(math.random(0.5, 25.5), minetest.set_node, spos, {name = slight, param2 = sdir})
elseif snode == slight then
minetest.after(math.random(0.5, 25.5), minetest.set_node, spos, {name = smed, param2 = sdir})
elseif snode == smed then
minetest.after(math.random(0,5, 25.5), minetest.set_node, spos, {name = sfull, param2 = sdir})
end
elseif weather == "rain" or weather == "storm" then
end
end,
})
minetest.register_node(":core:snow_medium", {
tiles = {"core_snow.png"},
inventory_image = "core_snowball.png",
description = "Snow",
wield_image = "core_snowball.png",
paramtype = "light",
buildable_to = true,
floodable = true,
drawtype = "nodebox",
drop = "core:snow 2",
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.0625, 0.5},
},
},
groups = {crumbly=3, falling_node=1, puts_out_fire=1, slippery=1},
sounds = mcore.sound_snow,
walkable = false,
on_construct = function(pos)
pos.y = pos.y - 1
if minetest.get_node(pos).name == "core:grass" then
minetest.set_node(pos, {name = "core:grass_snow"})
end
end,
_snow_melts_to = "core:snow",
})
minetest.register_node("environ:puddle", {
description = "A puddle, localised entirely in your hands,\nat this time of day, and at this time of year?",
tiles = {"core_water.png"},
paramtype = "light",
buildable_to = true,
floodable = true,
drawtype = "nodebox",
walkable = false,
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, -0.5+0.015625, 0.5},
},
},
groups = {falling_node=1, puts_out_fire=1},
})
minetest.register_node("environ:icicles", {
description = "Icicles, not for backstabbing.",
tiles = {"environ_icicles.png"},
drawtype = "mesh",
groups = {cracky=3},
sounds = mcore.sound_glass,
--drawtype = "mesh",
--mesh = "environ_icicles.b3d",
})

79
mods/environ/lvm.lua_ Normal file
View File

@ -0,0 +1,79 @@
-- Incomplete prototype LVM version of snow accumulation and puddle forming;
--[[
local environ_air = minetest.get_content_id("air")
local environ_snow_accum_nodes = {}
local environ_puddle_nodes = {}
local function get_snow_nodes()
for node, tab in pairs(minetest.registered_nodes) do
if tab.groups.snow_accum ~= nil then
environ_snow_accum_nodes[node] = {}
environ_snow_accum_nodes[node].node = minetest.get_content_id(node)
-- set default snow nodes here:
environ_snow_accum_nodes[node].light = minetest.get_content_id("core:snow")
environ_snow_accum_nodes[node].med = minetest.get_content_id("core:snow_medium")
environ_snow_accum_nodes[node].full = minetest.get_content_id("core:snowblock")
-- update with node specific nodes
if tab._snow_layer_light ~= nil then
environ_snow_accum_nodes[node].light = minetest.get_content_id(tab._snow_layer_light)
end
if tab._snow_layer_med ~= nil then
environ_snow_accum_nodes[node].med = minetest.get_content_id(tab._snow_layer_med)
end
if tab._snow_layer_full ~= nil then
environ_snow_accum_nodes[node].full = minetest.get_content_id(tab._snow_layer_full)
end
--soonTM: add whitelisted facedir support
elseif tab.groups.solid ~= nil then
environ_snow_accum_nodes[node] = {}
environ_snow_accum_nodes[node].node = minetest.get_content_id(node)
-- set default snow nodes here:
environ_snow_accum_nodes[node].light = minetest.get_content_id("core:snow")
environ_snow_accum_nodes[node].med = minetest.get_content_id("core:snow_medium")
environ_snow_accum_nodes[node].full = minetest.get_content_id("core:snowblock")
-- update with node specific nodes
if tab._snow_layer_light ~= nil then
environ_snow_accum_nodes[node].light = minetest.get_content_id(tab._snow_layer_light)
end
if tab._snow_layer_med ~= nil then
environ_snow_accum_nodes[node].med = minetest.get_content_id(tab._snow_layer_med)
end
if tab._snow_layer_full ~= nil then
environ_snow_accum_nodes[node].full = minetest.get_content_id(tab._snow_layer_full)
end
end
end
end
minetest.after(1, get_snow_nodes)
local function weather_event()
for _, player in ipairs(minetest.get_connected_players()) do
local pos = player:get_pos()
local vm = minetest.get_voxel_manip()
local minp, maxp = vm:read_from_map(
{x = pos.x - 16, y = pos.y - 16, z = pos.z - 16},
{x = pos.x + 16, y = pos.y + 16, z = pos.z + 16}
)
local area = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
local data = vm:get_data()
local param2 = vm:get_param2_data()
local light = vm:get_light_data()
for z=-16, 16 do
for y=-16, 16 do
for x=-16, 16 do
local vi = area:index(x, y, z)
end
end
end
end
end
--]]

View File

@ -48,27 +48,27 @@ function hudinfo.player_env_data(player)
local weather_str = ""
local atmw = atmos.current_weather
local atmw = atmos.get_weather(pos)
if atmw == 1 then
if atmw == "clear" then
weather_str = "Clear,"
elseif atmw == 2 then
elseif atmw == "light_cloud" then
weather_str = "Light Clouds,"
elseif atmw == 3 then
elseif atmw == "medium_cloud" then
weather_str = "Minor Clouds,"
elseif atmw == 4 then
elseif atmw == "large_cloud" then
weather_str = "Medium Clouds,"
elseif atmw == 5 then
elseif atmw == "cloudy" then
weather_str = "Cloudy,"
elseif latch and atmw == 6 then
elseif atmw == "snow" then
weather_str = "Snowfall,"
elseif atmw == 6 then
elseif atmw == "rain" then
weather_str = "Downpour,"
elseif atmw == 7 then
elseif atmw == "storm" then
weather_str = "Thunderstorm,"
elseif atmw == 8 then
elseif atmw == "snow" then
weather_str = "Snowfall,"
elseif atmw == 9 then
elseif atmw == "hail" then
weather_str = "Hailstorm,"
end

View File

@ -62,7 +62,7 @@ minetest.register_node("naturum:soil", {
description = "Farmland",
tiles = {"core_dirt.png^farming_soil.png", "core_dirt.png"},
sounds = mcore.sound_dirt,
groups = {crumbly=3, soil=1, solid=1},
groups = {crumbly=3, soil=1},
drop = "core:dirt",
_waila_texture = minetest.inventorycube(
"core_dirt.png^farming_soil.png",
@ -94,7 +94,7 @@ minetest.register_node("naturum:soil_wet", {
description = "Wet Farmland",
tiles = {"core_dirt.png^farming_soil_wet.png", "core_dirt.png^farming_soil_wet_side.png"},
sounds = mcore.sound_dirt,
groups = {crumbly=3, soil=1, solid=1},
groups = {crumbly=3, soil=1},
drop = "core:dirt",
_waila_texture= minetest.inventorycube(
"core_dirt.png^farming_soil_wet.png",

View File

@ -25,66 +25,33 @@ minetest.register_globalstep(function(dtime)
for _, player in ipairs(minetest.get_connected_players()) do
local player_name = player:get_player_name()
local heat, humid, latch = mcore.get_heat_humidity(player)
local ppos = player:get_pos()
local pposy = math.floor(ppos.y) + 2 -- Precipitation when swimming
if pposy >= YLIMIT then
local precip = false
local freeze = false
local hail = false
if atmos.current_weather == 6 and heat <= 4 then
local weather = atmos.get_weather(ppos)
local precip, freeze, hail
if weather == "snow" then
precip = true
freeze = true
hail = false
elseif atmos.current_weather == 6 or atmos.current_weather == 7 then
if humid > 5 and heat < 35 then
precip = true
freeze = false
hail = false
end
elseif atmos.current_weather == 9 and humid > 5 and heat < 1 then
elseif weather == "rain" then
precip = true
freeze = false
hail = false
elseif weather == "storm" then
precip = true
freeze = false
hail = false
elseif weather == "hail" then
precip = true
freeze = false
hail = true
elseif atmos.current_weather == 8 and humid > 5 and heat < 4 then
precip = true
freeze = true
hail = false
else
precip = false
freeze = false
hail = false
end
-- Check if player is outside
local outside = minetest.get_node_light(ppos, 0.5) == 15
local outside = minetest.get_node_light({x=ppos.x, y=ppos.y + 1, z=ppos.z}, 0.5) == 15
if not precip or not outside or freeze then
if handles[player_name] then
@ -102,7 +69,7 @@ minetest.register_globalstep(function(dtime)
minetest.add_particle({
pos = {
x = ppos.x - 24 + math.random(0, 47),
y = ppos.y + 8 + math.random(0, 1),
y = ppos.y + 8 + math.random(0, 8),
z = ppos.z - 20 + math.random(0, 47)
},
vel = {
@ -122,12 +89,11 @@ minetest.register_globalstep(function(dtime)
end
elseif hail then
for flake = 1, DROPS-48 do
minetest.add_particle({
pos = {
x = ppos.x - 8 + math.random(0, 16),
y = ppos.y + 8 + math.random(0, 5),
y = ppos.y + 8 + math.random(0, 8),
z = ppos.z - 8 + math.random(0, 16)
},
vel = {
@ -152,7 +118,7 @@ minetest.register_globalstep(function(dtime)
minetest.add_particle({
pos = {
x = ppos.x - 8 + math.random(0, 16),
y = ppos.y + 8 + math.random(0, 5),
y = ppos.y + 8 + math.random(0, 8),
z = ppos.z - 8 + math.random(0, 16)
},
vel = {

View File

@ -4,8 +4,8 @@
--[[
VHS is designed for a single mod to house and contain everything from UX, UI,
and how sounds are to be implemented. With a single mod providing sounds,
UI appearances, it simplifies everything.
and how sounds are to be implemented for UX and UI interactions.
With a single mod providing sounds, UI appearances, it simplifies everything.
Function calls:
@ -19,12 +19,14 @@
vhs.get_inventory_bg(player_ref)
vhs.get_notification_sound(player_ref)
vhs.get_click_sound(player_ref)
vhs.get_toast_tune(player_ref)
Gets the current filename for the currently used texture or sounds.
vhs.get_inv_slot_color(player_ref)
Gets the current colours used to set the inventory slots.
Returns as a table: {
Returns as a table:
{
slot =
}
]]--

View File

@ -219,7 +219,7 @@ local function draw_hud(player)
-- if we're not use the origin mods name, capitalise it, but doesn't convert underscores
if found_name ~= true then
local stringy = node.mod_origin
player:hud_change(player_huds[pname].modname, "text", stringy:sub(1,1):upper()..s:sub(2))
player:hud_change(player_huds[pname].modname, "text", stringy:sub(1,1):upper()..stringy:sub(2))
end
-- dependancy-less waila aliases override the dependancy method