From b769c03b620a36d7e048b9ac0712de08e0625307 Mon Sep 17 00:00:00 2001 From: LeMagnesium Date: Wed, 3 Aug 2016 18:05:16 +0200 Subject: [PATCH] [snow] Update --- mods/snow/aliases.lua | 3 - mods/snow/init.lua | 70 +++--- mods/snow/models/sled.png | Bin 2952 -> 4168 bytes .../other_textures/snow_snow_cobble.png_01 | Bin 570 -> 788 bytes mods/snow/src/abms.lua | 51 ++-- mods/snow/src/aliases.lua | 3 +- mods/snow/src/falling_snow.lua | 165 +++++++++---- mods/snow/src/mapgen.lua | 91 +++++-- mods/snow/src/mapgen_v6.lua | 196 ++++++++++----- mods/snow/src/mapgen_v7.lua | 20 +- mods/snow/src/nodes.lua | 31 ++- mods/snow/src/sled.lua | 26 +- mods/snow/src/snowball.lua | 107 +++++--- mods/snow/src/util.lua | 228 ++++++++++++------ 14 files changed, 661 insertions(+), 330 deletions(-) delete mode 100755 mods/snow/aliases.lua mode change 100755 => 100644 mods/snow/models/sled.png mode change 100755 => 100644 mods/snow/other_textures/snow_snow_cobble.png_01 diff --git a/mods/snow/aliases.lua b/mods/snow/aliases.lua deleted file mode 100755 index a6c8a9ce..00000000 --- a/mods/snow/aliases.lua +++ /dev/null @@ -1,3 +0,0 @@ -minetest.register_alias("snow:needles", "default:pine_needles") -minetest.register_alias("snow:leaves", "default:pine_needles") -minetest.register_alias("snow:sapling_pine", "default:pine_sapling") diff --git a/mods/snow/init.lua b/mods/snow/init.lua index f605db0d..b7127cf2 100755 --- a/mods/snow/init.lua +++ b/mods/snow/init.lua @@ -39,45 +39,47 @@ http://github.com/Splizard/minetest-mod-snow/ -- Original Lua Files ---dofile(minetest.get_modpath("snow").."/util.lua") ---dofile(minetest.get_modpath("snow").."/mapgen.lua") ---dofile(minetest.get_modpath("snow").."/sled.lua") +--dofile(modpath.."/util.lua") +--dofile(modpath.."/mapgen.lua") +--dofile(modpath.."/sled.lua") -- "falling_snow.lua" disabled since weather functions minetest.get_heat(pos) and minetest.get_humidity(pos) -- have been removed from Minetest. -- Until something else can be figured out, use paramat's "Snowdrift" mod instead. --- dofile(minetest.get_modpath("snow").."/falling_snow.lua") +-- dofile(modpath.."/falling_snow.lua") -- Original init.lua File Broken into Smaller Files --- dofile(minetest.get_modpath("snow").."/src/abms.lua") -dofile(minetest.get_modpath("snow").."/src/aliases.lua") -dofile(minetest.get_modpath("snow").."/src/crafting.lua") -dofile(minetest.get_modpath("snow").."/src/snowball.lua") +local modpath = minetest.get_modpath("snow") +dofile(modpath.."/src/abms.lua") +dofile(modpath.."/src/aliases.lua") +dofile(modpath.."/src/crafting.lua") -- The formspec menu didn't work when util.lua was the very first "dofile" so I moved -- it and all the other original "dofiles", in order, to the bottom of the list. ~ LazyJ -- Minetest would crash if the mapgen was called upon before the rest of other snow lua files so -- I put it lower on the list and that seems to do the trick. ~ LazyJ -dofile(minetest.get_modpath("snow").."/src/util.lua") +dofile(modpath.."/src/util.lua") +dofile(modpath.."/src/snowball.lua") -- To get Xmas tree saplings, the "christmas_content", true or false, in "util.lua" has to be determined first. -- That means "nodes.lua", where the saplings are controlled, has to come after "util.lua". ~ LazyJ -dofile(minetest.get_modpath("snow").."/src/nodes.lua") -dofile(minetest.get_modpath("snow").."/aliases.lua") -dofile(minetest.get_modpath("snow").."/src/basic_stairs_slabs.lua") --- dofile(minetest.get_modpath("snow").."/src/mapgen.lua") -dofile(minetest.get_modpath("snow").."/src/sled.lua") --- dofile(minetest.get_modpath("snow").."/src/falling_snow.lua") +dofile(modpath.."/src/nodes.lua") +dofile(modpath.."/src/basic_stairs_slabs.lua") +-- dofile(modpath.."/src/mapgen.lua") +dofile(modpath.."/src/sled.lua") +-- dofile(modpath.."/src/falling_snow.lua") -- Check for "MoreBlocks". If not found, skip this next "dofile". -if minetest.get_modpath("moreblocks") then +if rawget(_G, "stairsplus") +and minetest.get_modpath("moreblocks") then - dofile(minetest.get_modpath("snow").."/src/stairsplus.lua") + dofile(modpath.."/src/stairsplus.lua") end +local is_uneven --This function places snow checking at the same time for snow level and increasing as needed. --This also takes into account sourrounding snow and makes snow even. function snow.place(pos) @@ -90,12 +92,11 @@ function snow.place(pos) return end - local bnode = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}) if node.name == "default:snow" then local level = minetest.get_node_level(pos) if level < 63 then - if minetest.get_item_group(bnode.name, "leafdecay") == 0 - and not snow.is_uneven(pos) then + if minetest.get_item_group(minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name, "leafdecay") == 0 + and not is_uneven(pos) then minetest.sound_play("default_snow_footstep", {pos=pos}) minetest.add_node_level(pos, 7) end @@ -111,7 +112,7 @@ function snow.place(pos) end end elseif node.name ~= "default:ice" - and bnode.name ~= "air" then + and minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name ~= "air" then local data = minetest.registered_nodes[node.name] local drawtype = data.drawtype if drawtype == "normal" @@ -137,13 +138,11 @@ end -- Checks if the snow level is even at any given pos. -- Smooth Snow -local function is_uneven(pos) +local function uneven(pos) local num = minetest.get_node_level(pos) local get_node = minetest.get_node local add_node = minetest.add_node - local found local foundx - local foundy local foundz for z = -1,1 do for x = -1,1 do @@ -164,7 +163,6 @@ local function is_uneven(pos) if not (x == 0 and z == 0) and node.name == "default:snow" and minetest.get_node_level(p) < num then - found = true foundx = x foundz = z elseif node.name == "air" @@ -176,17 +174,27 @@ local function is_uneven(pos) end end end - if found then + if foundx then local p = {x=pos.x+foundx, y=pos.y, z=pos.z+foundz} - if is_uneven(p) ~= true then + if not is_uneven(p) then minetest.add_node_level(p, 7) end return true end end -function snow.is_uneven(pos) - if snow.smooth_snow then - return is_uneven(pos) - end +if snow.smooth_snow then + is_uneven = uneven +else + is_uneven = function() end end + +snow.register_on_configuring(function(name, v) + if name == "smooth_snow" then + if v then + is_uneven = uneven + else + is_uneven = function() end + end + end +end) diff --git a/mods/snow/models/sled.png b/mods/snow/models/sled.png old mode 100755 new mode 100644 index 2c832d85fe3af91622764f31c0d839c624c212f7..d270b6a6392420e1826b8c40d72c4e4b79a5c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UOmDDF zcd<`+u}^ukPkXUXe6vt`v`~AtQhc;heza47w^o0$R)MxwgSJ+PwpWO?SdF$_i?v;k zwO*09W0tp>u=Aa>^PaTyp|z4fKJ^M9qf^QF4Z|yYr{J z^QXM?sJ!&4y!5HP^sB%0tiSZG!St}g^}){e!_W4{()Y*H_sG=u$kh1C*ZIxZ`Onz- z&)WIX-1*Yn`P1F`)ZY2k-ul+w`Pbk2*x>rv;riO)`rPCC;pO|`=lkO5{N(EV=IZVNM1>+byS@%``e{P6Ss@$>!k_Wt$w{`mU-{r&%<%D5*0008PqL_t&- z(*?nYLW3|A1<>cLN=+b00arnb;>3lkRxGAfBbuNU?*D&@=g`ml*C=dT+`7IG08}*h zJSfYnoPE#Uw5jMcO6<_1#}8{eii?+ogun3w*vm_yC4WxhI3NIl0W`o_cVP`wD|q|Y zH~BDg0YKBkoxbFUQGaJ$K;^HB`g`YraCmQ}lMRPSl2TU$;=%x^tTa7#7y)pd%t)CW z+02`PRE5ABl;y5#%>hkAvdIKGgR?~dQc6QoW)?8dk<0N|PC*A-{P(X0SY@ 0 then - for l = 0,1 do - for i = -1,1,2 do - for _,p in pairs({ - {x=pos.x+i, z=pos.z-l*i}, - {x=pos.x+l*i, z=pos.z+i} - }) do - if math.random(2) == 2 then - p.y = pos.y - if minetest.get_node(p).name == "default:water_source" then - minetest.add_node(p,{name="default:ice", param2 = math.random(0,node.param2-1)}) - end + if node.param2 == 0 then + return + end + for l = 0,1 do + for i = -1,1,2 do + for _,p in pairs({ + {x=pos.x+i, z=pos.z-l*i}, + {x=pos.x+l*i, z=pos.z+i} + }) do + if math.random(2) == 2 then + p.y = pos.y + if minetest.get_node(p).name == "default:water_source" then + minetest.add_node(p,{name="default:ice", param2 = math.random(0,node.param2-1)}) end end end end - if math.random(8) == 8 then - minetest.add_node(pos, {name="default:water_source"}) - else - minetest.add_node(pos, {name="default:ice", param2 = 0}) - end + end + if math.random(8) == 8 then + minetest.add_node(pos, {name="default:water_source"}) + else + node.param2 = 0 + minetest.add_node(pos, node) end end, }) @@ -141,6 +143,7 @@ minetest.register_abm({ neighbors = {"snow:moss"}, interval = 20, chance = 6, + catch_up = false, action = function(pos, node) node.name = "default:mossycobble" minetest.add_node(pos, node) @@ -206,3 +209,17 @@ minetest.register_abm({ --end end }) + + + + +--Backwards Compatability. +minetest.register_abm({ + nodenames = {"snow:snow1","snow:snow2","snow:snow3","gsnow4","snow:snow5","snow:snow6","snow:snow7","snow:snow8"}, + interval = 1, + chance = 1, + action = function(pos, node) + minetest.add_node(pos, {name="default:snow"}) + minetest.set_node_level(pos, 7*(tonumber(node.name:sub(-1)))) + end, +}) diff --git a/mods/snow/src/aliases.lua b/mods/snow/src/aliases.lua index 603eb2db..8f156a9d 100755 --- a/mods/snow/src/aliases.lua +++ b/mods/snow/src/aliases.lua @@ -26,7 +26,8 @@ minetest.register_alias("icysnow", "snow:snow_cobble") minetest.register_alias("snowcobble", "snow:snow_cobble") minetest.register_alias("snowycobble", "snow:snow_cobble") minetest.register_alias("cobblesnow", "snow:snow_cobble") - +minetest.register_alias("snow:leaves", "default:pine_needles") +minetest.register_alias("snow:sapling_pine", "default:pine_sapling") -- To clean up my first stairsplus attempt. -- Stair diff --git a/mods/snow/src/falling_snow.lua b/mods/snow/src/falling_snow.lua index 1e40257e..0c0cc0f2 100755 --- a/mods/snow/src/falling_snow.lua +++ b/mods/snow/src/falling_snow.lua @@ -31,6 +31,7 @@ near torches and lava. * Add code to prevent snowfall from depositing snow on 'walkable = false' defined nodes. +both are already fixed -- Hybrid Dog --]] @@ -42,8 +43,9 @@ near torches and lava. local weather_legacy +local worldpath = minetest.get_worldpath() local read_weather_legacy = function () - local file = io.open(minetest.get_worldpath().."/weather_v6", "r") + local file = io.open(worldpath.."/weather_v6", "r") if not file then return end local readweather = file:read() file:close() @@ -52,26 +54,30 @@ end --Weather for legacy versions of minetest. local save_weather_legacy = function () - local file = io.open(minetest.get_worldpath().."/weather_v6", "w+") + local file = io.open(worldpath.."/weather_v6", "w+") file:write(weather_legacy) file:close() end - weather_legacy = read_weather_legacy() or "" +weather_legacy = read_weather_legacy() or "" - minetest.register_globalstep(function(dtime) - if weather_legacy == "snow" then - if math.random(1, 10000) == 1 then - weather_legacy = "none" - save_weather_legacy() - end - else - if math.random(1, 50000) == 2 then - weather_legacy = "snow" - save_weather_legacy() - end +local function leg_step() + if weather_legacy == "snow" then + if math.random(1000) == 1 then + weather_legacy = "none" + save_weather_legacy() end - end) + elseif math.random(5000) == 2 then + weather_legacy = "snow" + save_weather_legacy() + end + minetest.after(2, leg_step) +end +minetest.after(4, leg_step) + +local function infolog(msg) + minetest.log("info", "[snow] falling_snow: "..msg) +end -- copied from meru mod local SEEDDIFF3 = 9130 -- 9130 -- Values should match minetest mapgen desert perlin. @@ -79,29 +85,63 @@ local OCTAVES3 = 3 -- 3 local PERSISTENCE3 = 0.5 -- 0.5 local SCALE3 = 250 -- 250 ---Get snow at position. -local function get_snow(pos) - --Legacy support. - if weather_legacy == "snow" then - local perlin1 = minetest.get_perlin(112,3, 0.5, 150) - if perlin1:get2d({x=pos.x, y=pos.z}) <= 0.53 then - return false - end - - -- disable falling snow in desert - local desert_perlin = minetest.get_perlin(SEEDDIFF3, OCTAVES3, PERSISTENCE3, SCALE3) - local noise3 = desert_perlin:get2d({x=pos.x+150,y=pos.z+50}) -- Offsets must match minetest mapgen desert perlin. - if noise3 > 0.35 then -- Smooth transition 0.35 to 0.45. - return false - end - return true +-- cache perlin noise tests +local perlin_scale, rarity +local cold_perl_values = {} +setmetatable(cold_perl_values, {__mode = "kv"}) +local function cold_perlin_test(x, y) + if not cold_perl_values[y] then + cold_perl_values[y] = {} + setmetatable(cold_perl_values[y], {__mode = "kv"}) end - return false + + local v = cold_perl_values[y][x] + if v ~= nil then + return v + end + + if not rarity then + rarity = snow.mapgen.smooth_rarity_min + perlin_scale = snow.mapgen.perlin_scale + end + + v = minetest.get_perlin(112,3, 0.5, perlin_scale):get2d({x=x, y=y}) >= rarity + cold_perl_values[y][x] = v + return v end -local addvectors = vector and vector.add +-- disable falling snow in desert +local desert_perl_values = {} +setmetatable(desert_perl_values, {__mode = "kv"}) +local function is_desert(x, y) + if not desert_perl_values[y] then + desert_perl_values[y] = {} + setmetatable(desert_perl_values[y], {__mode = "kv"}) + end + + local v = desert_perl_values[y][x] + if v ~= nil then + return v + end + + -- Offsets must match minetest mapgen desert perlin. + -- Smooth transition 0.35 to 0.45. + v = minetest.get_perlin(SEEDDIFF3, OCTAVES3, PERSISTENCE3, SCALE3):get2d({x=x+150,y=y+50}) <= 0.35 + desert_perl_values[y][x] = v + return v +end + +--Get snow at position. +local function get_snow(pos) + return weather_legacy == "snow" --Legacy support. + and cold_perlin_test(pos.x, pos.z) + and not is_desert(pos.x, pos.z) +end + +local addvectors = vector.add --Returns a random position between minp and maxp. +-- TODO: make a fload random position local function randpos(minp, maxp) local x,z if minp.x > maxp.x then @@ -146,7 +186,7 @@ local function snow_fall(pos, player, animate) return end end - for y=pos.y+10,pos.y-15,-1 do + for y=pos.y+9,pos.y-15,-1 do local n = minetest.get_node({x=pos.x,y=y,z=pos.z}).name if n ~= "air" and n ~= "ignore" then ground_y = y @@ -159,23 +199,25 @@ local function snow_fall(pos, player, animate) pos = {x=pos.x, y=ground_y, z=pos.z} - if get_snow(pos) then - if animate then - local spos = {x=pos.x, y=ground_y+10, z=pos.z} - minetest.add_particlespawner(get_snow_particledef({ - minpos = addvectors(spos, {x=-9, y=3, z=-9}), - maxpos = addvectors(spos, {x= 9, y=5, z= 9}), - vel = {x=0, y=-1, z=-1}, - acc = {x=0, y=0, z=0}, - playername = player:get_player_name() - })) - end - snow.place(pos, true) - --minetest.place_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="default:snow"}) -- LazyJ + if not get_snow(pos) then + return end + if animate then + local spos = {x=pos.x, y=ground_y+10, z=pos.z} + minetest.add_particlespawner(get_snow_particledef({ + minpos = addvectors(spos, {x=-9, y=3, z=-9}), + maxpos = addvectors(spos, {x= 9, y=5, z= 9}), + vel = {x=0, y=-1, z=-1}, + acc = {x=0, y=0, z=0}, + playername = player:get_player_name() + })) + end + snow.place(pos, true) + --minetest.place_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="default:snow"}) -- LazyJ end -- Snow +local lighter_snowfall = snow.lighter_snowfall local function calc_snowfall() for _, player in pairs(minetest.get_connected_players()) do local ppos = player:getpos() @@ -184,7 +226,7 @@ local function calc_snowfall() if get_snow(ppos) and minetest.get_node_light(ppos, 0.5) == 15 then local animate - if not snow.lighter_snowfall then + if not lighter_snowfall then local vel = {x=0, y=-1, z=-1} local acc = {x=0, y=0, z=0} minetest.add_particlespawner(get_snow_particledef({ @@ -227,8 +269,29 @@ local function calc_snowfall() end end -minetest.register_globalstep(function(dtime) - if snow.enable_snowfall then - calc_snowfall() +local step_func +minetest.register_globalstep(function() + step_func() +end) + +if snow.enable_snowfall then + step_func = calc_snowfall + infolog("step function set to calc_snowfall") +else + step_func = function() end + infolog("step function set to empty function") +end + +snow.register_on_configuring(function(name, v) + if name == "enable_snowfall" then + if v then + step_func = calc_snowfall + infolog("step function set to calc_snowfall") + else + step_func = function() end + infolog("step function set to empty function") + end + elseif name == "lighter_snowfall" then + lighter_snowfall = v end end) diff --git a/mods/snow/src/mapgen.lua b/mods/snow/src/mapgen.lua index 56d8f6ac..5d9fce85 100755 --- a/mods/snow/src/mapgen.lua +++ b/mods/snow/src/mapgen.lua @@ -10,29 +10,70 @@ saplings grow into trees. --]] -- ~ LazyJ, 2014_05_13 ---[[ Part 1: To disable the mapgen, add the *starting* comment under this line. +-- Part 1: To disable the mapgen, add the *starting* comment under this line. + + +snow.mapgen = snow.mapgen or {} +local mg = snow.mapgen + +-- perlin noise "hills" are not peaks but looking like sinus curve +local function upper_rarity(rarity) + return math.sign(rarity)*math.sin(math.abs(rarity)*math.pi/2) +end + +local rarity = snow.mapgen_rarity +local size = snow.mapgen_size +local smooth = snow.smooth_biomes + +local nosmooth_rarity, perlin_scale +local function calc_values() + nosmooth_rarity = 1-rarity/50 + perlin_scale = size*100/rarity + mg.perlin_scale = perlin_scale + local smooth_rarity_max, smooth_rarity_min, smooth_rarity_dif + if smooth then + local smooth_trans_size = 4 --snow.smooth_trans_size + mg.smooth_rarity_max = upper_rarity(nosmooth_rarity+smooth_trans_size*2/perlin_scale) + mg.smooth_rarity_min = upper_rarity(nosmooth_rarity-smooth_trans_size/perlin_scale) + mg.smooth_rarity_dif = mg.smooth_rarity_max-mg.smooth_rarity_min + end + nosmooth_rarity = upper_rarity(nosmooth_rarity) + mg.nosmooth_rarity = nosmooth_rarity +end +calc_values() + +snow.register_on_configuring(function(name, v) + if name == "mapgen_rarity" then + rarity = v + elseif name == "mapgen_size" then + size = v + elseif name == "smooth_biomes" then + smooth = v + else + return + end + -- TODO: if e.g. size and rarity get changed at once, don't calculate the values more times + calc_values() +end) --Identify the mapgen. -minetest.register_on_mapgen_init(function(MapgenParams) - local mgname = MapgenParams.mgname - if not mgname then - io.write("[MOD] Snow Biomes: WARNING! mapgen could not be identifyed!\n") - end - if mgname == "v7" then - --Load mapgen_v7 compatibility. - dofile(minetest.get_modpath("snow").."/src/mapgen_v7.lua") - else - --Load mapgen_v6 compatibility. - dofile(minetest.get_modpath("snow").."/src/mapgen_v6.lua") - end -end) +local mgname = minetest.get_mapgen_setting"mg_name" +if not mgname then + minetest.log("error", "[MOD] Snow Biomes: WARNING! mapgen could not be identifyed!") +end +local path = minetest.get_modpath"snow" +if mgname == "v7" then + --Load mapgen_v7 compatibility. + dofile(path.."/src/mapgen_v7.lua") +else + --Load mapgen_v6 compatibility. + dofile(path.."/src/mapgen_v6.lua") +end -- To complete the commenting-out add the *closing* comment under this line. - - local pine_tree = { axiom="TABff", rules_a="[&T+f+ff+ff+ff+f]GA", @@ -66,7 +107,6 @@ local xmas_tree = { --Makes pine tree function snow.make_pine(pos,snow,xmas) local minetest = minetest - local perlin1 = minetest.get_perlin(112,3, 0.5, 150) local try_node = function(pos, node) local n = minetest.get_node(pos).name if n == "air" @@ -95,7 +135,7 @@ function snow.make_pine(pos,snow,xmas) if xmas then try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="snow:star_lit"}) -- Added lit star. ~ LazyJ elseif snow - and perlin1:get2d({x=pos.x,y=pos.z}) > 0.53 then + and minetest.get_perlin(112,3, 0.5, perlin_scale):get2d({x=pos.x,y=pos.z}) > nosmooth_rarity then try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="default:snow"}) end end @@ -109,7 +149,7 @@ function snow.voxelmanip_pine(pos,a,data) local c_pinetree = minetest.get_content_id("default:pinetree") local c_air = minetest.get_content_id("air") - local perlin1 = minetest.get_perlin(112,3, 0.5, 150) + local perlin1 = minetest.get_perlin(112,3, 0.5, perlin_scale) for z = -1,1 do local z = pos.z + z for x = -1,1 do @@ -120,7 +160,7 @@ function snow.voxelmanip_pine(pos,a,data) data[a:index(x,pos.y+i,z)] = c_pine_needles if x ~= 0 and z ~= 0 - and perlin1:get2d({x=x,y=z}) > 0.53 then + and perlin1:get2d({x=x,y=z}) > nosmooth_rarity then local abovenode = a:index(x,pos.y+i+1,z) data[abovenode] = c_snow end @@ -135,16 +175,16 @@ function snow.voxelmanip_pine(pos,a,data) data[a:index(x-1,y,z)] = c_pine_needles data[a:index(x,y,z+1)] = c_pine_needles data[a:index(x,y,z-1)] = c_pine_needles - if perlin1:get2d({x=x+1,y=z}) > 0.53 then + if perlin1:get2d({x=x+1,y=z}) > nosmooth_rarity then data[a:index(x+1,y+1,z)] = c_snow end - if perlin1:get2d({x=x+1,y=z}) > 0.53 then + if perlin1:get2d({x=x+1,y=z}) > nosmooth_rarity then data[a:index(x-1,y+1,z)] = c_snow end - if perlin1:get2d({x=x,y=z+1}) > 0.53 then + if perlin1:get2d({x=x,y=z+1}) > nosmooth_rarity then data[a:index(x,y+1,z+1)] = c_snow end - if perlin1:get2d({x=x,y=z-1}) > 0.53 then + if perlin1:get2d({x=x,y=z-1}) > nosmooth_rarity then data[a:index(x,y+1,z-1)] = c_snow end end @@ -153,8 +193,7 @@ function snow.voxelmanip_pine(pos,a,data) end data[a:index(pos.x,pos.y+5,pos.z)] = c_pine_needles data[a:index(pos.x,pos.y+6,pos.z)] = c_pine_needles - if perlin1:get2d({x=pos.x,y=pos.z}) > 0.53 then + if perlin1:get2d({x=pos.x,y=pos.z}) > nosmooth_rarity then data[a:index(pos.x,pos.y+7,pos.z)] = c_snow end end -]] diff --git a/mods/snow/src/mapgen_v6.lua b/mods/snow/src/mapgen_v6.lua index d79878bf..26b075e5 100755 --- a/mods/snow/src/mapgen_v6.lua +++ b/mods/snow/src/mapgen_v6.lua @@ -1,5 +1,6 @@ -- https://github.com/paramat/meru/blob/master/init.lua#L52 ---[[ Parameters must match mgv6 biome noise +-- Parameters must match mgv6 biome noise + local np_default = { offset = 0, scale = 1, @@ -9,17 +10,21 @@ local np_default = { persist = 0.5 } + -- 2D noise for coldness +local mg = snow.mapgen +local scale = mg.perlin_scale local np_cold = { offset = 0, - scale = -1, - spread = {x=256, y=256, z=256}, + scale = 1, + spread = {x=scale, y=scale, z=scale}, seed = 112, octaves = 3, persist = 0.5 } + -- 2D noise for icetype local np_ice = { @@ -31,29 +36,39 @@ local np_ice = { persist = 0.5 } --- Debugging function - -local biome_strings = { - {"snowy", "plain", "alpine", "normal", "normal"}, - {"cool", "icebergs", "icesheet", "icecave", "icehole"} -} -local function biome_to_string(num,num2) - local biome = biome_strings[1][num] or "unknown "..num - return biome -end - local function do_ws_func(a, x) - local n = x/(16000) + local n = math.pi * x / 16000 local y = 0 - for k=1,1000 do - y = y + 1000*math.sin(math.pi * k^a * n)/(math.pi * k^a) + for k = 1,1000 do + y = y + math.sin(k^a * n)/(k^a) end - return y + return 1000*y/math.pi end +-- caching functions + +local ws_values = {} +local function get_ws_value(a, x) + local v = ws_values[a] + if v then + v = v[x] + if v then + return v + end + else + ws_values[a] = {} + -- weak table, see https://www.lua.org/pil/17.1.html + setmetatable(ws_values[a], {__mode = "kv"}) + end + v = do_ws_func(a, x) + ws_values[a][x] = v + return v +end + local plantlike_ids = {} +setmetatable(plantlike_ids, {__mode = "kv"}) local function is_plantlike(id) if plantlike_ids[id] ~= nil then return plantlike_ids[id] @@ -74,6 +89,7 @@ local function is_plantlike(id) end local snowable_ids = {} +setmetatable(snowable_ids, {__mode = "kv"}) local function is_snowable(id) if snowable_ids[id] ~= nil then return snowable_ids[id] @@ -95,7 +111,8 @@ local function is_snowable(id) return true end -local c, replacements + +local c, replacements, mg_debug, biome_to_string local function define_contents() c = { dirt_with_grass = minetest.get_content_id("default:dirt_with_grass"), @@ -120,8 +137,41 @@ local function define_contents() desert_sand = minetest.get_content_id("default:desert_sand"), } replacements = snow.known_plants or {} + + mg_debug = snow.debug end +local smooth = snow.smooth_biomes +local smooth_rarity_max = mg.smooth_rarity_max +local smooth_rarity_min = mg.smooth_rarity_min +local smooth_rarity_dif = mg.smooth_rarity_dif +local nosmooth_rarity = mg.nosmooth_rarity + +snow.register_on_configuring(function(name, v) + if name == "debug" then + mg_debug = v + elseif name == "mapgen_rarity" + or name == "mapgen_size" + or name == "smooth_biomes" then + minetest.after(0, function() + smooth = snow.smooth_biomes + smooth_rarity_max = mg.smooth_rarity_max + smooth_rarity_min = mg.smooth_rarity_min + smooth_rarity_dif = mg.smooth_rarity_dif + nosmooth_rarity = mg.nosmooth_rarity + local scale = mg.perlin_scale + np_cold = { + offset = 0, + scale = 1, + spread = {x=scale, y=scale, z=scale}, + seed = 112, + octaves = 3, + persist = 0.5 + } + end) + end +end) + minetest.register_on_generated(function(minp, maxp, seed) local t1 = os.clock() @@ -130,23 +180,23 @@ minetest.register_on_generated(function(minp, maxp, seed) local x1 = maxp.x local z1 = maxp.z - local smooth = snow.smooth_biomes - if not c then define_contents() end - local vm, emin, emax = minetest.get_mapgen_object("voxelmanip") - local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax}) + local vm, emin, emax = minetest.get_mapgen_object"voxelmanip" + local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax} local data = vm:get_data() local param2s = vm:get_param2_data() + local heightmap = minetest.get_mapgen_object"heightmap" + local snow_tab,num = {},1 local pines_tab,pnum = {},1 local sidelen = x1 - x0 + 1 local chulens = {x=sidelen, y=sidelen, z=sidelen} - local nvals_default = minetest.get_perlin_map(np_default, chulens):get2dMap_flat({x=x0+150, y=z0+50}) + local nvals_default = minetest.get_perlin_map(np_default, chulens):get2dMap_flat{x=x0+150, y=z0+50} local nvals_cold, nvals_ice -- Choose biomes @@ -162,24 +212,30 @@ minetest.register_on_generated(function(minp, maxp, seed) -- Reseed random pr = PseudoRandom(seed+68) + local nodes_added + -- Loop through columns in chunk + local smooth = smooth and not snowy local write_to_map = false local ni = 1 for z = z0, z1 do for x = x0, x1 do - local in_biome = false - local test - if nvals_default[ni] < 0.35 then + local in_biome = false + local test + if nvals_default[ni] < 0.35 then if not nvals_cold then - nvals_cold = minetest.get_perlin_map(np_cold, chulens):get2dMap_flat({x=x0, y=z0}) + nvals_cold = minetest.get_perlin_map(np_cold, chulens):get2dMap_flat{x=x0, y=z0} end test = math.min(nvals_cold[ni], 1) - if smooth - and not snowy then - if (test > 0.73 or (test > 0.43 and pr:next(0,29) > (0.73 - test) * 100 )) then + if smooth then + if test >= smooth_rarity_max + or ( + test > smooth_rarity_min + and pr:next(1, 1000) <= ((test-smooth_rarity_min)/smooth_rarity_dif)*1000 + ) then in_biome = true end - elseif test > 0.53 then + elseif test > nosmooth_rarity then in_biome = true end end @@ -187,25 +243,23 @@ minetest.register_on_generated(function(minp, maxp, seed) if not in_biome then if alpine and test - and test > 0.43 then + and test > smooth_rarity_min then -- remove trees near alpine - local ground_y = nil - for y = maxp.y, minp.y, -1 do - local nodid = data[area:index(x, y, z)] - if nodid ~= c.air - and nodid ~= c.ignore then - ground_y = y - break + local ground_y + if data[area:index(x, maxp.y, z)] == c.air then + for y = math.min(heightmap[ni]+20, maxp.y), math.max(minp.y, heightmap[ni]-5), -1 do + if data[area:index(x, y, z)] ~= c.air then + ground_y = y + break + end end end - if ground_y == maxp.y then -- avoid awful snow layers at chunk boundaries underground - ground_y = nil - end if ground_y then local vi = area:index(x, ground_y, z) if data[vi] == c.leaves or data[vi] == c.jungleleaves then + nodes_added = true for y = ground_y, -16, -1 do local vi = area:index(x, y, z) local id = data[vi] @@ -224,28 +278,30 @@ minetest.register_on_generated(function(minp, maxp, seed) end end else + nodes_added = true write_to_map = true if not nvals_ice then - nvals_ice = minetest.get_perlin_map(np_ice, chulens):get2dMap_flat({x=x0, y=z0}) + nvals_ice = minetest.get_perlin_map(np_ice, chulens):get2dMap_flat{x=x0, y=z0} end - local icetype = nvals_ice[ni] + local icetype = nvals_ice[ni] local cool = icetype > 0 -- only spawns ice on edge of water local icebergs = icetype > -0.2 and icetype <= 0 local icehole = icetype > -0.4 and icetype <= -0.2 -- icesheet with holes local icesheet = icetype > -0.6 and icetype <= -0.4 local icecave = icetype <= -0.6 + local ground_y - for y = maxp.y, minp.y, -1 do - local nodid = data[area:index(x, y, z)] - if nodid ~= c.air and nodid ~= c.ignore then - ground_y = y - break + -- avoid generating underground + if data[area:index(x, maxp.y, z)] == c.air then + -- search for non air node from 20 m above ground down to 5 m below ground (confined by minp and maxp) + for y = math.min(heightmap[ni]+20, maxp.y), math.max(minp.y, heightmap[ni]-5), -1 do + if data[area:index(x, y, z)] ~= c.air then + ground_y = y + break + end end end - if ground_y == maxp.y then -- avoid awful snow layers at chunk boundaries underground - ground_y = nil - end if ground_y then local node = area:index(x, ground_y, z) @@ -253,7 +309,7 @@ minetest.register_on_generated(function(minp, maxp, seed) if c_ground == c.dirt_with_grass then if alpine - and test > 0.53 then + and test > nosmooth_rarity then snow_tab[num] = {ground_y, z, x, test} num = num+1 -- generate stone ground @@ -274,7 +330,7 @@ minetest.register_on_generated(function(minp, maxp, seed) data[area:index(x, ground_y+1, z)] = c.dry_shrub else if snowy - or test > 0.8 then + or test > smooth_rarity_max then -- more, deeper snow data[node] = c.snow_block else @@ -363,7 +419,7 @@ minetest.register_on_generated(function(minp, maxp, seed) break end end ---[[ elseif alpine then + elseif alpine then -- make stone pillars out of trees and other stuff for y = ground_y, math.max(-6, minp.y-6), -1 do local stone = area:index(x, y, z) @@ -374,7 +430,7 @@ minetest.register_on_generated(function(minp, maxp, seed) end -- put snow onto it snow_tab[num] = {ground_y, z, x, test} - num = num+1 --]] -- MFF (06/10/2015) + num = num+1 elseif c_ground ~= c.desert_sand then if is_snowable(c_ground) then -- put snow onto it @@ -414,19 +470,26 @@ minetest.register_on_generated(function(minp, maxp, seed) end end + -- abort if mapgen doesn't change sth + if not nodes_added then + return + end + + -- try to fix oom memory crashes + minetest.after(0, collectgarbage) + if num ~= 1 then for _,i in pairs(snow_tab) do -- set snow data[area:index(i[3], i[1]+1, i[2])] = c.snow end - local wsz, wsx for _,i in pairs(snow_tab) do local y,z,x,test = unpack(i) - test = (test-0.53)/0.47 -- /(1-0.53) + test = (test-nosmooth_rarity)/(1-nosmooth_rarity) -- /(1-0.53) if test > 0 then local maxh = math.floor(test*10)%10+1 if maxh ~= 1 then - local h = math.floor( do_ws_func(2, x) + do_ws_func(5, z)*5)%10+1 + local h = math.floor(get_ws_value(2, x) + get_ws_value(5, z)*5)%10+1 if h ~= 1 then -- search for nearby snow y = y+1 @@ -477,10 +540,21 @@ minetest.register_on_generated(function(minp, maxp, seed) vm:write_to_map() if write_to_map - and snow.debug then -- print if any column of mapchunk was snow biome + and mg_debug then -- print if any column of mapchunk was snow biome local biome_string = biome_to_string(biome) local chugent = math.ceil((os.clock() - t1) * 1000) print("[snow] "..biome_string.." x "..minp.x.." z "..minp.z.." time "..chugent.." ms") end end) + +-- Debugging function + +local biome_strings = { + {"snowy", "plain", "alpine", "normal", "normal"}, + {"cool", "icebergs", "icesheet", "icecave", "icehole"} +} +function biome_to_string(num,num2) + local biome = biome_strings[1][num] or "unknown "..num + return biome +end diff --git a/mods/snow/src/mapgen_v7.lua b/mods/snow/src/mapgen_v7.lua index 01220520..ebb3eedb 100755 --- a/mods/snow/src/mapgen_v7.lua +++ b/mods/snow/src/mapgen_v7.lua @@ -6,8 +6,8 @@ minetest.register_biome({ node_filler = "default:dirt", depth_filler = 2, - y_min = snow.min_height, - y_max = snow.min_height+60, + height_min = snow.min_height, + height_max = snow.min_height+60, heat_point = 10.0, humidity_point = 40.0, }) @@ -20,8 +20,8 @@ minetest.register_biome({ node_filler = "default:dirt", depth_filler = 2, - y_min = snow.min_height, - y_max = snow.min_height+60, + height_min = snow.min_height, + height_max = snow.min_height+60, heat_point = 10.0, humidity_point = 55.0, }) @@ -34,8 +34,8 @@ minetest.register_biome({ node_filler = "default:dirt", depth_filler = 2, - y_min = snow.min_height, - y_max = snow.min_height+60, + height_min = snow.min_height, + height_max = snow.min_height+60, heat_point = 10.0, humidity_point = 70.0, }) @@ -47,8 +47,8 @@ minetest.register_biome({ depth_top = 1, node_filler = "default:stone", - y_min = snow.min_height+60, - y_max = 31000, + height_min = snow.min_height+60, + height_max = 31000, heat_point = 10.0, humidity_point = 40.0, }) @@ -61,8 +61,8 @@ minetest.register_biome({ node_filler = "default:stone", depth_filler = 0, - y_min = -31000, - y_max = 2, + height_min = -31000, + height_max = 2, heat_point = 10.0, humidity_point = 40.0, }) diff --git a/mods/snow/src/nodes.lua b/mods/snow/src/nodes.lua index e2c84a54..c8310a30 100755 --- a/mods/snow/src/nodes.lua +++ b/mods/snow/src/nodes.lua @@ -38,17 +38,27 @@ end ]] minetest.register_node("snow:needles", table.copy(nodedef)) - - - - - --Christmas easter egg - minetest.register_on_mapgen_init( function() - if rawget(_G, "skins") then - skins.add("character_snow_man") +snow.register_on_configuring(function(name, v) + if name == "christmas_content" then + local drop = minetest.registered_nodes["snow:needles"].drop + if v then + table.insert(drop.items, 1, { + items = {"snow:xmas_tree"}, + rarity = 120, + }) + else + table.remove(drop.items, 1) end + minetest.override_item("snow:needles", {drop = drop}) + end +end) + + + + -- Christmas egg + if minetest.global_exists"skins" then + skins.add"character_snow_man" end - ) -- Decorated Pine Leaves @@ -181,6 +191,7 @@ minetest.register_node("snow:shrub", table.copy(nodedef)) nodedef.tiles = {"snow_shrub.png^snow_shrub_covering.png"} nodedef.inventory_image = "snow_shrub.png^snow_shrub_covering.png" nodedef.wield_image = "snow_shrub.png^snow_shrub_covering.png" +nodedef.paramtype2 = "degrotate" nodedef.drop = "snow:shrub" nodedef.furnace_burntime = 3 minetest.register_node("snow:shrub_covered", nodedef) @@ -198,6 +209,7 @@ if rawget(_G, "flowers") then tiles = { "snow_" .. name .. ".png" }, sunlight_propagates = true, paramtype = "light", + paramtype2 = "degrotate", walkable = false, drop = "", groups = {snappy=3, attached_node = 1}, @@ -232,6 +244,7 @@ nodedef = { drawtype = "plantlike", tiles = {"snow_apple.png"}, paramtype = "light", + paramtype2 = "degrotate", walkable = false, sunlight_propagates = apple.sunlight_propagates, selection_box = apple.selection_box, diff --git a/mods/snow/src/sled.lua b/mods/snow/src/sled.lua index 58f0cdfb..31909bd9 100755 --- a/mods/snow/src/sled.lua +++ b/mods/snow/src/sled.lua @@ -113,9 +113,8 @@ local function leave_sled(self, player) player:get_inventory():add_item("main", "snow:sled") end -function sled:on_rightclick(player) - if self.driver - or not snow.sleds then +local function sled_rightclick(self, player) + if self.driver then return end join_sled(self, player) @@ -136,6 +135,27 @@ function sled:on_rightclick(player) -- End part 1 end +local on_sled_click +if snow.sleds then + on_sled_click = sled_rightclick +else + on_sled_click = function() end +end + +snow.register_on_configuring(function(name, v) + if name == "sleds" then + if v then + on_sled_click = sled_rightclick + else + on_sled_click = function() end + end + end +end) + +function sled:on_rightclick(player) + on_sled_click(self, player) +end + function sled:on_activate(staticdata, dtime_s) self.object:set_armor_groups({immortal=1}) self.object:setacceleration({x=0, y=-10, z=0}) diff --git a/mods/snow/src/snowball.lua b/mods/snow/src/snowball.lua index 6739a2d7..b8008de0 100755 --- a/mods/snow/src/snowball.lua +++ b/mods/snow/src/snowball.lua @@ -8,13 +8,30 @@ local creative_mode = minetest.setting_getbool("creative_mode") + +local snowball_velocity, entity_attack_delay +local function update_snowball_vel(v) + snowball_velocity = v + local walkspeed = tonumber(minetest.setting_get("movement_speed_walk")) or 4 + entity_attack_delay = (walkspeed+1)/v +end +update_snowball_vel(snow.snowball_velocity) + +local snowball_gravity = snow.snowball_gravity +snow.register_on_configuring(function(name, v) + if name == "snowball_velocity" then + update_snowball_vel(v) + elseif name == "snowball_gravity" then + snowball_gravity = v + end +end) + local function get_gravity() local grav = tonumber(minetest.setting_get("movement_gravity")) or 9.81 - return grav*snow.snowball_gravity + return grav*snowball_gravity end -local someone_throwing -local timer = 0 +local someone_throwing, just_acitvated --Shoot snowball local function snow_shoot_snowball(item, player) @@ -25,13 +42,13 @@ local function snow_shoot_snowball(item, player) addp.z = -dir.x/dif -- + (math.random()-0.5)/5 local pos = vector.add(player:getpos(), addp) local obj = minetest.add_entity(pos, "snow:snowball_entity") - obj:get_luaentity().thrower = player:get_player_name() - obj:setvelocity(vector.multiply(dir, snow.snowball_velocity)) + obj:setvelocity(vector.multiply(dir, snowball_velocity)) obj:setacceleration({x=dir.x*-3, y=-get_gravity(), z=dir.z*-3}) + obj:get_luaentity().thrower = player:get_player_name() if creative_mode then if not someone_throwing then someone_throwing = true - timer = -0.5 + just_acitvated = true end return end @@ -40,13 +57,7 @@ local function snow_shoot_snowball(item, player) end if creative_mode then - local function update_step(dtime) - timer = timer+dtime - if timer < 0.006 then - return - end - timer = 0 - + local function update_step() local active for _,player in pairs(minetest.get_connected_players()) do if player:get_player_control().LMB then @@ -66,13 +77,21 @@ if creative_mode then end end - -- do automatic throwing using a globalstep - minetest.register_globalstep(function(dtime) + -- do automatic throwing using minetest.after + local function do_step() + local timer -- only if one holds left click - if someone_throwing then - update_step(dtime) + if someone_throwing + and not just_acitvated then + update_step() + timer = 0.006 + else + timer = 0.5 + just_acitvated = false end - end) + minetest.after(timer, do_step) + end + minetest.after(3, do_step) end --The snowball Entity @@ -80,7 +99,6 @@ local snow_snowball_ENTITY = { physical = false, timer = 0, collisionbox = {-5/16,-5/16,-5/16, 5/16,5/16,5/16}, - thrower = "", } function snow_snowball_ENTITY.on_activate(self) @@ -118,25 +136,6 @@ function snow_snowball_ENTITY.on_step(self, dtime) return end - if self.timer > 0.15 then - for i, v in pairs(minetest.get_objects_inside_radius(self.object:getpos(), 1)) do - if v ~= self.object then - local entity_name = v:get_entity_name() - if entity_name and entity_name ~= "snow:snowball_entity" - and entity_name ~= "__builtin:item" - and entity_name ~= "gauges:hp_bar" then - local puncher = self.object - if minetest.get_player_by_name(self.thrower or "") then - puncher = minetest.get_player_by_name(self.thrower) - end - v:punch(puncher, 1.0, {full_punch_interval=1.0, damage_groups = {fleshy=1} }) - minetest.add_item(self.object:getpos(), "default:snow") - self.object:remove() - return - end - end - end - end if self.physical then local fell = self.object:getvelocity().y == 0 if not fell then @@ -163,13 +162,41 @@ function snow_snowball_ENTITY.on_step(self, dtime) --self.object:setvelocity({x=0, y=0, z=0}) pos = self.lastpos self.object:setpos(pos) - local gain = vector.length(self.object:getvelocity())/30 - minetest.sound_play("default_snow_footstep", {pos=pos, gain=gain}) + minetest.sound_play("default_snow_footstep", {pos=pos, gain=vector.length(self.object:getvelocity())/30}) self.object:set_properties({physical = true}) self.physical = true return end self.lastpos = vector.new(pos) + + if self.timer < entity_attack_delay then + return + end + for _,v in pairs(minetest.get_objects_inside_radius(pos, 1.73)) do + if v ~= self.object then + local entity_name = v:get_entity_name() + if entity_name ~= "snow:snowball_entity" + and entity_name ~= "__builtin:item" + and entity_name ~= "gauges:hp_bar" then + local vvel = v:getvelocity() or v:get_player_velocity() + local veldif = self.object:getvelocity() + if vvel then + veldif = vector.subtract(veldif, vvel) + end + local gain = vector.length(veldif)/20 + v:punch( + (self.thrower and minetest.get_player_by_name(self.thrower)) + or self.object, + 1, + {full_punch_interval=1, damage_groups = {fleshy=math.ceil(gain)}} + ) + minetest.sound_play("default_snow_footstep", {pos=pos, gain=gain}) + spawn_falling_node(pos, {name = "default:snow"}) + self.object:remove() + return + end + end + end end diff --git a/mods/snow/src/util.lua b/mods/snow/src/util.lua index f2dd9f96..b78d8efd 100755 --- a/mods/snow/src/util.lua +++ b/mods/snow/src/util.lua @@ -10,6 +10,8 @@ snow = { christmas_content = true, smooth_snow = true, min_height = 3, + mapgen_rarity = 18, + mapgen_size = 210, } --Config documentation. @@ -24,74 +26,115 @@ local doc = { smooth_snow = "Disable this to stop snow from being smoothed.", christmas_content = "Disable this to remove christmas saplings from being found.", min_height = "The minumum height a snow biome will generate (mgv7)", + mapgen_rarity = "mapgen rarity in %", + mapgen_size = "size of the generated… (has an effect to the rarity, too)", } ---Manage config. + +-- functions for dynamically changing settings + +local on_configurings,n = {},1 +function snow.register_on_configuring(func) + on_configurings[n] = func + n = n+1 +end + +local function change_setting(name, value) + if snow[name] == value then + return + end + for i = 1,n-1 do + if on_configurings[i](name, value) == false then + return + end + end + snow[name] = value +end + + +local function value_from_string(v) + if v == "true" then + v = true + elseif v == "false" then + v = false + else + local a_number = tonumber(v) + if a_number then + v = a_number + end + end + return v +end + +local allowed_types = {string = true, number = true, boolean = true} + --Saves contents of config to file. local function saveConfig(path, config, doc) local file = io.open(path,"w") - if file then - for i,v in pairs(config) do - local t = type(v) - if t == "string" or t == "number" or t == "boolean" then - if doc and doc[i] then - file:write("# "..doc[i].."\n") - end - file:write(i.." = "..tostring(v).."\n") + if not file then + minetest.log("error", "[snow] could not open config file for writing at "..path) + return + end + for i,v in pairs(config) do + if allowed_types[type(v)] then + if doc and doc[i] then + file:write("# "..doc[i].."\n") end + file:write(i.." = "..tostring(v).."\n") end end + file:close() end ---Loads config and returns config values inside table. -local function loadConfig(path) - local config = {} - local file = io.open(path,"r") - if file then - io.close(file) - for line in io.lines(path) do - if line:sub(1,1) ~= "#" then - local i, v = line:match("^(%S*) = (%S*)") - if i and v then - if v == "true" then v = true end - if v == "false" then v = false end - if tonumber(v) then v = tonumber(v) end - config[i] = v - end - end - end - return config - else - --Create config file. - return nil - end -end + +local modpath = minetest.get_modpath("snow") minetest.register_on_shutdown(function() - saveConfig(minetest.get_modpath("snow").."/config.txt", snow, doc) + saveConfig(modpath.."/config.txt", snow, doc) end) -local config = loadConfig(minetest.get_modpath("snow").."/config.txt") + +-- load settings from config.txt + +local config +do + local path = modpath.."/config.txt" + local file = io.open(path,"r") + if not file then + --Create config file. + return + end + io.close(file) + config = {} + for line in io.lines(path) do + if line:sub(1,1) ~= "#" then + local i, v = line:match("^(%S*) = (%S*)") + if i and v then + config[i] = value_from_string(v) + end + end + end +end + if config then for i,v in pairs(config) do if type(snow[i]) == type(v) then snow[i] = v + else + minetest.log("error", "[snow] wrong type of setting "..i) end end else - saveConfig(minetest.get_modpath("snow").."/config.txt", snow, doc) + saveConfig(modpath.."/config.txt", snow, doc) end + +-- load settings from minetest.conf + for i,v in pairs(snow) do - local t = type(v) - if t == "string" - or t == "number" - or t == "boolean" then + if allowed_types[type(v)] then local v = minetest.setting_get("snow_"..i) if v ~= nil then - if v == "true" then v = true end - if v == "false" then v = false end - if tonumber(v) then v = tonumber(v) end - snow[i] = v + snow[i] = value_from_string(v) end end end @@ -99,53 +142,52 @@ end --MENU -local get_formspec = function() - local p = -0.5 - local formspec = "label[0,-0.3;Settings:]" +local function form_sort_func(a,b) + return a[1] < b[1] +end + +--[[ +local function form_sort_func_bool(a,b) + if a[2] == b[2] then + return a[1] < b[1] + else + return b[2] + end +end--]] + +local function get_formspec() + local ids,n1,n2 = {{},{}},1,1 for i,v in pairs(snow) do local t = type(v) if t == "string" or t == "number" then - p = p + 1.5 - formspec = formspec.."field[0.3,"..p..";2,1;snow:"..i..";"..i..";"..v.."]" + ids[2][n2] = {i,v} + n2 = n2+1 elseif t == "boolean" then - p = p + 0.5 - formspec = formspec.."checkbox[0,"..p..";snow:"..i..";"..i..";"..tostring(v).."]" + ids[1][n1] = {i,v} + n1 = n1+1 end end + table.sort(ids[2], form_sort_func) + table.sort(ids[1], form_sort_func) + + local p = -0.5 + local formspec = "label[0,-0.3;Settings:]" + for n = 1,n1-1 do + local i,v = unpack(ids[1][n]) + p = p + 0.5 + formspec = formspec.."checkbox[0,"..p..";snow:"..i..";"..i..";"..tostring(v).."]" + end + for n = 1,n2-1 do + local i,v = unpack(ids[2][n]) + p = p + 1.5 + formspec = formspec.."field[0.3,"..p..";2,1;snow:"..i..";"..i..";"..v.."]" + end p = p + 1 formspec = "size[4,"..p..";]\n"..formspec return formspec end -minetest.register_on_player_receive_fields(function(player, formname, fields) - if formname ~= "snow:menu" then - return - end - for i,v in pairs(snow) do - local t = type(v) - if t == "string" or t == "number" or t == "boolean" then - local field = fields["snow:"..i] - if field then - if t == "string" then - snow[i] = field - end - if t == "number" then - snow[i] = tonumber(field) - end - if t == "boolean" then - if field == "true" then - snow[i] = true - elseif field == "false" then - snow[i] = false - end - end - end - end - end -end) - - minetest.register_chatcommand("snow", { description = "Show a menu for various actions", privs = {server=true}, @@ -154,3 +196,33 @@ minetest.register_chatcommand("snow", { minetest.show_formspec(name, "snow:menu", get_formspec()) end, }) + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname ~= "snow:menu" then + return + end + for i,v in pairs(snow) do + local t = type(v) + if allowed_types[t] then + local field = fields["snow:"..i] + if field then + if t == "number" then + field = tonumber(field) + elseif t == "boolean" then + if field == "true" then + field = true + elseif field == "false" then + field = false + else + field = nil + end + elseif t ~= "string" then + field = nil + end + if field ~= nil then + change_setting(i, field) + end + end + end + end +end)