From b8e61fd763aa2360c4d9af967bccf4d3a3575ac0 Mon Sep 17 00:00:00 2001 From: LeMagnesium Date: Wed, 10 Jun 2015 17:26:05 +0200 Subject: [PATCH] Updated snow mod - See #87 --- mods/snow/.gitignore | 3 + mods/snow/depends.txt | 3 +- mods/snow/init.lua | 152 ++++++----- mods/snow/src/abms.lua | 8 +- mods/snow/src/basic_stairs_slabs.lua | 16 +- mods/snow/src/crafting.lua | 8 +- mods/snow/src/falling_snow.lua | 101 +++---- mods/snow/src/mapgen.lua | 123 ++++----- mods/snow/src/mapgen_v6.lua | 210 ++++++++------ mods/snow/src/mapgen_v7.lua | 4 +- mods/snow/src/nodes.lua | 42 +-- mods/snow/src/sled.lua | 202 ++++++++------ mods/snow/src/snowball.lua | 286 ++++++++++++-------- mods/snow/src/stairsplus.lua | 36 +-- mods/snow/src/util.lua | 77 +++--- mods/snow/textures/default_ice.xcf | Bin 1015 -> 0 bytes mods/snow/textures/default_snowball.png | Bin 0 -> 211 bytes mods/snow/textures/inkscape_default_ice.svg | 67 ----- mods/snow/textures/snow_ice.png | Bin 206 -> 0 bytes mods/snow/textures/snow_snowball.png | Bin 189 -> 0 bytes mods/snow/textures/snow_snowfall.png | Bin 350 -> 0 bytes mods/snow/textures/snow_star_lit.xcf | Bin 1480 -> 0 bytes 22 files changed, 719 insertions(+), 619 deletions(-) create mode 100644 mods/snow/.gitignore delete mode 100755 mods/snow/textures/default_ice.xcf create mode 100644 mods/snow/textures/default_snowball.png delete mode 100755 mods/snow/textures/inkscape_default_ice.svg delete mode 100755 mods/snow/textures/snow_ice.png delete mode 100755 mods/snow/textures/snow_snowball.png delete mode 100755 mods/snow/textures/snow_snowfall.png delete mode 100755 mods/snow/textures/snow_star_lit.xcf diff --git a/mods/snow/.gitignore b/mods/snow/.gitignore new file mode 100644 index 00000000..43ed67f5 --- /dev/null +++ b/mods/snow/.gitignore @@ -0,0 +1,3 @@ +config.txt +debug.txt +*~ diff --git a/mods/snow/depends.txt b/mods/snow/depends.txt index 9771003c..3bed44f5 100755 --- a/mods/snow/depends.txt +++ b/mods/snow/depends.txt @@ -1,2 +1,3 @@ default -moreblocks? \ No newline at end of file +moreblocks? +technic_worldgen? diff --git a/mods/snow/init.lua b/mods/snow/init.lua index 86ad7232..01a5676e 100755 --- a/mods/snow/init.lua +++ b/mods/snow/init.lua @@ -24,12 +24,12 @@ http://github.com/Splizard/minetest-mod-snow/ it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, @@ -57,7 +57,7 @@ dofile(minetest.get_modpath("snow").."/src/snowball.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 +-- 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") -- To get Xmas tree saplings, the "christmas_content", true or false, in "util.lua" has to be determined first. @@ -71,7 +71,7 @@ dofile(minetest.get_modpath("snow").."/src/sled.lua") -- Check for "MoreBlocks". If not found, skip this next "dofile". -if (minetest.get_modpath("moreblocks")) then +if minetest.get_modpath("moreblocks") then dofile(minetest.get_modpath("snow").."/src/stairsplus.lua") @@ -82,34 +82,52 @@ end function snow.place(pos) if pos.y < -19000 then return end -- Don't put anything in the nether! local node = minetest.get_node_or_nil(pos) - local drawtype = "" - if node and minetest.registered_nodes[node.name] then - drawtype = minetest.registered_nodes[node.name].drawtype - end - + --Oops, maybe there is no node? - if node == nil then + if not node + or not minetest.registered_nodes[node.name] then return end - local bnode = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}) - if node.name == "default:snow" and minetest.get_node_level(pos) < 63 then - if minetest.get_item_group(bnode.name, "leafdecay") == 0 and snow.is_uneven(pos) ~= true then - minetest.add_node_level(pos, 7) + 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 + minetest.sound_play("default_snow_footstep", {pos=pos}) + minetest.add_node_level(pos, 7) + end + elseif level == 63 then + local p = minetest.find_node_near(pos, 10, "default:dirt_with_grass") + if p + and minetest.get_node_light(p, 0.5) == 15 then + minetest.sound_play("default_grass_footstep", {pos=pos}) + minetest.place_node({x=pos.x, y=pos.y+1, z=pos.z}, {name="default:snow"}) + else + minetest.sound_play("default_snow_footstep", {pos=pos}) + minetest.add_node(pos, {name="default:snowblock"}) + end end - elseif node.name == "default:snow" and minetest.get_node_level(pos) == 63 then - local p = minetest.find_node_near(pos, 10, "default:dirt_with_grass") - if p and minetest.get_node_light(p, 0.5) == 15 then - minetest.place_node({x=pos.x,y=pos.y+1,z=pos.z},{name="default:snow"}) - else - minetest.add_node(pos,{name="default:snowblock"}) - end - elseif node.name ~= "default:ice" and bnode.name ~= "air" then - if drawtype == "normal" or drawtype == "allfaces_optional" then - minetest.place_node({x=pos.x,y=pos.y+1,z=pos.z}, {name="default:snow"}) + elseif node.name ~= "default:ice" + and bnode.name ~= "air" then + local data = minetest.registered_nodes[node.name] + local drawtype = data.drawtype + if drawtype == "normal" + or drawtype == "allfaces_optional" then + pos.y = pos.y+1 + local sound = data.sounds + if sound then + sound = sound.footstep + if sound then + minetest.sound_play(sound.name, {pos=pos, gain=sound.gain}) + end + end + minetest.place_node(pos, {name="default:snow"}) elseif drawtype == "plantlike" then pos.y = pos.y - 1 if minetest.get_node(pos).name == "default:dirt_with_grass" then + minetest.sound_play("default_grass_footstep", {pos=pos}) minetest.add_node(pos, {name="default:dirt_with_snow"}) end end @@ -118,50 +136,56 @@ end -- Checks if the snow level is even at any given pos. -- Smooth Snow -local smooth_snow = snow.smooth_snow -snow.is_uneven = function(pos) - if smooth_snow then - 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 x=-1,1 do - for z=-1,1 do - local node = get_node({x=pos.x+x,y=pos.y,z=pos.z+z}) - local bnode = get_node({x=pos.x+x,y=pos.y-1,z=pos.z+z}) - local drawtype - if node and minetest.registered_nodes[node.name] then - drawtype = minetest.registered_nodes[node.name].drawtype +local function is_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 + local p = {x=pos.x+x, y=pos.y, z=pos.z+z} + local node = get_node(p) + p.y = p.y-1 + local bnode = get_node(p) + + if node + and minetest.registered_nodes[node.name] + and minetest.registered_nodes[node.name].drawtype == "plantlike" + and bnode.name == "default:dirt_with_grass" then + add_node(p, {name="default:dirt_with_snow"}) + return true end - - if drawtype == "plantlike" then - if bnode.name == "default:dirt_with_grass" then - add_node({x=pos.x+x,y=pos.y-1,z=pos.z+z}, {name="default:dirt_with_snow"}) - return true - end - end - - if (not(x == 0 and y == 0)) and node.name == "default:snow" and minetest.get_node_level({x=pos.x+x,y=pos.y,z=pos.z+z}) < num then + + p.y = p.y+1 + 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" and bnode.name ~= "air" then - if not (bnode.name == "default:snow") then - snow.place({x=pos.x+x,y=pos.y-1,z=pos.z+z}) - return true - end + foundz = z + elseif node.name == "air" + and bnode.name ~= "air" + and bnode.name ~= "default:snow" then + p.y = p.y-1 + snow.place(p) + return true end end - end - if found then - local node = get_node({x=pos.x+foundx,y=pos.y,z=pos.z+foundz}) - if snow.is_uneven({x=pos.x+foundx,y=pos.y,z=pos.z+foundz}) ~= true then - minetest.add_node_level({x=pos.x+foundx,y=pos.y,z=pos.z+foundz}, 7) - end - return true - end + end + if found then + local p = {x=pos.x+foundx, y=pos.y, z=pos.z+foundz} + if is_uneven(p) ~= true 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 end diff --git a/mods/snow/src/abms.lua b/mods/snow/src/abms.lua index 8197bfea..04ae8d9f 100755 --- a/mods/snow/src/abms.lua +++ b/mods/snow/src/abms.lua @@ -52,7 +52,7 @@ minetest.register_abm({ elseif intensity == 2 then minetest.add_node(pos,{name="default:water_flowing", param2=7}) --[[ LazyJ, you need to add param2, which defines the amount of the flowing water ~ HybridDog 2015_03_06 - This was causing "melts=2" nodes to just disappear so I changed it to replace the + This was causing "melts=2" nodes to just disappear so I changed it to replace the node with a water_source for a couple seconds and then replace the water_source with air. This way it made a watery mess that quickly evaporated. ~ LazyJ 2014_04_24 local check_place = function(pos,node) @@ -70,7 +70,7 @@ minetest.register_abm({ minetest.add_node(pos,{name="default:water_source"}) minetest.after(2, function() -- 2 seconds gives just enough time for -- the water to flow and spread before the - -- water_source is changed to air. ~ LazyJ + -- water_source is changed to air. ~ LazyJ if minetest.get_node(pos).name == "default:water_source" then minetest.add_node(pos,{name="air"}) end @@ -150,7 +150,7 @@ minetest.register_abm({ minetest.register_abm({ nodenames = {"snow:sapling_pine"}, interval = 10, - chance = 50, + chance = 50, action = function(pos, node) -- Check if there is enough vertical-space for the sapling to grow without @@ -169,7 +169,7 @@ minetest.register_abm({ if minetest.get_node(pos).name == "snow:sapling_pine" then -- This switches the sapling to a tree trunk. ~ LazyJ minetest.set_node(pos, {name="default:pinetree"}) - -- This is more for testing but it may be useful info to some admins when + -- This is more for testing but it may be useful info to some admins when -- grepping the server logs too. ~ LazyJ minetest.log("action", "A pine sapling grows into a tree at "..minetest.pos_to_string(pos)) end diff --git a/mods/snow/src/basic_stairs_slabs.lua b/mods/snow/src/basic_stairs_slabs.lua index d62f4488..a65872dc 100755 --- a/mods/snow/src/basic_stairs_slabs.lua +++ b/mods/snow/src/basic_stairs_slabs.lua @@ -9,7 +9,7 @@ -snow_stairs = {} -- This is a little trick. Without it Minetest will complain +snow_stairs = {} -- This is a little trick. Without it Minetest will complain -- "attempt to index global 'snow' (a nil value)" and -- refuse to load. So a value without definition "={}"is assigned to snow. @@ -66,11 +66,11 @@ function snow_stairs.register_stair(subname, recipeitem, groups, images, descrip return minetest.item_place(itemstack, placer, pointed_thing, param2) end, - + on_construct = function(pos) pos.y = pos.y - 1 if minetest.get_node(pos).name == "default:dirt_with_grass" - -- Thinking in terms of layers, dirt_with_snow could also double as + -- Thinking in terms of layers, dirt_with_snow could also double as -- dirt_with_frost which adds subtlety to the winterscape. ~ LazyJ, 2014_04_04 or minetest.get_node(pos).name == "default:dirt" then minetest.set_node(pos, {name="default:dirt_with_snow"}) @@ -168,7 +168,7 @@ function snow_stairs.register_slab(subname, recipeitem, groups, images, descript end return itemstack end - + -- Upside down slabs if p0.y-1 == p1.y then -- Turn into full block if pointing at a existing slab @@ -203,17 +203,17 @@ function snow_stairs.register_slab(subname, recipeitem, groups, images, descript return minetest.item_place(itemstack, placer, pointed_thing, param2) end, - + on_construct = function(pos) pos.y = pos.y - 1 if minetest.get_node(pos).name == "default:dirt_with_grass" - -- Thinking in terms of layers, dirt_with_snow could also double as + -- Thinking in terms of layers, dirt_with_snow could also double as -- dirt_with_frost which adds subtlety to the winterscape. ~ LazyJ, 2014_04_04 or minetest.get_node(pos).name == "default:dirt" then minetest.set_node(pos, {name="default:dirt_with_snow"}) end end - + }) --[[ -- for replace ABM @@ -296,7 +296,7 @@ for _, row in ipairs(list_of_snow_stuff) do true ) -end -- End the "list of snow stuff" part of the above section. ~ LazyJ +end -- End the "list of snow stuff" part of the above section. ~ LazyJ -- Snow stairs and slabs should be easier to break than the more dense and diff --git a/mods/snow/src/crafting.lua b/mods/snow/src/crafting.lua index 657ce669..fcc1706a 100755 --- a/mods/snow/src/crafting.lua +++ b/mods/snow/src/crafting.lua @@ -48,11 +48,11 @@ minetest.register_craft({ -- 2. Cooking --[[ -"Cooks_into_ice" is a custom group I assigned to full-sized, snow-stuff nodes +"Cooks_into_ice" is a custom group I assigned to full-sized, snow-stuff nodes (snow bricks, snow cobble, snow blocks, etc.) so I wouldn't have to write an individual cooking recipe for each one. -~ LazyJ +~ LazyJ --]] minetest.register_craft({ @@ -203,7 +203,7 @@ for _, name in pairs(recycle_default_slabs) do recipe = { "snow:slab_"..subname_default, "snow:slab_"..subname_default, - } + } }) end @@ -229,6 +229,6 @@ for _, name in pairs(recycle_snowmod_slabs) do recipe = { "snow:slab_"..subname_snowmod, "snow:slab_"..subname_snowmod, - } + } }) end diff --git a/mods/snow/src/falling_snow.lua b/mods/snow/src/falling_snow.lua index c0983fcb..1e40257e 100755 --- a/mods/snow/src/falling_snow.lua +++ b/mods/snow/src/falling_snow.lua @@ -40,10 +40,6 @@ near torches and lava. --============================================================= -if not snow.enable_snowfall then - return -end - local weather_legacy local read_weather_legacy = function () @@ -84,7 +80,7 @@ local PERSISTENCE3 = 0.5 -- 0.5 local SCALE3 = 250 -- 250 --Get snow at position. -local get_snow = function(pos) +local function get_snow(pos) --Legacy support. if weather_legacy == "snow" then local perlin1 = minetest.get_perlin(112,3, 0.5, 150) @@ -106,14 +102,19 @@ end local addvectors = vector and vector.add --Returns a random position between minp and maxp. -local randpos = function (minp, maxp) - local x,y,z +local function randpos(minp, maxp) + local x,z if minp.x > maxp.x then - x = math.random(maxp.x,minp.x) else x = math.random(minp.x,maxp.x) end - y = minp.y + x = math.random(maxp.x,minp.x) + else + x = math.random(minp.x,maxp.x) + end if minp.z > maxp.z then - z = math.random(maxp.z,minp.z) else z = math.random(minp.z,maxp.z) end - return {x=x,y=y,z=z} + z = math.random(maxp.z,minp.z) + else + z = math.random(minp.z,maxp.z) + end + return {x=x,y=minp.y,z=z} end local default_snow_particle = { @@ -152,22 +153,20 @@ local function snow_fall(pos, player, animate) break end end - if not ground_y then return end - pos = {x=pos.x, y=ground_y, z=pos.z} - local spos = {x=pos.x, y=ground_y+10, z=pos.z} + if not ground_y then + return + end + + pos = {x=pos.x, y=ground_y, z=pos.z} - if get_snow(pos) then if animate then - local minp = addvectors(spos, {x=-9, y=3, z=-9}) - local maxp = addvectors(spos, {x= 9, y=5, z= 9}) - local vel = {x=0, y= -1, z=-1} - local acc = {x=0, y= 0, z=0} + local spos = {x=pos.x, y=ground_y+10, z=pos.z} minetest.add_particlespawner(get_snow_particledef({ - minpos = minp, - maxpos = maxp, - vel = vel, - acc = acc, + 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 @@ -177,30 +176,21 @@ local function snow_fall(pos, player, animate) end -- Snow -minetest.register_globalstep(function(dtime) +local function calc_snowfall() for _, player in pairs(minetest.get_connected_players()) do local ppos = player:getpos() - - local sminp = addvectors(ppos, {x=-20, y=0, z=-20}) - local smaxp = addvectors(ppos, {x= 20, y=0, z= 20}) - + -- Make sure player is not in a cave/house... - if get_snow(ppos) and minetest.get_node_light(ppos, 0.5) == 15 then - - local minp = addvectors(ppos, {x=-9, y=3, z=-9}) - local maxp = addvectors(ppos, {x= 9, y=5, z= 9}) - - local minp_deep = addvectors(ppos, {x=-5, y=3.2, z=-5}) - local maxp_deep = addvectors(ppos, {x= 5, y=1.6, z= 5}) - - local vel = {x=0, y= -1, z=-1} - local acc = {x=0, y= 0, z=0} - + if get_snow(ppos) + and minetest.get_node_light(ppos, 0.5) == 15 then + local animate if not snow.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({ amount = 5, - minpos = minp, - maxpos = maxp, + minpos = addvectors(ppos, {x=-9, y=3, z=-9}), + maxpos = addvectors(ppos, {x= 9, y=5, z= 9}), vel = vel, acc = acc, size = 25, @@ -209,8 +199,8 @@ minetest.register_globalstep(function(dtime) minetest.add_particlespawner(get_snow_particledef({ amount = 4, - minpos = minp_deep, - maxpos = maxp_deep, + minpos = addvectors(ppos, {x=-5, y=3.2, z=-5}), + maxpos = addvectors(ppos, {x= 5, y=1.6, z= 5}), vel = vel, acc = acc, exptime = 4, @@ -218,14 +208,27 @@ minetest.register_globalstep(function(dtime) playername = player:get_player_name() })) - if math.random(1,5) == 4 then - snow_fall(randpos(sminp, smaxp), player) - end + animate = false else - if math.random(1,5) == 4 then - snow_fall(randpos(sminp, smaxp), player, true) - end + animate = true + end + + if math.random(1,5) == 4 then + snow_fall( + randpos( + addvectors(ppos, {x=-20, y=0, z=-20}), + addvectors(ppos, {x= 20, y=0, z= 20}) + ), + player, + animate + ) end end end +end + +minetest.register_globalstep(function(dtime) + if snow.enable_snowfall then + calc_snowfall() + end end) diff --git a/mods/snow/src/mapgen.lua b/mods/snow/src/mapgen.lua index b8a11298..455c92df 100755 --- a/mods/snow/src/mapgen.lua +++ b/mods/snow/src/mapgen.lua @@ -1,8 +1,8 @@ --[[ -If you want to run PlantLife and mods that depend on it, i.e. MoreTrees, Disable the mapgen by +If you want to run PlantLife and mods that depend on it, i.e. MoreTrees, Disable the mapgen by commenting-out the lines starting with "local mgname = " through "end" (I left a note were to start -and stop) Disabling "Snow's" mapgen allows MoreTrees and PlantLife to do their thing until the -issue is figured out. However, the pine and xmas tree code is still needed for when those +and stop) Disabling "Snow's" mapgen allows MoreTrees and PlantLife to do their thing until the +issue is figured out. However, the pine and xmas tree code is still needed for when those saplings grow into trees. --]] --The *starting* comment looks like this: --[[ --The *closing* comment looks like this: --]] @@ -13,13 +13,10 @@ saplings grow into trees. --]] -- Part 1: To disable the mapgen, add the *starting* comment under this line. -local mgname = "" - --Identify the mapgen. minetest.register_on_mapgen_init(function(MapgenParams) - if MapgenParams.mgname then - mgname = MapgenParams.mgname - else + 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 @@ -72,20 +69,21 @@ function snow.make_pine(pos,snow,xmas) 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" or n == "ignore" then - minetest.add_node(pos,node) + if n == "air" + or n == "ignore" then + minetest.add_node(pos, node) end end --Clear ground. - for x=-1,1 do - for z=-1,1 do - if minetest.get_node({x=pos.x+x,y=pos.y,z=pos.z+z}).name == "default:snow" then - minetest.remove_node({x=pos.x+x,y=pos.y,z=pos.z+z}) + for z = -1,1 do + for x = -1,1 do + local p = {x=pos.x+x,y=pos.y,z=pos.z+z} + local nd = minetest.get_node(p).name + if nd == "default:snow" + or nd == "default:snowblock" then + minetest.remove_node(p) + end end - if minetest.get_node({x=pos.x+x,y=pos.y,z=pos.z+z}).name == "default:snowblock" then - minetest.remove_node({x=pos.x+x,y=pos.y,z=pos.z+z}) - end - end end if xmas then minetest.remove_node(pos) @@ -107,7 +105,8 @@ function snow.make_pine(pos,snow,xmas) end 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 + elseif snow + and perlin1:get2d({x=pos.x,y=pos.z}) > 0.53 then try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="default:snow"}) end end @@ -121,60 +120,62 @@ 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) - --Clear ground. - for x=-1,1 do - for z=-1,1 do - local node = a:index(pos.x+x,pos.y,pos.z+z) - if data[node] == c_snow then - data[node] = c_air - end - end - end - --Make tree. - for i=0, 4 do - if i==1 or i==2 then - for x=-1,1 do - for z=-1,1 do - local x = pos.x + x - local z = pos.z + z + local perlin1 = minetest.get_perlin(112,3, 0.5, 150) + for z = -1,1 do + local z = pos.z + z + for x = -1,1 do + local x = pos.x + x + + --Clear ground. + local node = a:index(x,pos.y,z) + if data[node] == c_snow then + data[node] = c_air + end + + --Make tree. + for i = 1,2 do local node = a:index(x,pos.y+i,z) data[node] = c_pine_needles - if snow and x ~= 0 and z ~= 0 and perlin1:get2d({x=x,y=z}) > 0.53 then + if snow + and x ~= 0 + and z ~= 0 + and perlin1:get2d({x=x,y=z}) > 0.53 then local abovenode = a:index(x,pos.y+i+1,z) data[abovenode] = c_snow end end + end + end + for i=3, 4 do + local x = pos.x + local y = pos.y+i + local z = pos.z + data[a:index(x+1,y,z)] = c_pine_needles + 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 snow then + if perlin1:get2d({x=x+1,y=z}) > 0.53 then + data[a:index(x+1,y+1,z)] = c_snow + end + if perlin1:get2d({x=x+1,y=z}) > 0.53 then + data[a:index(x-1,y+1,z)] = c_snow + end + if perlin1:get2d({x=x,y=z+1}) > 0.53 then + data[a:index(x,y+1,z+1)] = c_snow + end + if perlin1:get2d({x=x,y=z-1}) > 0.53 then + data[a:index(x,y+1,z-1)] = c_snow end end - if i==3 or i==4 then - local x = pos.x - local y = pos.y+i - local z = pos.z - data[a:index(x+1,y,z)] = c_pine_needles - 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 snow then - if perlin1:get2d({x=x+1,y=z}) > 0.53 then - data[a:index(x+1,y+1,z)] = c_snow - end - if perlin1:get2d({x=x+1,y=z}) > 0.53 then - data[a:index(x-1,y+1,z)] = c_snow - end - if perlin1:get2d({x=x,y=z+1}) > 0.53 then - data[a:index(x,y+1,z+1)] = c_snow - end - if perlin1:get2d({x=x,y=z-1}) > 0.53 then - data[a:index(x,y+1,z-1)] = c_snow - end - end - end + end + for i=0, 4 do data[a:index(pos.x,pos.y+i,pos.z)] = c_pinetree 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 snow and perlin1:get2d({x=pos.x,y=pos.z}) > 0.53 then + if snow + and perlin1:get2d({x=pos.x,y=pos.z}) > 0.53 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 7f0c51c0..0bb01fe1 100755 --- a/mods/snow/src/mapgen_v6.lua +++ b/mods/snow/src/mapgen_v6.lua @@ -22,33 +22,38 @@ local np_ice = { -- Debugging function -local biome_to_string = function(num,num2) - local biome, biome2 - if num == 1 then - biome = "snowy" - elseif num == 2 then - biome = "plain" - elseif num == 3 then - biome = "alpine" - elseif num == 4 or num == 5 then - biome = "normal" - else - biome = "unknown "..num +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 y = 0 + for k=1,1000 do + y = y + 1000*(math.sin(math.pi * k^a * n)/(math.pi * k^a)) end - if num2 == 1 then - biome2 = "cool" - elseif num2 == 2 then - biome2 = "icebergs" - elseif num2 == 3 then - biome2 = "icesheet" - elseif num2 == 4 then - biome2 = "icecave" - elseif num2 == 5 then - biome2 = "icehole" - else - biome2 = "unknown "..num - end - return biome, biome2 + return y +end + +local ws_lists = {} +local function get_ws_list(a,x) + ws_lists[a] = ws_lists[a] or {} + local v = ws_lists[a][x] + if v then + return v + end + v = {} + for x=x,x + (80 - 1) do + local y = do_ws_func(a, x) + v[x] = y + end + ws_lists[a][x] = v + return v end -- On generated function @@ -60,12 +65,9 @@ minetest.register_on_generated(function(minp, maxp, seed) local z0 = minp.z local x1 = maxp.x local z1 = maxp.z - - local debug = snow.debug - local min_height = snow.min_height + local spawn_pine = snow.voxelmanip_pine local smooth = snow.smooth_biomes - local legacy = snow.legacy local c_dirt_with_grass = minetest.get_content_id("default:dirt_with_grass") local c_dirt = minetest.get_content_id("default:dirt") @@ -91,30 +93,21 @@ minetest.register_on_generated(function(minp, maxp, seed) local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax}) local data = vm:get_data() + local snow_tab,num = {},1 + local sidelen = x1 - x0 + 1 local chulens = {x=sidelen, y=sidelen, z=sidelen} - local minpos = {x=x0, y=z0} local nvals_cold = minetest.get_perlin_map(np_cold, chulens):get2dMap_flat({x=x0, y=z0}) local nvals_ice = minetest.get_perlin_map(np_ice, chulens):get2dMap_flat({x=x0, y=z0}) -- Choose biomes local pr = PseudoRandom(seed+57) - local biome -- Land biomes - biome = pr:next(1, 5) + local biome = pr:next(1, 5) local snowy = biome == 1 -- spawns alot of snow - local plain = biome == 2 -- spawns not much local alpine = biome == 3 -- rocky terrain - -- Water biomes - local biome2 = pr:next(1, 5) - local cool = biome == 1 -- only spawns ice on edge of water - local icebergs = biome == 2 - local icesheet = biome == 3 - local icecave = biome == 4 - local icehole = biome == 5 -- icesheet with holes -- Misc biome settings local icy = pr:next(1, 2) == 2 -- if enabled spawns ice in sand instead of snow blocks - local mossy = pr:next(1,2) == 1 -- spawns moss in snow local shrubs = pr:next(1,2) == 1 -- spawns dry shrubs in snow local pines = pr:next(1,2) == 1 -- spawns pines -- Reseed random @@ -135,11 +128,12 @@ minetest.register_on_generated(function(minp, maxp, seed) end if not in_biome then - if alpine == true and test > 0.43 then + if alpine and test > 0.43 then 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 + if nodid ~= c_air + and nodid ~= c_ignore then ground_y = y break end @@ -147,7 +141,7 @@ minetest.register_on_generated(function(minp, maxp, seed) if ground_y then local vi = area:index(x, ground_y, z) - if data[vi] == c_leaves or data[vi] == c_jungleleaves then + if data[vi] == c_leaves or data[vi] == c_jungleleaves then for y = ground_y, -16, -1 do local vi = area:index(x, y, z) local id = data[vi] @@ -155,7 +149,6 @@ minetest.register_on_generated(function(minp, maxp, seed) if id == c_leaves or id == c_jungleleaves or id == c_tree - or id == c_air or id == c_apple then data[vi] = c_air else @@ -163,15 +156,15 @@ minetest.register_on_generated(function(minp, maxp, seed) end end end - end - end - end + end + end + end elseif in_biome then write_to_map = true local icetype = nvals_ice[ni] - local cool = icetype > 0 + 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 + 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 @@ -183,7 +176,7 @@ minetest.register_on_generated(function(minp, maxp, seed) break end end - + if ground_y then local node = area:index(x, ground_y, z) local abovenode = area:index(x, ground_y+1, z) @@ -191,7 +184,8 @@ minetest.register_on_generated(function(minp, maxp, seed) if ground_y and data[node] == c_dirt_with_grass then if alpine and test > 0.53 then - data[abovenode] = c_snow + snow_tab[num] = {abovenode, z, x, test} + num = num+1 for y = ground_y, -6, -1 do local vi = area:index(x, y, z) if data[vi] == c_stone then @@ -210,18 +204,21 @@ minetest.register_on_generated(function(minp, maxp, seed) data[abovenode] = c_snow_block else data[node] = c_dirt_with_snow - data[abovenode] = c_snow + snow_tab[num] = {abovenode, z, x, test} + num = num+1 end elseif ground_y and data[node] == c_sand then if not icy then - data[abovenode] = c_snow + snow_tab[num] = {abovenode, z, x, test} + num = num+1 else data[node] = c_ice end elseif ground_y and data[node] == c_leaves or data[node] == c_jungleleaves or data[node] == c_apple then if alpine then - data[abovenode] = c_snow + snow_tab[num] = {abovenode, z, x, test} + num = num+1 for y = ground_y, -6, -1 do local stone = area:index(x, y, z) if data[stone] == c_stone then @@ -231,54 +228,64 @@ minetest.register_on_generated(function(minp, maxp, seed) end end else - data[abovenode] = c_snow + snow_tab[num] = {abovenode, z, x, test} + num = num+1 end - elseif ground_y and data[node] == c_junglegrass then + elseif ground_y + and data[node] == c_junglegrass then data[node] = c_dry_shrub - elseif ground_y and data[node] == c_papyrus then + elseif ground_y + and data[node] == c_papyrus then for y = ground_y, ground_y-4, -1 do local vi = area:index(x, y, z) if data[vi] == c_papyrus then - local via = area:index(x, ground_y, z) - data[via] = c_snow + snow_tab[num] = {area:index(x, ground_y, z), z, x, test} + num = num+1 data[vi] = c_snow_block end end - elseif ground_y and data[node] == c_water then - if not icesheet and not icecave and not icehole then + elseif ground_y + and data[node] == c_water then + if not icesheet + and not icecave + and not icehole then local x1 = data[area:index(x+1, ground_y, z)] local z1 = data[area:index(x, ground_y, z+1)] local xz1 = data[area:index(x+1, ground_y, z+1)] local xz2 = data[area:index(x-1, ground_y, z-1)] local x2 = data[area:index(x-1, ground_y, z)] local z2 = data[area:index(x, ground_y, z-1)] + local rand = (pr:next(1,4) == 1) and (cool or icebergs) + local ice + if rand then + for _,i in ipairs({x1,z1,xz1,xz2,x2,z2}) do + if i == c_ice then + ice = true + break + end + end + end + if not ice then + for _,i in ipairs({x1,z1,xz1,xz2,x2,z2}) do + if i ~= c_water + and i ~= c_ice + and i ~= c_air + and i ~= c_ignore then + ice = true + break + end + end + end local y = data[area:index(x, ground_y-1, z)] - local rand = pr:next(1,4) == 1 - if ((x1 and x1 ~= c_water and x1 ~= c_ice - and x1 ~= c_air and x1 ~= c_ignore) - or (rand and (cool or icebergs) and x1 == c_ice)) - or ((z1 and z1 ~= c_water and z1 ~= c_ice - and z1 ~= c_air and z1 ~= c_ignore) - or (rand and (cool or icebergs) and z1 == c_ice)) - or ((xz1 and xz1 ~= c_water and xz1 ~= c_ice - and xz1 ~= c_air and xz1 ~= c_ignore) - or (rand and (cool or icebergs) and xz1 == c_ice)) - or ((xz2 and xz2 ~= c_water and xz2 ~= c_ice - and xz2 ~= c_air and xz2 ~= c_ignore) - or (rand and (cool or icebergs) and xz2 == c_ice)) - or ((x2 and x2 ~= c_water and x2 ~= c_ice - and x2 ~= c_air and x2 ~= c_ignore) - or (rand and (cool or icebergs) and x2 == c_ice)) - or ((z2 and z2 ~= c_water and z2 ~= c_ice - and z2 ~= c_air and z2 ~= c_ignore) - or (rand and (cool or icebergs) and z2 == c_ice)) + if ice or (y ~= c_water and y ~= c_ice) -- and y ~= "air") …I don't think y can be a string here ~HybridDog or (icebergs and pr:next(1,6) == 1) then data[node] = c_ice end else if (icehole and pr:next(1,10) > 1) - or icecave or icesheet then + or icecave + or icesheet then data[node] = c_ice end if icecave then @@ -299,15 +306,46 @@ minetest.register_on_generated(function(minp, maxp, seed) end end + local param2s + if num ~= 1 then + local wsz, wsx + for _,i in pairs(snow_tab) do + local p,z,x,test = unpack(i) + data[p] = c_snow + test = test-0.73 + if test > 0 then + local minh = math.floor(test*4*9)%9+1 + if minh ~= 1 then + if not wsz then + wsz = get_ws_list(5, z0) + wsx = get_ws_list(2, x0) + param2s = vm:get_param2_data() + end + local h = math.min(minh, math.floor(wsx[x]+wsz[z]*5)%9+1) + if h ~= 1 then + if h == 9 then + h = 4 + end + param2s[p] = h*7 + end + end + end + end + end + vm:set_data(data) + if param2s then + vm:set_param2_data(param2s) + end vm:set_lighting({day=0, night=0}) vm:calc_lighting() vm:write_to_map() - if write_to_map and debug then -- print if any column of mapchunk was snow biome - local biome_string,biome2_string = biome_to_string(biome,biome2) + if write_to_map + and snow.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.." and "..biome2_string.." x "..minp.x.." z "..minp.z.." time "..chugent.." ms") + print("[snow] "..biome_string.." x "..minp.x.." z "..minp.z.." time "..chugent.." ms") end end) diff --git a/mods/snow/src/mapgen_v7.lua b/mods/snow/src/mapgen_v7.lua index 2fd83e2a..ebb3eedb 100755 --- a/mods/snow/src/mapgen_v7.lua +++ b/mods/snow/src/mapgen_v7.lua @@ -55,12 +55,12 @@ minetest.register_biome({ minetest.register_biome({ name = "snow_biome_sand", - + node_top = "default:sand", depth_top = 3, node_filler = "default:stone", depth_filler = 0, - + height_min = -31000, height_max = 2, heat_point = 10.0, diff --git a/mods/snow/src/nodes.lua b/mods/snow/src/nodes.lua index 03f4f6c8..c2582bd6 100755 --- a/mods/snow/src/nodes.lua +++ b/mods/snow/src/nodes.lua @@ -35,10 +35,10 @@ The Xmas tree needles are registred and defined a farther down in this nodes.lua ~ LazyJ --]] - + if snow.christmas_content then --Christmas trees - + minetest.override_item("snow:needles", { drop = { max_items = 1, @@ -61,9 +61,9 @@ if snow.christmas_content then } } }) -end - - +end + + --Christmas easter egg minetest.register_on_mapgen_init( function() if rawget(_G, "skins") then @@ -75,7 +75,7 @@ end --[[ -Original, static Xmas lights. Keep so people can "turn off" the +Original, static Xmas lights. Keep so people can "turn off" the animation if it is too much for them. ~ LazyJ --Decorated Pine leaves @@ -179,7 +179,7 @@ minetest.register_node("snow:sapling_pine", { walkable = false, groups = {snappy=2,dig_immediate=3}, sounds = default.node_sound_defaults(), - + }) @@ -197,8 +197,9 @@ minetest.register_node("snow:star", { --groups = {snappy=2,dig_immediate=3}, groups = {cracky=1, crumbly=1, choppy=1, oddly_breakable_by_hand=1}, -- Don't want the ornament breaking too easily because you have to punch it to turn it on and off. ~ LazyJ sounds = default.node_sound_glass_defaults({dig = {name="default_glass_footstep", gain=0.2}}), -- Breaking "glass" sound makes it sound like a real, broken, Xmas tree ornament (Sorry, Mom!). ;)- ~ LazyJ - on_punch = function(pos, node, puncher) -- Added a "lit" star that can be punched on or off depending on your preference. ~ LazyJ - minetest.set_node(pos, {name = "snow:star_lit"}) + on_punch = function(pos, node) -- Added a "lit" star that can be punched on or off depending on your preference. ~ LazyJ + node.name = "snow:star_lit" + minetest.set_node(pos, node) nodeupdate(pos) end, }) @@ -217,8 +218,9 @@ minetest.register_node("snow:star_lit", { drop = "snow:star", groups = {cracky=1, crumbly=1, choppy=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1}, sounds = default.node_sound_glass_defaults({dig = {name="default_glass_footstep", gain=0.2}}), - on_punch = function(pos, node, puncher) - minetest.set_node(pos, {name = "snow:star"}) + on_punch = function(pos, node) + node.name = "snow:star" + minetest.set_node(pos, node) nodeupdate(pos) end, }) @@ -264,9 +266,9 @@ minetest.register_node("snow:snow_brick", { liquidtype = "none", paramtype = "light", sunlight_propagates = true, - paramtype2 = "facedir", -- Allow blocks to be rotated with the screwdriver or + paramtype2 = "facedir", -- Allow blocks to be rotated with the screwdriver or -- by player position. ~ LazyJ - -- I made this a little harder to dig than snow blocks because + -- I made this a little harder to dig than snow blocks because -- I imagine snow brick as being much more dense and solid than fluffy snow. ~ LazyJ groups = {cracky=2, crumbly=2, choppy=2, oddly_breakable_by_hand=2, melts=1, icemaker=1, cooks_into_ice=1}, --Let's use the new snow sounds instead of the old grass sounds. ~ LazyJ @@ -276,7 +278,7 @@ minetest.register_node("snow:snow_brick", { dug = {name="default_snow_footstep", gain=0.75}, place = {name="default_place_node", gain=1.0} }), - -- The "on_construct" part below, thinking in terms of layers, dirt_with_snow could also + -- The "on_construct" part below, thinking in terms of layers, dirt_with_snow could also -- double as dirt_with_frost which adds subtlety to the winterscape. ~ LazyJ on_construct = snow_onto_dirt }) @@ -291,9 +293,9 @@ minetest.register_node("snow:snow_cobble", { is_ground_content = true, liquidtype = "none", paramtype = "light", - sunlight_propagates = true, + sunlight_propagates = true, paramtype2 = "facedir", - -- I made this a little harder to dig than snow blocks because + -- I made this a little harder to dig than snow blocks because -- I imagine snow brick as being much more dense and solid than fluffy snow. ~ LazyJ groups = {cracky=2, crumbly=2, choppy=2, oddly_breakable_by_hand=2, melts=1, icemaker=1, cooks_into_ice=1}, sounds = default.node_sound_dirt_defaults({ @@ -302,7 +304,7 @@ minetest.register_node("snow:snow_cobble", { dug = {name="default_snow_footstep", gain=0.75}, place = {name="default_place_node", gain=1.0} }), - -- The "on_construct" part below, thinking in terms of layers, dirt_with_snow could also + -- The "on_construct" part below, thinking in terms of layers, dirt_with_snow could also -- double as dirt_with_frost which adds subtlety to the winterscape. ~ LazyJ on_construct = snow_onto_dirt }) @@ -313,7 +315,7 @@ minetest.register_node("snow:snow_cobble", { -- This adds code to the existing default ice. ~ LazyJ minetest.override_item("default:ice", { - -- The Lines: 1. Alpah to make semi-transparent ice, 2 to work with + -- The Lines: 1. Alpah to make semi-transparent ice, 2 to work with -- the dirt_with_grass/snow/just dirt ABMs. ~ LazyJ, 2014_03_09 use_texture_alpha = true, -- 1 param2 = 0, @@ -328,7 +330,7 @@ minetest.override_item("default:ice", { on_construct = snow_onto_dirt, liquids_pointable = true, --Make ice freeze over when placed by a maximum of 10 blocks. - after_place_node = function(pos, placer, itemstack, pointed_thing) + after_place_node = function(pos) minetest.set_node(pos, {name="default:ice", param2=math.random(0,10)}) end }) @@ -344,6 +346,6 @@ minetest.override_item("default:snowblock", { groups = {cracky=3, crumbly=3, choppy=3, oddly_breakable_by_hand=3, melts=1, icemaker=1, cooks_into_ice=1, falling_node=1}, --drop = "snow:snow_cobble", on_construct = snow_onto_dirt - -- Thinking in terms of layers, dirt_with_snow could also double as + -- Thinking in terms of layers, dirt_with_snow could also double as -- dirt_with_frost which adds subtlety to the winterscape. ~ LazyJ, 2014_04_04 }) diff --git a/mods/snow/src/sled.lua b/mods/snow/src/sled.lua index d3728c66..f8358c3c 100755 --- a/mods/snow/src/sled.lua +++ b/mods/snow/src/sled.lua @@ -15,9 +15,9 @@ THE LIST OF CHANGES I'VE MADE -* The HUD message that displayed when a player sat on the sled would not go away after the player -got off the sled. I spent hours on trial-and-error while reading the lua_api.txt and scrounging -the Internet for a needle-in-the-haystack solution as to why the hud_remove wasn't working. +* The HUD message that displayed when a player sat on the sled would not go away after the player +got off the sled. I spent hours on trial-and-error while reading the lua_api.txt and scrounging +the Internet for a needle-in-the-haystack solution as to why the hud_remove wasn't working. Turns out Splizard's code was mostly correct, just not assembled in the right order. The key to the solution was found in the code of leetelate's scuba mod: @@ -30,15 +30,16 @@ http://forum.minetest.net/viewtopic.php?id=7175 TODO ~~~~~~ -* Figure out why the player avatars remain in a seated position, even after getting off the sled, -if they flew while on the sled. 'default.player_set_animation', where is a better explanation +* Figure out why the player avatars remain in a seated position, even after getting off the sled, +if they flew while on the sled. 'default.player_set_animation', where is a better explanation for this and what are it's available options? -* Go through, clean-up my notes and get them better sorted. Some are in the code, some are -scattered in my note-taking program. This "Oh, I'll just make a little tweak here and a -little tweak there" project has evolved into something much bigger and more complex +* Go through, clean-up my notes and get them better sorted. Some are in the code, some are +scattered in my note-taking program. This "Oh, I'll just make a little tweak here and a +little tweak there" project has evolved into something much bigger and more complex than I originally planned. :p ~ LazyJ +* find out why the sled disappears after rightclicking it ~ HybridDog --]] @@ -52,9 +53,19 @@ than I originally planned. :p ~ LazyJ -- Helper functions -- +vector.zero = vector.zero or {x=0, y=0, z=0} + +local function table_find(t, v) + for i = 1,#t do + if t[i] == v then + return true + end + end + return false +end + local function is_water(pos) - local nn = minetest.get_node(pos).name - return minetest.get_item_group(nn, "water") ~= 0 + return minetest.get_item_group(minetest.get_node(pos).name, "water") ~= 0 end @@ -63,105 +74,116 @@ end -- local sled = { - physical = false, + physical = true, collisionbox = {-0.6,-0.25,-0.6, 0.6,0.3,0.6}, visual = "mesh", mesh = "sled.x", textures = {"sled.png"}, - nil, - - driver = nil, - sliding = false, } local players_sled = {} +local function join_sled(self, player) + local pos = self.object:getpos() + player:setpos(pos) + local name = player:get_player_name() + players_sled[name] = true + default.player_attached[name] = true + default.player_set_animation(player, "sit" , 30) + self.driver = name + self.object:set_attach(player, "", {x=0,y=-9,z=0}, {x=0,y=90,z=0}) + self.object:setyaw(player:get_look_yaw())-- - math.pi/2) +end -function sled:on_rightclick(clicker) - if (not self.driver) and snow.sleds then - players_sled[clicker:get_player_name()] = true - self.driver = clicker - self.object:set_attach(clicker, "", {x=0,y=-9,z=0}, {x=0,y=90,z=0}) - clicker:set_physics_override({ - speed = 2, -- multiplier to default value - jump = 0, -- multiplier to default value - gravity = 1 - }) ---[[ - local HUD = - { - hud_elem_type = "text", -- see HUD element types - position = {x=0.5, y=0.89}, - name = "sled", - scale = {x=2, y=2}, - text = "You are sledding, hold sneak to stop.", - direction = 0, - } - - clicker:hud_add(HUD) ---]] +local function leave_sled(self, player) + local name = player:get_player_name() + players_sled[name] = false + self.driver = nil + player:set_detach() + default.player_attached[name] = false + default.player_set_animation(player, "stand" , 30) + + player:set_physics_override({ + speed = 1, + jump = 1, + }) + player:hud_remove(self.HUD) -- And here is part 2. ~ LazyJ + self.object:remove() + + --Give the sled back again + player:get_inventory():add_item("main", "snow:sled") +end + +function sled:on_rightclick(player) + if self.driver + or not snow.sleds then + return + end + join_sled(self, player) + player:set_physics_override({ + speed = 2, -- multiplier to default value + jump = 0, -- multiplier to default value + }) -- Here is part 1 of the fix. ~ LazyJ - self.HUD = clicker:hud_add({ - hud_elem_type = "text", - position = {x=0.5, y=0.89}, - name = "sled", - scale = {x=2, y=2}, - text = "You are on the sled! Press the sneak key to get off the sled.", -- LazyJ - direction = 0, - }) --- End part 1 - end + self.HUD = player:hud_add({ + hud_elem_type = "text", + position = {x=0.5, y=0.89}, + name = "sled", + scale = {x=2, y=2}, + text = "You are on the sled! Press the sneak key to get off the sled.", -- LazyJ + direction = 0, + }) +-- End part 1 end function sled:on_activate(staticdata, dtime_s) self.object:set_armor_groups({immortal=1}) + self.object:setacceleration({x=0, y=-10, z=0}) if staticdata then self.v = tonumber(staticdata) end end function sled:get_staticdata() - return tostring(v) + return tostring(self.v) end -function sled:on_punch(puncher, time_from_last_punch, tool_capabilities, direction) +function sled:on_punch(puncher) self.object:remove() - if puncher and puncher:is_player() then + if puncher + and puncher:is_player() then puncher:get_inventory():add_item("main", "snow:sled") end end - -minetest.register_globalstep(function(dtime) - for _, player in pairs(minetest.get_connected_players()) do - if players_sled[player:get_player_name()] then - default.player_set_animation(player, "sit", 0) - end +local driveable_nodes = {"default:snow","default:snowblock","default:ice","default:dirt_with_snow", "group:icemaker"} +local function accelerating_possible(pos) + if is_water(pos) then + return false end -end) + if table_find(driveable_nodes, minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name) then + return true + end + return false +end +local timer = 0 function sled:on_step(dtime) - if self.driver then - local p = self.object:getpos() - p.y = p.y+0.4 - local s = self.object:getpos() - s.y = s.y -0.5 - local keys = self.driver:get_player_control() - if keys["sneak"] or is_water(p) or (not minetest.find_node_near(s, 1, {"default:snow","default:snowblock","default:ice","default:dirt_with_snow", "group:icemaker"})) then -- LazyJ - self.driver:set_physics_override({ - speed = 1, -- multiplier to default value - jump = 1, -- multiplier to default value - gravity = 1 - }) - - players_sled[self.driver:get_player_name()] = false - self.object:set_detach() - --self.driver:hud_remove("sled") - self.driver:hud_remove(self.HUD) -- And here is part 2. ~ LazyJ - self.driver = nil - self.object:remove() - - end + if not self.driver then + return + end + timer = timer+dtime + if timer < 1 then + return + end + timer = 0 + local player = minetest.get_player_by_name(self.driver) + if not player then + return + end + if player:get_player_control().sneak + or not accelerating_possible(vector.round(self.object:getpos())) then + leave_sled(self, player) end end @@ -175,16 +197,18 @@ minetest.register_craftitem("snow:sled", { wield_scale = {x=2, y=2, z=1}, liquids_pointable = true, stack_max = 1, - - on_use = function(itemstack, placer) - local pos = {x=0,y=-1000, z=0} - local name = placer:get_player_name() - local player_pos = placer:getpos() - if not players_sled[name] then - if minetest.get_node(player_pos).name == "default:snow" then - local sled = minetest.add_entity(pos, "snow:sled") - sled:get_luaentity():on_rightclick(placer) - end + + on_use = function(itemstack, placer) + if players_sled[placer:get_player_name()] then + return + end + local pos = placer:getpos() + if accelerating_possible(vector.round(pos)) then + pos.y = pos.y+0.5 + + --Get on the sled and remove it from inventory. + minetest.add_entity(pos, "snow:sled"):right_click(placer) + itemstack:take_item(); return itemstack end end, }) diff --git a/mods/snow/src/snowball.lua b/mods/snow/src/snowball.lua index 89a78e86..d0be241d 100755 --- a/mods/snow/src/snowball.lua +++ b/mods/snow/src/snowball.lua @@ -3,63 +3,151 @@ --============ -- Snowballs were destroying nodes if the snowballs landed just right. --- Quite a bit of trial-and-error learning here and it boiled down to a +-- Quite a bit of trial-and-error learning here and it boiled down to a -- small handful of code lines making the difference. ~ LazyJ -local snowball_GRAVITY=9 -local snowball_VELOCITY=19 +local creative_mode = minetest.setting_getbool("creative_mode") + +local function get_gravity() + local grav = tonumber(minetest.setting_get("movement_gravity")) or 9.81 + return grav*snow.snowball_gravity +end + +local someone_throwing +local timer = 0 --Shoot snowball -local snow_shoot_snowball=function (item, player, pointed_thing) - local playerpos=player:getpos() - local obj=minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, "snow:snowball_entity") - local dir=player:get_look_dir() - obj:setvelocity({x=dir.x*snowball_VELOCITY, y=dir.y*snowball_VELOCITY, z=dir.z*snowball_VELOCITY}) - obj:setacceleration({x=dir.x*-3, y=-snowball_GRAVITY, z=dir.z*-3}) +local function snow_shoot_snowball(item, player) + local addp = {y = 1.625} -- + (math.random()-0.5)/5} + local dir = player:get_look_dir() + local dif = 2*math.sqrt(dir.z*dir.z+dir.x*dir.x) + addp.x = dir.z/dif -- + (math.random()-0.5)/5 + 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:setvelocity(vector.multiply(dir, snow.snowball_velocity)) + obj:setacceleration({x=dir.x*-3, y=-get_gravity(), z=dir.z*-3}) + if creative_mode then + if not someone_throwing then + someone_throwing = true + timer = -0.5 + end + return + end item:take_item() return item end +if creative_mode then + local function update_step(dtime) + timer = timer+dtime + if timer < 0.006 then + return + end + timer = 0 + + local active + for _,player in pairs(minetest.get_connected_players()) do + if player:get_player_control().LMB then + local item = player:get_wielded_item() + local itemname = item:get_name() + if itemname == "default:snow" then + snow_shoot_snowball(nil, player) + active = true + break + end + end + end + + -- disable the function if noone currently throws them + if not active then + someone_throwing = false + end + end + + -- do automatic throwing using a globalstep + minetest.register_globalstep(function(dtime) + -- only if one holds left click + if someone_throwing then + update_step(dtime) + end + end) +end + --The snowball Entity -snow_snowball_ENTITY={ +local snow_snowball_ENTITY = { physical = false, - timer=0, - textures = {"default_snowball.png"}, - lastpos={}, - collisionbox = {0,0,0,0,0,0}, + timer = 0, + collisionbox = {-5/16,-5/16,-5/16, 5/16,5/16,5/16}, } ---Snowball_entity.on_step()--> called when snowball is moving. -snow_snowball_ENTITY.on_step = function(self, dtime) - self.timer=self.timer+dtime - local pos = self.object:getpos() - local node = minetest.get_node(pos) +function snow_snowball_ENTITY.on_activate(self) + self.object:set_properties({textures = {"default_snowball.png^[transform"..math.random(0,7)}}) + self.object:setacceleration({x=0, y=-get_gravity(), z=0}) + self.lastpos = self.object:getpos() + minetest.after(0.1, function(obj) + if not obj then + return + end + local vel = obj:getvelocity() + if vel + and vel.y ~= 0 then + return + end + minetest.after(0, function(obj) + if not obj then + return + end + local vel = obj:getvelocity() + if not vel + or vel.y == 0 then + obj:remove() + end + end, obj) + end, self.object) +end - --Become item when hitting a node. - if self.lastpos.x~=nil then --If there is no lastpos for some reason. ~ Splizard - -- Check to see what is one node above where the snow is - -- going to be placed. ~ LazyJ, 2014_04_08 - local abovesnowballtarget = {x=pos.x, y=pos.y+1, z=pos.z} - -- Identify the name of the node that was found above. ~ LazyJ, 2014_04_08 - local findwhatisabove = minetest.get_node(abovesnowballtarget).name - -- If the node above is air, then it's OK to go on to the next step. ~ LazyJ, 2014_04_08 - if findwhatisabove == "air" then - -- If the node where the snow is going is anything except air, then it's OK to put - -- the snow on it. ~ Original line of code by Splizard, comment by LazyJ so I can - -- keep track of what this code does. ~ LazyJ, 2014_04_07 - if node.name ~= "air" then - snow.place(pos) -- this is the original code, I replaced it with - -- minetest.place_node and bumped the y position up by 2 (make the snow drop - -- from a node above and pile up). ~ LazyJ, 2014_04_07 - --minetest.place_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="default:snow"}) - self.object:remove() - end - else -- If findwhatisabove is not equal to "air" then cancel the snowball - -- with self.object:remove() ~ LazyJ, 2014_04_08 - self.object:remove() - end +--Snowball_entity.on_step()--> called when snowball is moving. +function snow_snowball_ENTITY.on_step(self, dtime) + self.timer = self.timer+dtime + if self.timer > 600 then + -- 10 minutes are too long for a snowball to fly somewhere + self.object:remove() end - self.lastpos={x=pos.x, y=pos.y, z=pos.z} + + if self.physical then + local fell = self.object:getvelocity().y == 0 + if not fell then + return + end + local pos = vector.round(self.object:getpos()) + if minetest.get_node(pos).name == "air" then + pos.y = pos.y-1 + if minetest.get_node(pos).name == "air" then + return + end + end + snow.place(pos) + self.object:remove() + return + end + + local pos = vector.round(self.object:getpos()) + if vector.equals(pos, self.lastpos) then + return + end + if minetest.get_node(pos).name ~= "air" then + self.object:setacceleration({x=0, y=-get_gravity(), z=0}) + --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}) + self.object:set_properties({physical = true}) + self.physical = true + return + end + self.lastpos = vector.new(pos) end @@ -70,8 +158,8 @@ minetest.register_entity("snow:snowball_entity", snow_snowball_ENTITY) -- Snowball and Default Snowball Merged --- They both look the same, they do basically the same thing (except one is a leftclick throw --- and the other is a rightclick drop),... Why not combine snow:snowball with default:snow and +-- They both look the same, they do basically the same thing (except one is a leftclick throw +-- and the other is a rightclick drop),... Why not combine snow:snowball with default:snow and -- benefit from both? ~ LazyJ, 2014_04_08 --[[ Save this for reference and occasionally compare to the default code for any updates. @@ -118,16 +206,8 @@ minetest.override_item("default:snow", { drop = { max_items = 2, items = { - { - -- player will get sapling with 1/20 chance - items = {'snow:moss'}, - rarity = 20, - }, - { - -- player will get leaves only if he get no saplings, - -- this is because max_items is 1 - items = {'default:snow'}, - } + {items = {'snow:moss'}, rarity = 20,}, + {items = {'default:snow'},} } }, leveled = 7, @@ -137,88 +217,78 @@ minetest.override_item("default:snow", { {-0.5, -0.5, -0.5, 0.5, -0.5, 0.5}, }, }, - groups = {cracky=3, crumbly=3, choppy=3, oddly_breakable_by_hand=3,falling_node=1, melts=2, float=1}, + groups = {cracky=3, crumbly=3, choppy=3, oddly_breakable_by_hand=3, falling_node=1, melts=2, float=1}, sunlight_propagates = true, --Disable placement prediction for snow. node_placement_prediction = "", on_construct = function(pos) - if minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name == "default:dirt_with_grass" - or minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name == "default:dirt" then - minetest.set_node({x=pos.x, y=pos.y-1, z=pos.z}, {name="default:dirt_with_snow"}) + pos.y = pos.y-1 + local node = minetest.get_node(pos) + if node.name == "default:dirt_with_grass" + or node.name == "default:dirt" then + node.name = "default:dirt_with_snow" + minetest.set_node(pos, node) end end, - --Remove dirt_with_snow and replace with dirt_with_grass. - --[[after_destruct = function(pos) - if minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name == "default:dirt_with_snow" then - minetest.set_node({x=pos.x, y=pos.y-1, z=pos.z}, {name="default:dirt_with_grass"}) - end - end,]] --Handle node drops due to node level. on_dig = function(pos, node, digger) local level = minetest.get_node_level(pos) minetest.node_dig(pos, node, digger) if minetest.get_node(pos).name ~= node.name then - if digger:get_inventory() then - local _, dropped_item - local left = digger:get_inventory():add_item("main", "default:snow "..tostring(level/7-1)) - if not left:is_empty() then - local p = { - x = pos.x + math.random()/2-0.25, - y = pos.y + math.random()/2-0.25, - z = pos.z + math.random()/2-0.25, - } - minetest.add_item(p, left) - end + local inv = digger:get_inventory() + if not inv then + return + end + local left = inv:add_item("main", "default:snow "..tostring(level/7-1)) + if not left:is_empty() then + minetest.add_item({ + x = pos.x + math.random()/2-0.25, + y = pos.y + math.random()/2-0.25, + z = pos.z + math.random()/2-0.25, + }, left) end end end, --Manage snow levels. on_place = function(itemstack, placer, pointed_thing) - local node - local above - local level - local under = pointed_thing.under local oldnode_under = minetest.get_node_or_nil(under) local above = pointed_thing.above - local oldnode_above = minetest.get_node_or_nil(above) - - if not oldnode_under or not oldnode_above then + + if not oldnode_under + or not above then return end - + local olddef_under = ItemStack({name=oldnode_under.name}):get_definition() olddef_under = olddef_under or minetest.nodedef_default - local olddef_above = ItemStack({name=oldnode_above.name}):get_definition() - olddef_above = olddef_above or minetest.nodedef_default - - -- Place above pointed node - local place_to = {x = above.x, y = above.y, z = above.z} + local place_to -- If node under is buildable_to, place into it instead (eg. snow) if olddef_under.buildable_to then - place_to = {x = under.x, y = under.y, z = under.z} + place_to = under + else + -- Place above pointed node + place_to = above end - - node = minetest.get_node(place_to) - level = minetest.get_node_level(place_to) + + local level = minetest.get_node_level(place_to) if level == 63 then minetest.set_node(place_to, {name="default:snowblock"}) else minetest.set_node_level(place_to, level+7) end - - if node.name ~= "default:snow" then + + if minetest.get_node(place_to).name ~= "default:snow" then local itemstack, placed = minetest.item_place_node(itemstack, placer, pointed_thing) return itemstack, placed end - + itemstack:take_item() - + return itemstack end, - on_use = snow_shoot_snowball -- This line is from the 'Snow' mod, - -- the reset is default Minetest. ~ LazyJ + on_use = snow_shoot_snowball }) @@ -230,16 +300,16 @@ On servers where buckets are disabled, snow and ice stuff is used to set water f water stuff like fountains, pools, ponds, ect.. It is a common practice to set a default torch on the snow placed where the players want water to be. -If you place a default torch *on* default snow to melt it, instead of melting the snow is -*replaced* by the torch. Using "buildable_to = false" would fix this but then the snow would no +If you place a default torch *on* default snow to melt it, instead of melting the snow is +*replaced* by the torch. Using "buildable_to = false" would fix this but then the snow would no longer pile-up in layers; the snow would stack like thin shelves in a vertical column. -I tinkered with the default torch's code (see below) to check for snow at the position and one -node above (layered snow logs as the next y position above) but default snow's -"buildable_to = true" always happened first. An interesting exercise to better learn how Minetest -works, but otherwise not worth it. If you set a regular torch near snow, the snow will melt -and disappear leaving you with nearly the same end result anyway. I say "nearly the same" -because if you set a default torch on layered snow, the torch will replace the snow and be +I tinkered with the default torch's code (see below) to check for snow at the position and one +node above (layered snow logs as the next y position above) but default snow's +"buildable_to = true" always happened first. An interesting exercise to better learn how Minetest +works, but otherwise not worth it. If you set a regular torch near snow, the snow will melt +and disappear leaving you with nearly the same end result anyway. I say "nearly the same" +because if you set a default torch on layered snow, the torch will replace the snow and be lit on the ground. If you were able to set a default torch *on* layered snow, the snow would melt and the torch would become a dropped item. @@ -255,7 +325,7 @@ local can_place_torch_on_top = function(pos) or minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name == "default:snow" then minetest.override_item("default:snow", {buildable_to = false,}) end - end + end --]] diff --git a/mods/snow/src/stairsplus.lua b/mods/snow/src/stairsplus.lua index 4525d2c0..6d4d5e21 100755 --- a/mods/snow/src/stairsplus.lua +++ b/mods/snow/src/stairsplus.lua @@ -47,7 +47,7 @@ There is one in each of the "stairsplus.register_all" sections. --- First, let's run a check to see if MoreBlocks is installed; we're going to need it for the +-- First, let's run a check to see if MoreBlocks is installed; we're going to need it for the -- next section of stairsplus stuff. ~LazyJ if (minetest.get_modpath("moreblocks")) @@ -70,7 +70,7 @@ end --- Leave commented out. Another, possible piece of the puzzle, as to why the placement of +-- Leave commented out. Another, possible piece of the puzzle, as to why the placement of -- stairsplus nodes aren't recorded in the logs. Shelved till I can concentrate on it again. -- ~ LazyJ @@ -134,7 +134,7 @@ end end return itemstack end - + -- Upside down slabs if p0.y-1 == p1.y then -- Turn into full block if pointing at a existing slab @@ -175,10 +175,10 @@ end --[[ -Below, in the "groups" line there is a "melts" category. Back in the ABMs lua file, melting -code, melts=1 will produce a water_source when the full-sized snow/ice block is melted making -a big, watery mess. melts=2 will produce a water_source only for a moment, then it changes back -to water_flowing and then dries-up and disappears. I gave these stairs/slabs/panels/microblocks +Below, in the "groups" line there is a "melts" category. Back in the ABMs lua file, melting +code, melts=1 will produce a water_source when the full-sized snow/ice block is melted making +a big, watery mess. melts=2 will produce a water_source only for a moment, then it changes back +to water_flowing and then dries-up and disappears. I gave these stairs/slabs/panels/microblocks a melts value of 2 instead of 1 because they are not full blocks. ~ LazyJ @@ -189,26 +189,26 @@ a melts value of 2 instead of 1 because they are not full blocks. local ndef = minetest.registered_nodes["default:ice"] local groups = {} for k, v in pairs(ndef.groups) do groups[k] = v end - + stairsplus:register_all("moreblocks", "ice", "default:ice", { description = ndef.description, paramtype2 = "facedir", - -- Added "icemaker=1" in groups. This ties into the freezing + -- Added "icemaker=1" in groups. This ties into the freezing -- function in the ABMs.lua file. ~ LazyJ groups = {cracky=1, crumbly=1, choppy=1, oddly_breakable_by_hand=1, melts=2, icemaker=1}, sounds = default.node_sound_glass_defaults(), tiles = ndef.tiles, -- Because of the "use_texture_alpha" line, that gives ice transparency, I couldn't combine -- default ice and default snowblocks in a list like MoreBlocks does. ~ LazyJ - use_texture_alpha = true, + use_texture_alpha = true, sunlight_propagates = true, -- This "on_place" line makes placing these nodes recorded in the logs. -- Useful for investigating griefings and determining ownership -- BUT these nodes will nolonger auto-rotate into position. ~ LazyJ --on_place = minetest.item_place, - - -- The "on_construct" part below, thinking in terms of layers, dirt_with_snow could + + -- The "on_construct" part below, thinking in terms of layers, dirt_with_snow could -- also double as dirt_with_frost which adds subtlety to the winterscape. ~ LazyJ on_construct = function(pos) pos.y = pos.y - 1 @@ -224,11 +224,11 @@ a melts value of 2 instead of 1 because they are not full blocks. local ndef = minetest.registered_nodes["default:snowblock"] local groups = {} for k, v in pairs(ndef.groups) do groups[k] = v end - + stairsplus:register_all("moreblocks", "snowblock", "default:snowblock", { description = ndef.description, paramtype2 = "facedir", - -- Added "icemaker=1" in groups. This ties into the freezing function + -- Added "icemaker=1" in groups. This ties into the freezing function -- in the ABMs.lua file. ~ LazyJ groups = {cracky=3, crumbly=3, choppy=3, oddly_breakable_by_hand=3, melts=2, icemaker=1}, tiles = ndef.tiles, @@ -244,8 +244,8 @@ a melts value of 2 instead of 1 because they are not full blocks. -- BUT these nodes will nolonger auto-rotate into position. ~ LazyJ --on_place = minetest.item_place, - - -- The "on_construct" part below, thinking in terms of layers, + + -- The "on_construct" part below, thinking in terms of layers, -- dirt_with_snow could also double as dirt_with_frost -- which adds subtlety to the winterscape. ~ LazyJ on_construct = function(pos) @@ -313,7 +313,7 @@ for _, name in pairs(snow_nodes) do -- Picking up were we left off... ~ LazyJ - -- The "on_construct" part below, thinking in terms of layers, dirt_with_snow could + -- The "on_construct" part below, thinking in terms of layers, dirt_with_snow could -- also double as dirt_with_frost which adds subtlety to the winterscape. ~ LazyJ on_construct = function(pos) pos.y = pos.y - 1 @@ -336,7 +336,7 @@ for _, name in pairs(snow_nodes) do }) end -else -- from clear up at the top, the MoreBlocks check. "Else", if MoreBlocks wasn't found, skip +else -- from clear up at the top, the MoreBlocks check. "Else", if MoreBlocks wasn't found, skip -- down to here, "return" nothing and "end" this script. ~ LazyJ return end diff --git a/mods/snow/src/util.lua b/mods/snow/src/util.lua index 7f361a94..f2dd9f96 100755 --- a/mods/snow/src/util.lua +++ b/mods/snow/src/util.lua @@ -1,6 +1,7 @@ --Global config and function table. snow = { - legacy = true, + snowball_gravity = 100/109, + snowball_velocity = 19, sleds = true, enable_snowfall = true, lighter_snowfall = false, @@ -8,20 +9,21 @@ snow = { smooth_biomes = true, christmas_content = true, smooth_snow = true, - min_height = 50, + min_height = 3, } --Config documentation. local doc = { - legacy = "Whether you are running a legacy minetest version (auto-detected).", + snowball_gravity = "The gravity of thrown snowballs", + snowball_velocity = "How fast players throw snowballs", sleds = "Disable this to prevent sleds from being riden.", enable_snowfall = "Enables falling snow.", lighter_snowfall = "Reduces the amount of resources and fps used by snowfall.", - debug = "Enables debug output.", - smooth_biomes = "Enables smooth transition of biomes", - christmas_content = "Disable this to remove christmas saplings from being found.", + debug = "Enables debug output. Currently it only prints mgv6 info.", + smooth_biomes = "Enables smooth transition of biomes (mgv6)", smooth_snow = "Disable this to stop snow from being smoothed.", - min_height = "The minumum height a snow biome will generate.", + christmas_content = "Disable this to remove christmas saplings from being found.", + min_height = "The minumum height a snow biome will generate (mgv7)", } --Manage config. @@ -64,7 +66,9 @@ local function loadConfig(path) end end -minetest.register_on_shutdown(function() saveConfig(minetest.get_modpath("snow").."/config.txt", snow, doc) end) +minetest.register_on_shutdown(function() + saveConfig(minetest.get_modpath("snow").."/config.txt", snow, doc) +end) local config = loadConfig(minetest.get_modpath("snow").."/config.txt") if config then @@ -79,7 +83,9 @@ end for i,v in pairs(snow) do local t = type(v) - if t == "string" or t == "number" or t == "boolean" then + if t == "string" + or t == "number" + or t == "boolean" then local v = minetest.setting_get("snow_"..i) if v ~= nil then if v == "true" then v = true end @@ -90,18 +96,6 @@ for i,v in pairs(snow) do end end ---AUTO DETECT and/or OVERIDEN values-- - ---legacy-- ---Detect if we are running the latest minetest. -if minetest.register_on_mapgen_init then - snow.legacy = false -else - snow.legacy = true -end -if config and snow.legacy ~= config.legacy then - saveConfig(minetest.get_modpath("snow").."/config.txt", snow, doc) -end --MENU @@ -110,7 +104,8 @@ local get_formspec = function() local formspec = "label[0,-0.3;Settings:]" for i,v in pairs(snow) do local t = type(v) - if t == "string" or t == "number" then + if t == "string" + or t == "number" then p = p + 1.5 formspec = formspec.."field[0.3,"..p..";2,1;snow:"..i..";"..i..";"..v.."]" elseif t == "boolean" then @@ -124,22 +119,27 @@ local get_formspec = function() end minetest.register_on_player_receive_fields(function(player, formname, fields) - if formname == "snow:menu" then - for i,v in pairs(snow) do - local t = type(v) - if t == "string" or t == "number" or t == "boolean" then - if fields["snow:"..i] then - if t == "string" then - snow[i] = fields["snow:"..i] + 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 - if t == "number" then - snow[i] = tonumber(fields["snow:"..i]) - end - if t == "boolean" then - if fields["snow:"..i] == "true" then snow[i] = true end - if fields["snow:"..i] == "false" then snow[i] = false end - end - end + end end end end @@ -149,7 +149,8 @@ end) minetest.register_chatcommand("snow", { description = "Show a menu for various actions", privs = {server=true}, - func = function(name, param) + func = function(name) + minetest.chat_send_player(name, "Showing snow menu…") minetest.show_formspec(name, "snow:menu", get_formspec()) end, }) diff --git a/mods/snow/textures/default_ice.xcf b/mods/snow/textures/default_ice.xcf deleted file mode 100755 index cadccac3c289fe72c287a003623751a0801b1f4c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1015 zcmZ`%TTa_h5WR896Nt~XFSMnQxTO!fQc&1JH&TU=xRyeKNT}ei>I(W1Lc((cAPA3D zpddiNf0s}R2yb^TwJT85(Hzb3JnVDl+IA);jhSrT_?k|SGBS8jCaD zW^?nl*}Q8u@3*$x?QM5w$KBm^_x8?Ot@BpvVt=2!eQ7r9HoMQG%t}N$E`FuH7`72OP|C{=gc{(ch;F;3vGm8H8%bj98m(NTWDxaNf zZe+4(%Qm@ZX(58_k(U$kxZHcx;}n?OzwD6~Blx`g5$}1#r4GMGB`)9VTbPJndwl0! zU1@p5*H2oMpHFkjFZq0jxCn?gn67fDpaX3p8DvQgD@~@$_4O^&Gj?R2YD}^BP4h{)~ACFFT9+uhet^ diff --git a/mods/snow/textures/default_snowball.png b/mods/snow/textures/default_snowball.png new file mode 100644 index 0000000000000000000000000000000000000000..bbe5351e1b97cfe6ccdc695d704886f1156e86d8 GIT binary patch literal 211 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`vpiiKLn?0Fon*;($Uwwp=YLZR z22);lQr7)&JOhnk#N8?``?a{l6G^?1ipsY?${R=t>4p LS3j3^P6 - - - - - - - - - image/svg+xml - - - - - - - - - diff --git a/mods/snow/textures/snow_ice.png b/mods/snow/textures/snow_ice.png deleted file mode 100755 index 97581e8b8cbc1350f974c25f57cea276d9a46fda..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 206 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=ffJsh%#5Ar-gYPWR?Ipupqu{MugE z^%qM0FD||rtNG))C)+{SvRU6%5*=j9cT8zr%6iUS<3K|=tJ8*7aaNlLk&QBQLjSuv zaQ3sLJ>2?xR+ABH(~n2(o;YOGI+ZBxvXsD)+_9&mT&aD z#$){8FFS{{i||s(B?3zXXEVA;G8r?ZaTv|lSf60b(B{~X!hC|uXGZS{DbGI68ET7| d^I4b~4#*z+^ndTo=|EE%JYD@<);T3K0RT^0H=zIk diff --git a/mods/snow/textures/snow_snowfall.png b/mods/snow/textures/snow_snowfall.png deleted file mode 100755 index 08922ad436a50590af5ee649dd37650f10590918..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 350 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=DjSL74G){)!Z!AbW|YuPgf<9zjtxrp*o-bAUpxJzX3_EKX0Iw6W-rfq={X$`!io zRVSYOuh%>ru})FU^vp5=vq`DiDbZ_}>@Cj@F<~p*c_^`;!76>*7n9D&Cy32_H7Hq`2A#OEVvT(wZ-Fk z+_Y!02El6^b=LY8{$eWKn91iU}`GUKc1vfkIV s`;Kkt^xhG+dYk;B<+;yKw7wUAzUGNu`1!5fKyNd6y85}Sb4q9e09mDv)c^nh diff --git a/mods/snow/textures/snow_star_lit.xcf b/mods/snow/textures/snow_star_lit.xcf deleted file mode 100755 index ecaa73c687f9e78add6d4a9eaaff49186ab6866a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1480 zcmcIj%}x_h6h1Sh6wnHavT`vC7qF;u)96CN0u8A|p){mvnuat(nU;zDA?+Ap#ljab z@fCamoK0pP=T+V)X;2*&r%pq+kQz{gUqJ=ZD@z&F_ph03`VT@&{w zyP{2AA)aXhp(}q2^&EdE^E4c~QCZhBW-+IUM{WryH~*w`b)i>9)6&dhX3eN@d?}l) z7}l=_Ir^%~(OeGYdvHbh;1K@}SK+-8-)eACukfY5&^L`T+xbmc`T>3;8yIjo2MoF# z8{O^ULp}Uj55L~SgFSp0ob!4T0O5Kpz4PH{NG-Xd-cZALH$!5F{j6ek|Gh3 zyPU7Ne~jF*Fp489$~I62Jv?}fwZ+8<4!EDN51rQd1_k<$PjUarDehnJ+7fd_A{FP@ z#4;xmDS@piQuwvgg6MfvaR1@NG)1GdBm{an6XDs}SR9_{e<~Rl3Bmm@N5U!YKblO7 znKbu5lTI$jV-M4axzLjW1usO5^EGGV$UTbb6Ud6PNt99P#~^r1B&UgVfm!N^=zn;8 zXE>b4cZS9pB4-46kh~%54x=}o!%Ifq$XI5nsLkt@mu&N<+xuBt(EZEL;&02b{QEe) j4}f@|gw?M2--37@K<|I=8eE