From 6fd073aaa7cce72e6e3d65e580b18613cde7ed93 Mon Sep 17 00:00:00 2001 From: Splizard Date: Wed, 4 Jun 2014 22:19:44 +1200 Subject: [PATCH] Add snow.place back. Use place_node for creating new nodes. --- init.lua | 29 +++++++++++++++++++++++++++++ src/falling_snow.lua | 4 ++-- src/snowball.lua | 4 ++-- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index 3186d51..916c230 100644 --- a/init.lua +++ b/init.lua @@ -78,7 +78,36 @@ if (minetest.get_modpath("moreblocks")) then else end +--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) + local node = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z}) + local node = minetest.get_node(pos) + local drawtype = minetest.registered_nodes[node.name].drawtype + 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) + 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 drawtype == "plantlike" then + pos.y = pos.y - 1 + if minetest.get_node(pos).name == "default:dirt_with_grass" then + minetest.add_node(pos, {name="default:dirt_with_snow"}) + end + end + end +end -- Checks if the snow level is even at any given pos. -- Smooth Snow diff --git a/src/falling_snow.lua b/src/falling_snow.lua index a453ad2..5192b3b 100644 --- a/src/falling_snow.lua +++ b/src/falling_snow.lua @@ -137,8 +137,8 @@ if snow.enable_snowfall then 50, 50, false, "weather_snow.png", 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 + snow.place(pos, true) + --minetest.place_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="default:snow"}) -- LazyJ end end diff --git a/src/snowball.lua b/src/snowball.lua index 73e0c98..0567dbb 100644 --- a/src/snowball.lua +++ b/src/snowball.lua @@ -48,10 +48,10 @@ snow_snowball_ENTITY.on_step = function(self, dtime) -- 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 + 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"}) + --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