1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2025-04-02 10:40:33 +02:00

Updated snow mod

- See #87
This commit is contained in:
LeMagnesium 2015-06-10 17:26:05 +02:00
parent e4ef41d7af
commit b8e61fd763
22 changed files with 719 additions and 619 deletions

3
mods/snow/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
config.txt
debug.txt
*~

View File

@ -1,2 +1,3 @@
default default
moreblocks? moreblocks?
technic_worldgen?

View File

@ -24,12 +24,12 @@ http://github.com/Splizard/minetest-mod-snow/
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 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 -- 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 -- 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 -- I put it lower on the list and that seems to do the trick. ~ LazyJ
dofile(minetest.get_modpath("snow").."/src/util.lua") 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. -- 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". -- 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") dofile(minetest.get_modpath("snow").."/src/stairsplus.lua")
@ -82,34 +82,52 @@ end
function snow.place(pos) function snow.place(pos)
if pos.y < -19000 then return end -- Don't put anything in the nether! if pos.y < -19000 then return end -- Don't put anything in the nether!
local node = minetest.get_node_or_nil(pos) 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? --Oops, maybe there is no node?
if node == nil then if not node
or not minetest.registered_nodes[node.name] then
return return
end end
local bnode = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}) 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 node.name == "default:snow" then
if minetest.get_item_group(bnode.name, "leafdecay") == 0 and snow.is_uneven(pos) ~= true then local level = minetest.get_node_level(pos)
minetest.add_node_level(pos, 7) 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 end
elseif node.name == "default:snow" and minetest.get_node_level(pos) == 63 then elseif node.name ~= "default:ice"
local p = minetest.find_node_near(pos, 10, "default:dirt_with_grass") and bnode.name ~= "air" then
if p and minetest.get_node_light(p, 0.5) == 15 then local data = minetest.registered_nodes[node.name]
minetest.place_node({x=pos.x,y=pos.y+1,z=pos.z},{name="default:snow"}) local drawtype = data.drawtype
else if drawtype == "normal"
minetest.add_node(pos,{name="default:snowblock"}) or drawtype == "allfaces_optional" then
end pos.y = pos.y+1
elseif node.name ~= "default:ice" and bnode.name ~= "air" then local sound = data.sounds
if drawtype == "normal" or drawtype == "allfaces_optional" then if sound then
minetest.place_node({x=pos.x,y=pos.y+1,z=pos.z}, {name="default:snow"}) 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 elseif drawtype == "plantlike" then
pos.y = pos.y - 1 pos.y = pos.y - 1
if minetest.get_node(pos).name == "default:dirt_with_grass" then 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"}) minetest.add_node(pos, {name="default:dirt_with_snow"})
end end
end end
@ -118,50 +136,56 @@ end
-- Checks if the snow level is even at any given pos. -- Checks if the snow level is even at any given pos.
-- Smooth Snow -- Smooth Snow
local smooth_snow = snow.smooth_snow local function is_uneven(pos)
snow.is_uneven = function(pos) local num = minetest.get_node_level(pos)
if smooth_snow then local get_node = minetest.get_node
local num = minetest.get_node_level(pos) local add_node = minetest.add_node
local get_node = minetest.get_node local found
local add_node = minetest.add_node local foundx
local found local foundy
local foundx local foundz
local foundy for z = -1,1 do
local foundz for x = -1,1 do
for x=-1,1 do local p = {x=pos.x+x, y=pos.y, z=pos.z+z}
for z=-1,1 do local node = get_node(p)
local node = get_node({x=pos.x+x,y=pos.y,z=pos.z+z}) p.y = p.y-1
local bnode = get_node({x=pos.x+x,y=pos.y-1,z=pos.z+z}) local bnode = get_node(p)
local drawtype
if node and minetest.registered_nodes[node.name] then if node
drawtype = minetest.registered_nodes[node.name].drawtype 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 end
if drawtype == "plantlike" then p.y = p.y+1
if bnode.name == "default:dirt_with_grass" then if not (x == 0 and z == 0)
add_node({x=pos.x+x,y=pos.y-1,z=pos.z+z}, {name="default:dirt_with_snow"}) and node.name == "default:snow"
return true and minetest.get_node_level(p) < num then
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
found = true found = true
foundx = x foundx = x
foundz=z foundz = z
elseif node.name == "air" and bnode.name ~= "air" then elseif node.name == "air"
if not (bnode.name == "default:snow") then and bnode.name ~= "air"
snow.place({x=pos.x+x,y=pos.y-1,z=pos.z+z}) and bnode.name ~= "default:snow" then
return true p.y = p.y-1
end snow.place(p)
return true
end end
end end
end end
if found then if found then
local node = get_node({x=pos.x+foundx,y=pos.y,z=pos.z+foundz}) local p = {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 if is_uneven(p) ~= true then
minetest.add_node_level({x=pos.x+foundx,y=pos.y,z=pos.z+foundz}, 7) minetest.add_node_level(p, 7)
end end
return true return true
end end
end
function snow.is_uneven(pos)
if snow.smooth_snow then
return is_uneven(pos)
end end
end end

View File

@ -52,7 +52,7 @@ minetest.register_abm({
elseif intensity == 2 then elseif intensity == 2 then
minetest.add_node(pos,{name="default:water_flowing", param2=7}) 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 --[[ 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 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 air. This way it made a watery mess that quickly evaporated. ~ LazyJ 2014_04_24
local check_place = function(pos,node) local check_place = function(pos,node)
@ -70,7 +70,7 @@ minetest.register_abm({
minetest.add_node(pos,{name="default:water_source"}) minetest.add_node(pos,{name="default:water_source"})
minetest.after(2, function() -- 2 seconds gives just enough time for minetest.after(2, function() -- 2 seconds gives just enough time for
-- the water to flow and spread before the -- 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 if minetest.get_node(pos).name == "default:water_source" then
minetest.add_node(pos,{name="air"}) minetest.add_node(pos,{name="air"})
end end
@ -150,7 +150,7 @@ minetest.register_abm({
minetest.register_abm({ minetest.register_abm({
nodenames = {"snow:sapling_pine"}, nodenames = {"snow:sapling_pine"},
interval = 10, interval = 10,
chance = 50, chance = 50,
action = function(pos, node) action = function(pos, node)
-- Check if there is enough vertical-space for the sapling to grow without -- 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 if minetest.get_node(pos).name == "snow:sapling_pine" then
-- This switches the sapling to a tree trunk. ~ LazyJ -- This switches the sapling to a tree trunk. ~ LazyJ
minetest.set_node(pos, {name="default:pinetree"}) 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 -- grepping the server logs too. ~ LazyJ
minetest.log("action", "A pine sapling grows into a tree at "..minetest.pos_to_string(pos)) minetest.log("action", "A pine sapling grows into a tree at "..minetest.pos_to_string(pos))
end end

View File

@ -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 -- "attempt to index global 'snow' (a nil value)" and
-- refuse to load. So a value without definition "={}"is assigned to snow. -- 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) return minetest.item_place(itemstack, placer, pointed_thing, param2)
end, end,
on_construct = function(pos) on_construct = function(pos)
pos.y = pos.y - 1 pos.y = pos.y - 1
if minetest.get_node(pos).name == "default:dirt_with_grass" 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 -- dirt_with_frost which adds subtlety to the winterscape. ~ LazyJ, 2014_04_04
or minetest.get_node(pos).name == "default:dirt" then or minetest.get_node(pos).name == "default:dirt" then
minetest.set_node(pos, {name="default:dirt_with_snow"}) minetest.set_node(pos, {name="default:dirt_with_snow"})
@ -168,7 +168,7 @@ function snow_stairs.register_slab(subname, recipeitem, groups, images, descript
end end
return itemstack return itemstack
end end
-- Upside down slabs -- Upside down slabs
if p0.y-1 == p1.y then if p0.y-1 == p1.y then
-- Turn into full block if pointing at a existing slab -- 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) return minetest.item_place(itemstack, placer, pointed_thing, param2)
end, end,
on_construct = function(pos) on_construct = function(pos)
pos.y = pos.y - 1 pos.y = pos.y - 1
if minetest.get_node(pos).name == "default:dirt_with_grass" 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 -- dirt_with_frost which adds subtlety to the winterscape. ~ LazyJ, 2014_04_04
or minetest.get_node(pos).name == "default:dirt" then or minetest.get_node(pos).name == "default:dirt" then
minetest.set_node(pos, {name="default:dirt_with_snow"}) minetest.set_node(pos, {name="default:dirt_with_snow"})
end end
end end
}) })
--[[ --[[
-- for replace ABM -- for replace ABM
@ -296,7 +296,7 @@ for _, row in ipairs(list_of_snow_stuff) do
true 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 -- Snow stairs and slabs should be easier to break than the more dense and

View File

@ -48,11 +48,11 @@ minetest.register_craft({
-- 2. Cooking -- 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 (snow bricks, snow cobble, snow blocks, etc.) so I wouldn't have to write an individual cooking
recipe for each one. recipe for each one.
~ LazyJ ~ LazyJ
--]] --]]
minetest.register_craft({ minetest.register_craft({
@ -203,7 +203,7 @@ for _, name in pairs(recycle_default_slabs) do
recipe = { recipe = {
"snow:slab_"..subname_default, "snow:slab_"..subname_default,
"snow:slab_"..subname_default, "snow:slab_"..subname_default,
} }
}) })
end end
@ -229,6 +229,6 @@ for _, name in pairs(recycle_snowmod_slabs) do
recipe = { recipe = {
"snow:slab_"..subname_snowmod, "snow:slab_"..subname_snowmod,
"snow:slab_"..subname_snowmod, "snow:slab_"..subname_snowmod,
} }
}) })
end end

View File

@ -40,10 +40,6 @@ near torches and lava.
--============================================================= --=============================================================
if not snow.enable_snowfall then
return
end
local weather_legacy local weather_legacy
local read_weather_legacy = function () local read_weather_legacy = function ()
@ -84,7 +80,7 @@ local PERSISTENCE3 = 0.5 -- 0.5
local SCALE3 = 250 -- 250 local SCALE3 = 250 -- 250
--Get snow at position. --Get snow at position.
local get_snow = function(pos) local function get_snow(pos)
--Legacy support. --Legacy support.
if weather_legacy == "snow" then if weather_legacy == "snow" then
local perlin1 = minetest.get_perlin(112,3, 0.5, 150) local perlin1 = minetest.get_perlin(112,3, 0.5, 150)
@ -106,14 +102,19 @@ end
local addvectors = vector and vector.add local addvectors = vector and vector.add
--Returns a random position between minp and maxp. --Returns a random position between minp and maxp.
local randpos = function (minp, maxp) local function randpos(minp, maxp)
local x,y,z local x,z
if minp.x > maxp.x then if minp.x > maxp.x then
x = math.random(maxp.x,minp.x) else x = math.random(minp.x,maxp.x) end x = math.random(maxp.x,minp.x)
y = minp.y else
x = math.random(minp.x,maxp.x)
end
if minp.z > maxp.z then if minp.z > maxp.z then
z = math.random(maxp.z,minp.z) else z = math.random(minp.z,maxp.z) end z = math.random(maxp.z,minp.z)
return {x=x,y=y,z=z} else
z = math.random(minp.z,maxp.z)
end
return {x=x,y=minp.y,z=z}
end end
local default_snow_particle = { local default_snow_particle = {
@ -152,22 +153,20 @@ local function snow_fall(pos, player, animate)
break break
end end
end end
if not ground_y then return end if not ground_y then
pos = {x=pos.x, y=ground_y, z=pos.z} return
local spos = {x=pos.x, y=ground_y+10, z=pos.z} end
pos = {x=pos.x, y=ground_y, z=pos.z}
if get_snow(pos) then if get_snow(pos) then
if animate then if animate then
local minp = addvectors(spos, {x=-9, y=3, z=-9}) local spos = {x=pos.x, y=ground_y+10, z=pos.z}
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}
minetest.add_particlespawner(get_snow_particledef({ minetest.add_particlespawner(get_snow_particledef({
minpos = minp, minpos = addvectors(spos, {x=-9, y=3, z=-9}),
maxpos = maxp, maxpos = addvectors(spos, {x= 9, y=5, z= 9}),
vel = vel, vel = {x=0, y=-1, z=-1},
acc = acc, acc = {x=0, y=0, z=0},
playername = player:get_player_name() playername = player:get_player_name()
})) }))
end end
@ -177,30 +176,21 @@ local function snow_fall(pos, player, animate)
end end
-- Snow -- Snow
minetest.register_globalstep(function(dtime) local function calc_snowfall()
for _, player in pairs(minetest.get_connected_players()) do for _, player in pairs(minetest.get_connected_players()) do
local ppos = player:getpos() 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... -- Make sure player is not in a cave/house...
if get_snow(ppos) and minetest.get_node_light(ppos, 0.5) == 15 then 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 animate
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 not snow.lighter_snowfall then 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({ minetest.add_particlespawner(get_snow_particledef({
amount = 5, amount = 5,
minpos = minp, minpos = addvectors(ppos, {x=-9, y=3, z=-9}),
maxpos = maxp, maxpos = addvectors(ppos, {x= 9, y=5, z= 9}),
vel = vel, vel = vel,
acc = acc, acc = acc,
size = 25, size = 25,
@ -209,8 +199,8 @@ minetest.register_globalstep(function(dtime)
minetest.add_particlespawner(get_snow_particledef({ minetest.add_particlespawner(get_snow_particledef({
amount = 4, amount = 4,
minpos = minp_deep, minpos = addvectors(ppos, {x=-5, y=3.2, z=-5}),
maxpos = maxp_deep, maxpos = addvectors(ppos, {x= 5, y=1.6, z= 5}),
vel = vel, vel = vel,
acc = acc, acc = acc,
exptime = 4, exptime = 4,
@ -218,14 +208,27 @@ minetest.register_globalstep(function(dtime)
playername = player:get_player_name() playername = player:get_player_name()
})) }))
if math.random(1,5) == 4 then animate = false
snow_fall(randpos(sminp, smaxp), player)
end
else else
if math.random(1,5) == 4 then animate = true
snow_fall(randpos(sminp, smaxp), player, true) end
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
end end
end
minetest.register_globalstep(function(dtime)
if snow.enable_snowfall then
calc_snowfall()
end
end) end)

View File

@ -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 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 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 issue is figured out. However, the pine and xmas tree code is still needed for when those
saplings grow into trees. --]] saplings grow into trees. --]]
--The *starting* comment looks like this: --[[ --The *starting* comment looks like this: --[[
--The *closing* 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. -- Part 1: To disable the mapgen, add the *starting* comment under this line.
local mgname = ""
--Identify the mapgen. --Identify the mapgen.
minetest.register_on_mapgen_init(function(MapgenParams) minetest.register_on_mapgen_init(function(MapgenParams)
if MapgenParams.mgname then local mgname = MapgenParams.mgname
mgname = MapgenParams.mgname if not mgname then
else
io.write("[MOD] Snow Biomes: WARNING! mapgen could not be identifyed!\n") io.write("[MOD] Snow Biomes: WARNING! mapgen could not be identifyed!\n")
end end
if mgname == "v7" then 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 perlin1 = minetest.get_perlin(112,3, 0.5, 150)
local try_node = function(pos, node) local try_node = function(pos, node)
local n = minetest.get_node(pos).name local n = minetest.get_node(pos).name
if n == "air" or n == "ignore" then if n == "air"
minetest.add_node(pos,node) or n == "ignore" then
minetest.add_node(pos, node)
end end
end end
--Clear ground. --Clear ground.
for x=-1,1 do for z = -1,1 do
for z=-1,1 do for x = -1,1 do
if minetest.get_node({x=pos.x+x,y=pos.y,z=pos.z+z}).name == "default:snow" then local p = {x=pos.x+x,y=pos.y,z=pos.z+z}
minetest.remove_node({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 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 end
if xmas then if xmas then
minetest.remove_node(pos) minetest.remove_node(pos)
@ -107,7 +105,8 @@ function snow.make_pine(pos,snow,xmas)
end end
if xmas then if xmas then
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="snow:star_lit"}) -- Added lit star. ~ LazyJ 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"}) try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="default:snow"})
end end
end end
@ -121,60 +120,62 @@ function snow.voxelmanip_pine(pos,a,data)
local c_pinetree = minetest.get_content_id("default:pinetree") local c_pinetree = minetest.get_content_id("default:pinetree")
local c_air = minetest.get_content_id("air") 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, 150)
--Clear ground. for z = -1,1 do
for x=-1,1 do local z = pos.z + z
for z=-1,1 do for x = -1,1 do
local node = a:index(pos.x+x,pos.y,pos.z+z) local x = pos.x + x
if data[node] == c_snow then
data[node] = c_air --Clear ground.
end local node = a:index(x,pos.y,z)
end if data[node] == c_snow then
end data[node] = c_air
--Make tree. end
for i=0, 4 do
if i==1 or i==2 then --Make tree.
for x=-1,1 do for i = 1,2 do
for z=-1,1 do
local x = pos.x + x
local z = pos.z + z
local node = a:index(x,pos.y+i,z) local node = a:index(x,pos.y+i,z)
data[node] = c_pine_needles 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) local abovenode = a:index(x,pos.y+i+1,z)
data[abovenode] = c_snow data[abovenode] = c_snow
end end
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
end end
if i==3 or i==4 then end
local x = pos.x for i=0, 4 do
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
data[a:index(pos.x,pos.y+i,pos.z)] = c_pinetree data[a:index(pos.x,pos.y+i,pos.z)] = c_pinetree
end end
data[a:index(pos.x,pos.y+5,pos.z)] = c_pine_needles 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 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 data[a:index(pos.x,pos.y+7,pos.z)] = c_snow
end end
end end

View File

@ -22,33 +22,38 @@ local np_ice = {
-- Debugging function -- Debugging function
local biome_to_string = function(num,num2) local biome_strings = {
local biome, biome2 {"snowy", "plain", "alpine", "normal", "normal"},
if num == 1 then {"cool", "icebergs", "icesheet", "icecave", "icehole"}
biome = "snowy" }
elseif num == 2 then local function biome_to_string(num,num2)
biome = "plain" local biome = biome_strings[1][num] or "unknown "..num
elseif num == 3 then return biome
biome = "alpine" end
elseif num == 4 or num == 5 then
biome = "normal" local function do_ws_func(a, x)
else local n = x/(16000)
biome = "unknown "..num local y = 0
for k=1,1000 do
y = y + 1000*(math.sin(math.pi * k^a * n)/(math.pi * k^a))
end end
if num2 == 1 then return y
biome2 = "cool" end
elseif num2 == 2 then
biome2 = "icebergs" local ws_lists = {}
elseif num2 == 3 then local function get_ws_list(a,x)
biome2 = "icesheet" ws_lists[a] = ws_lists[a] or {}
elseif num2 == 4 then local v = ws_lists[a][x]
biome2 = "icecave" if v then
elseif num2 == 5 then return v
biome2 = "icehole" end
else v = {}
biome2 = "unknown "..num for x=x,x + (80 - 1) do
end local y = do_ws_func(a, x)
return biome, biome2 v[x] = y
end
ws_lists[a][x] = v
return v
end end
-- On generated function -- On generated function
@ -60,12 +65,9 @@ minetest.register_on_generated(function(minp, maxp, seed)
local z0 = minp.z local z0 = minp.z
local x1 = maxp.x local x1 = maxp.x
local z1 = maxp.z local z1 = maxp.z
local debug = snow.debug
local min_height = snow.min_height
local spawn_pine = snow.voxelmanip_pine local spawn_pine = snow.voxelmanip_pine
local smooth = snow.smooth_biomes 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_with_grass = minetest.get_content_id("default:dirt_with_grass")
local c_dirt = minetest.get_content_id("default:dirt") 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 area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
local data = vm:get_data() local data = vm:get_data()
local snow_tab,num = {},1
local sidelen = x1 - x0 + 1 local sidelen = x1 - x0 + 1
local chulens = {x=sidelen, y=sidelen, z=sidelen} 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_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}) local nvals_ice = minetest.get_perlin_map(np_ice, chulens):get2dMap_flat({x=x0, y=z0})
-- Choose biomes -- Choose biomes
local pr = PseudoRandom(seed+57) local pr = PseudoRandom(seed+57)
local biome
-- Land biomes -- Land biomes
biome = pr:next(1, 5) local biome = pr:next(1, 5)
local snowy = biome == 1 -- spawns alot of snow local snowy = biome == 1 -- spawns alot of snow
local plain = biome == 2 -- spawns not much
local alpine = biome == 3 -- rocky terrain 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 -- Misc biome settings
local icy = pr:next(1, 2) == 2 -- if enabled spawns ice in sand instead of snow blocks 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 shrubs = pr:next(1,2) == 1 -- spawns dry shrubs in snow
local pines = pr:next(1,2) == 1 -- spawns pines local pines = pr:next(1,2) == 1 -- spawns pines
-- Reseed random -- Reseed random
@ -135,11 +128,12 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
if not in_biome then if not in_biome then
if alpine == true and test > 0.43 then if alpine and test > 0.43 then
local ground_y = nil local ground_y = nil
for y = maxp.y, minp.y, -1 do for y = maxp.y, minp.y, -1 do
local nodid = data[area:index(x, y, z)] 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 ground_y = y
break break
end end
@ -147,7 +141,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
if ground_y then if ground_y then
local vi = area:index(x, ground_y, z) 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 for y = ground_y, -16, -1 do
local vi = area:index(x, y, z) local vi = area:index(x, y, z)
local id = data[vi] local id = data[vi]
@ -155,7 +149,6 @@ minetest.register_on_generated(function(minp, maxp, seed)
if id == c_leaves if id == c_leaves
or id == c_jungleleaves or id == c_jungleleaves
or id == c_tree or id == c_tree
or id == c_air
or id == c_apple then or id == c_apple then
data[vi] = c_air data[vi] = c_air
else else
@ -163,15 +156,15 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
end end
end end
end end
end end
end end
elseif in_biome then elseif in_biome then
write_to_map = true write_to_map = true
local icetype = nvals_ice[ni] 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 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 icesheet = icetype > -0.6 and icetype <= -0.4
local icecave = icetype <= -0.6 local icecave = icetype <= -0.6
@ -183,7 +176,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
break break
end end
end end
if ground_y then if ground_y then
local node = area:index(x, ground_y, z) local node = area:index(x, ground_y, z)
local abovenode = area:index(x, ground_y+1, 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 ground_y and data[node] == c_dirt_with_grass then
if alpine and test > 0.53 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 for y = ground_y, -6, -1 do
local vi = area:index(x, y, z) local vi = area:index(x, y, z)
if data[vi] == c_stone then if data[vi] == c_stone then
@ -210,18 +204,21 @@ minetest.register_on_generated(function(minp, maxp, seed)
data[abovenode] = c_snow_block data[abovenode] = c_snow_block
else else
data[node] = c_dirt_with_snow data[node] = c_dirt_with_snow
data[abovenode] = c_snow snow_tab[num] = {abovenode, z, x, test}
num = num+1
end end
elseif ground_y and data[node] == c_sand then elseif ground_y and data[node] == c_sand then
if not icy then if not icy then
data[abovenode] = c_snow snow_tab[num] = {abovenode, z, x, test}
num = num+1
else else
data[node] = c_ice data[node] = c_ice
end end
elseif ground_y and data[node] == c_leaves elseif ground_y and data[node] == c_leaves
or data[node] == c_jungleleaves or data[node] == c_apple then or data[node] == c_jungleleaves or data[node] == c_apple then
if alpine 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 for y = ground_y, -6, -1 do
local stone = area:index(x, y, z) local stone = area:index(x, y, z)
if data[stone] == c_stone then if data[stone] == c_stone then
@ -231,54 +228,64 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
end end
else else
data[abovenode] = c_snow snow_tab[num] = {abovenode, z, x, test}
num = num+1
end end
elseif ground_y and data[node] == c_junglegrass then elseif ground_y
and data[node] == c_junglegrass then
data[node] = c_dry_shrub 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 for y = ground_y, ground_y-4, -1 do
local vi = area:index(x, y, z) local vi = area:index(x, y, z)
if data[vi] == c_papyrus then if data[vi] == c_papyrus then
local via = area:index(x, ground_y, z) snow_tab[num] = {area:index(x, ground_y, z), z, x, test}
data[via] = c_snow num = num+1
data[vi] = c_snow_block data[vi] = c_snow_block
end end
end end
elseif ground_y and data[node] == c_water then elseif ground_y
if not icesheet and not icecave and not icehole then 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 x1 = data[area:index(x+1, ground_y, z)]
local z1 = data[area:index(x, ground_y, z+1)] local z1 = data[area:index(x, ground_y, z+1)]
local xz1 = data[area:index(x+1, 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 xz2 = data[area:index(x-1, ground_y, z-1)]
local x2 = data[area:index(x-1, ground_y, z)] local x2 = data[area:index(x-1, ground_y, z)]
local z2 = data[area:index(x, ground_y, z-1)] 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 y = data[area:index(x, ground_y-1, z)]
local rand = pr:next(1,4) == 1 if ice
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))
or (y ~= c_water and y ~= c_ice) -- and y ~= "air") …I don't think y can be a string here ~HybridDog 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 or (icebergs and pr:next(1,6) == 1) then
data[node] = c_ice data[node] = c_ice
end end
else else
if (icehole and pr:next(1,10) > 1) if (icehole and pr:next(1,10) > 1)
or icecave or icesheet then or icecave
or icesheet then
data[node] = c_ice data[node] = c_ice
end end
if icecave then if icecave then
@ -299,15 +306,46 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
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) vm:set_data(data)
if param2s then
vm:set_param2_data(param2s)
end
vm:set_lighting({day=0, night=0}) vm:set_lighting({day=0, night=0})
vm:calc_lighting() vm:calc_lighting()
vm:write_to_map() vm:write_to_map()
if write_to_map and debug then -- print if any column of mapchunk was snow biome if write_to_map
local biome_string,biome2_string = biome_to_string(biome,biome2) 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) 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
end) end)

View File

@ -55,12 +55,12 @@ minetest.register_biome({
minetest.register_biome({ minetest.register_biome({
name = "snow_biome_sand", name = "snow_biome_sand",
node_top = "default:sand", node_top = "default:sand",
depth_top = 3, depth_top = 3,
node_filler = "default:stone", node_filler = "default:stone",
depth_filler = 0, depth_filler = 0,
height_min = -31000, height_min = -31000,
height_max = 2, height_max = 2,
heat_point = 10.0, heat_point = 10.0,

View File

@ -35,10 +35,10 @@ The Xmas tree needles are registred and defined a farther down in this nodes.lua
~ LazyJ ~ LazyJ
--]] --]]
if snow.christmas_content then if snow.christmas_content then
--Christmas trees --Christmas trees
minetest.override_item("snow:needles", { minetest.override_item("snow:needles", {
drop = { drop = {
max_items = 1, max_items = 1,
@ -61,9 +61,9 @@ if snow.christmas_content then
} }
} }
}) })
end end
--Christmas easter egg --Christmas easter egg
minetest.register_on_mapgen_init( function() minetest.register_on_mapgen_init( function()
if rawget(_G, "skins") then 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 animation if it is too much for them. ~ LazyJ
--Decorated Pine leaves --Decorated Pine leaves
@ -179,7 +179,7 @@ minetest.register_node("snow:sapling_pine", {
walkable = false, walkable = false,
groups = {snappy=2,dig_immediate=3}, groups = {snappy=2,dig_immediate=3},
sounds = default.node_sound_defaults(), sounds = default.node_sound_defaults(),
}) })
@ -197,8 +197,9 @@ minetest.register_node("snow:star", {
--groups = {snappy=2,dig_immediate=3}, --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 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 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 on_punch = function(pos, node) -- Added a "lit" star that can be punched on or off depending on your preference. ~ LazyJ
minetest.set_node(pos, {name = "snow:star_lit"}) node.name = "snow:star_lit"
minetest.set_node(pos, node)
nodeupdate(pos) nodeupdate(pos)
end, end,
}) })
@ -217,8 +218,9 @@ minetest.register_node("snow:star_lit", {
drop = "snow:star", drop = "snow:star",
groups = {cracky=1, crumbly=1, choppy=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1}, 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}}), sounds = default.node_sound_glass_defaults({dig = {name="default_glass_footstep", gain=0.2}}),
on_punch = function(pos, node, puncher) on_punch = function(pos, node)
minetest.set_node(pos, {name = "snow:star"}) node.name = "snow:star"
minetest.set_node(pos, node)
nodeupdate(pos) nodeupdate(pos)
end, end,
}) })
@ -264,9 +266,9 @@ minetest.register_node("snow:snow_brick", {
liquidtype = "none", liquidtype = "none",
paramtype = "light", paramtype = "light",
sunlight_propagates = true, 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 -- 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 -- 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}, 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 --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}, dug = {name="default_snow_footstep", gain=0.75},
place = {name="default_place_node", gain=1.0} 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 -- double as dirt_with_frost which adds subtlety to the winterscape. ~ LazyJ
on_construct = snow_onto_dirt on_construct = snow_onto_dirt
}) })
@ -291,9 +293,9 @@ minetest.register_node("snow:snow_cobble", {
is_ground_content = true, is_ground_content = true,
liquidtype = "none", liquidtype = "none",
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
paramtype2 = "facedir", 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 -- 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}, 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({ sounds = default.node_sound_dirt_defaults({
@ -302,7 +304,7 @@ minetest.register_node("snow:snow_cobble", {
dug = {name="default_snow_footstep", gain=0.75}, dug = {name="default_snow_footstep", gain=0.75},
place = {name="default_place_node", gain=1.0} 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 -- double as dirt_with_frost which adds subtlety to the winterscape. ~ LazyJ
on_construct = snow_onto_dirt on_construct = snow_onto_dirt
}) })
@ -313,7 +315,7 @@ minetest.register_node("snow:snow_cobble", {
-- This adds code to the existing default ice. ~ LazyJ -- This adds code to the existing default ice. ~ LazyJ
minetest.override_item("default:ice", { 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 -- the dirt_with_grass/snow/just dirt ABMs. ~ LazyJ, 2014_03_09
use_texture_alpha = true, -- 1 use_texture_alpha = true, -- 1
param2 = 0, param2 = 0,
@ -328,7 +330,7 @@ minetest.override_item("default:ice", {
on_construct = snow_onto_dirt, on_construct = snow_onto_dirt,
liquids_pointable = true, liquids_pointable = true,
--Make ice freeze over when placed by a maximum of 10 blocks. --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)}) minetest.set_node(pos, {name="default:ice", param2=math.random(0,10)})
end 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}, 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", --drop = "snow:snow_cobble",
on_construct = snow_onto_dirt 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 -- dirt_with_frost which adds subtlety to the winterscape. ~ LazyJ, 2014_04_04
}) })

View File

@ -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 * 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 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 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. 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: 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 TODO
~~~~~~ ~~~~~~
* Figure out why the player avatars remain in a seated position, even after getting off the sled, * 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 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? 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 * 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 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 little tweak there" project has evolved into something much bigger and more complex
than I originally planned. :p ~ LazyJ 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 -- 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 function is_water(pos)
local nn = minetest.get_node(pos).name return minetest.get_item_group(minetest.get_node(pos).name, "water") ~= 0
return minetest.get_item_group(nn, "water") ~= 0
end end
@ -63,105 +74,116 @@ end
-- --
local sled = { local sled = {
physical = false, physical = true,
collisionbox = {-0.6,-0.25,-0.6, 0.6,0.3,0.6}, collisionbox = {-0.6,-0.25,-0.6, 0.6,0.3,0.6},
visual = "mesh", visual = "mesh",
mesh = "sled.x", mesh = "sled.x",
textures = {"sled.png"}, textures = {"sled.png"},
nil,
driver = nil,
sliding = false,
} }
local players_sled = {} 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) local function leave_sled(self, player)
if (not self.driver) and snow.sleds then local name = player:get_player_name()
players_sled[clicker:get_player_name()] = true players_sled[name] = false
self.driver = clicker self.driver = nil
self.object:set_attach(clicker, "", {x=0,y=-9,z=0}, {x=0,y=90,z=0}) player:set_detach()
clicker:set_physics_override({ default.player_attached[name] = false
speed = 2, -- multiplier to default value default.player_set_animation(player, "stand" , 30)
jump = 0, -- multiplier to default value
gravity = 1 player:set_physics_override({
}) speed = 1,
--[[ jump = 1,
local HUD = })
{ player:hud_remove(self.HUD) -- And here is part 2. ~ LazyJ
hud_elem_type = "text", -- see HUD element types self.object:remove()
position = {x=0.5, y=0.89},
name = "sled", --Give the sled back again
scale = {x=2, y=2}, player:get_inventory():add_item("main", "snow:sled")
text = "You are sledding, hold sneak to stop.", end
direction = 0,
} function sled:on_rightclick(player)
if self.driver
clicker:hud_add(HUD) 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 -- Here is part 1 of the fix. ~ LazyJ
self.HUD = clicker:hud_add({ self.HUD = player:hud_add({
hud_elem_type = "text", hud_elem_type = "text",
position = {x=0.5, y=0.89}, position = {x=0.5, y=0.89},
name = "sled", name = "sled",
scale = {x=2, y=2}, scale = {x=2, y=2},
text = "You are on the sled! Press the sneak key to get off the sled.", -- LazyJ text = "You are on the sled! Press the sneak key to get off the sled.", -- LazyJ
direction = 0, direction = 0,
}) })
-- End part 1 -- End part 1
end
end end
function sled:on_activate(staticdata, dtime_s) function sled:on_activate(staticdata, dtime_s)
self.object:set_armor_groups({immortal=1}) self.object:set_armor_groups({immortal=1})
self.object:setacceleration({x=0, y=-10, z=0})
if staticdata then if staticdata then
self.v = tonumber(staticdata) self.v = tonumber(staticdata)
end end
end end
function sled:get_staticdata() function sled:get_staticdata()
return tostring(v) return tostring(self.v)
end end
function sled:on_punch(puncher, time_from_last_punch, tool_capabilities, direction) function sled:on_punch(puncher)
self.object:remove() 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") puncher:get_inventory():add_item("main", "snow:sled")
end end
end end
local driveable_nodes = {"default:snow","default:snowblock","default:ice","default:dirt_with_snow", "group:icemaker"}
minetest.register_globalstep(function(dtime) local function accelerating_possible(pos)
for _, player in pairs(minetest.get_connected_players()) do if is_water(pos) then
if players_sled[player:get_player_name()] then return false
default.player_set_animation(player, "sit", 0)
end
end 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) function sled:on_step(dtime)
if self.driver then if not self.driver then
local p = self.object:getpos() return
p.y = p.y+0.4 end
local s = self.object:getpos() timer = timer+dtime
s.y = s.y -0.5 if timer < 1 then
local keys = self.driver:get_player_control() return
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 end
self.driver:set_physics_override({ timer = 0
speed = 1, -- multiplier to default value local player = minetest.get_player_by_name(self.driver)
jump = 1, -- multiplier to default value if not player then
gravity = 1 return
}) end
if player:get_player_control().sneak
players_sled[self.driver:get_player_name()] = false or not accelerating_possible(vector.round(self.object:getpos())) then
self.object:set_detach() leave_sled(self, player)
--self.driver:hud_remove("sled")
self.driver:hud_remove(self.HUD) -- And here is part 2. ~ LazyJ
self.driver = nil
self.object:remove()
end
end end
end end
@ -175,16 +197,18 @@ minetest.register_craftitem("snow:sled", {
wield_scale = {x=2, y=2, z=1}, wield_scale = {x=2, y=2, z=1},
liquids_pointable = true, liquids_pointable = true,
stack_max = 1, stack_max = 1,
on_use = function(itemstack, placer) on_use = function(itemstack, placer)
local pos = {x=0,y=-1000, z=0} if players_sled[placer:get_player_name()] then
local name = placer:get_player_name() return
local player_pos = placer:getpos() end
if not players_sled[name] then local pos = placer:getpos()
if minetest.get_node(player_pos).name == "default:snow" then if accelerating_possible(vector.round(pos)) then
local sled = minetest.add_entity(pos, "snow:sled") pos.y = pos.y+0.5
sled:get_luaentity():on_rightclick(placer)
end --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
end, end,
}) })

View File

@ -3,63 +3,151 @@
--============ --============
-- Snowballs were destroying nodes if the snowballs landed just right. -- 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 -- small handful of code lines making the difference. ~ LazyJ
local snowball_GRAVITY=9 local creative_mode = minetest.setting_getbool("creative_mode")
local snowball_VELOCITY=19
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 --Shoot snowball
local snow_shoot_snowball=function (item, player, pointed_thing) local function snow_shoot_snowball(item, player)
local playerpos=player:getpos() local addp = {y = 1.625} -- + (math.random()-0.5)/5}
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()
local dir=player:get_look_dir() local dif = 2*math.sqrt(dir.z*dir.z+dir.x*dir.x)
obj:setvelocity({x=dir.x*snowball_VELOCITY, y=dir.y*snowball_VELOCITY, z=dir.z*snowball_VELOCITY}) addp.x = dir.z/dif -- + (math.random()-0.5)/5
obj:setacceleration({x=dir.x*-3, y=-snowball_GRAVITY, z=dir.z*-3}) 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() item:take_item()
return item return item
end 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 --The snowball Entity
snow_snowball_ENTITY={ local snow_snowball_ENTITY = {
physical = false, physical = false,
timer=0, timer = 0,
textures = {"default_snowball.png"}, collisionbox = {-5/16,-5/16,-5/16, 5/16,5/16,5/16},
lastpos={},
collisionbox = {0,0,0,0,0,0},
} }
--Snowball_entity.on_step()--> called when snowball is moving. function snow_snowball_ENTITY.on_activate(self)
snow_snowball_ENTITY.on_step = function(self, dtime) self.object:set_properties({textures = {"default_snowball.png^[transform"..math.random(0,7)}})
self.timer=self.timer+dtime self.object:setacceleration({x=0, y=-get_gravity(), z=0})
local pos = self.object:getpos() self.lastpos = self.object:getpos()
local node = minetest.get_node(pos) 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. --Snowball_entity.on_step()--> called when snowball is moving.
if self.lastpos.x~=nil then --If there is no lastpos for some reason. ~ Splizard function snow_snowball_ENTITY.on_step(self, dtime)
-- Check to see what is one node above where the snow is self.timer = self.timer+dtime
-- going to be placed. ~ LazyJ, 2014_04_08 if self.timer > 600 then
local abovesnowballtarget = {x=pos.x, y=pos.y+1, z=pos.z} -- 10 minutes are too long for a snowball to fly somewhere
-- Identify the name of the node that was found above. ~ LazyJ, 2014_04_08 self.object:remove()
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
end 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 end
@ -70,8 +158,8 @@ minetest.register_entity("snow:snowball_entity", snow_snowball_ENTITY)
-- Snowball and Default Snowball Merged -- Snowball and Default Snowball Merged
-- They both look the same, they do basically the same thing (except one is a leftclick throw -- 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 -- and the other is a rightclick drop),... Why not combine snow:snowball with default:snow and
-- benefit from both? ~ LazyJ, 2014_04_08 -- benefit from both? ~ LazyJ, 2014_04_08
--[[ Save this for reference and occasionally compare to the default code for any updates. --[[ Save this for reference and occasionally compare to the default code for any updates.
@ -118,16 +206,8 @@ minetest.override_item("default:snow", {
drop = { drop = {
max_items = 2, max_items = 2,
items = { items = {
{ {items = {'snow:moss'}, rarity = 20,},
-- player will get sapling with 1/20 chance {items = {'default:snow'},}
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'},
}
} }
}, },
leveled = 7, leveled = 7,
@ -137,88 +217,78 @@ minetest.override_item("default:snow", {
{-0.5, -0.5, -0.5, 0.5, -0.5, 0.5}, {-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, sunlight_propagates = true,
--Disable placement prediction for snow. --Disable placement prediction for snow.
node_placement_prediction = "", node_placement_prediction = "",
on_construct = function(pos) on_construct = function(pos)
if minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name == "default:dirt_with_grass" pos.y = pos.y-1
or minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name == "default:dirt" then local node = minetest.get_node(pos)
minetest.set_node({x=pos.x, y=pos.y-1, z=pos.z}, {name="default:dirt_with_snow"}) 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
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. --Handle node drops due to node level.
on_dig = function(pos, node, digger) on_dig = function(pos, node, digger)
local level = minetest.get_node_level(pos) local level = minetest.get_node_level(pos)
minetest.node_dig(pos, node, digger) minetest.node_dig(pos, node, digger)
if minetest.get_node(pos).name ~= node.name then if minetest.get_node(pos).name ~= node.name then
if digger:get_inventory() then local inv = digger:get_inventory()
local _, dropped_item if not inv then
local left = digger:get_inventory():add_item("main", "default:snow "..tostring(level/7-1)) return
if not left:is_empty() then end
local p = { local left = inv:add_item("main", "default:snow "..tostring(level/7-1))
x = pos.x + math.random()/2-0.25, if not left:is_empty() then
y = pos.y + math.random()/2-0.25, minetest.add_item({
z = pos.z + math.random()/2-0.25, x = pos.x + math.random()/2-0.25,
} y = pos.y + math.random()/2-0.25,
minetest.add_item(p, left) z = pos.z + math.random()/2-0.25,
end }, left)
end end
end end
end, end,
--Manage snow levels. --Manage snow levels.
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
local node
local above
local level
local under = pointed_thing.under local under = pointed_thing.under
local oldnode_under = minetest.get_node_or_nil(under) local oldnode_under = minetest.get_node_or_nil(under)
local above = pointed_thing.above local above = pointed_thing.above
local oldnode_above = minetest.get_node_or_nil(above)
if not oldnode_under
if not oldnode_under or not oldnode_above then or not above then
return return
end end
local olddef_under = ItemStack({name=oldnode_under.name}):get_definition() local olddef_under = ItemStack({name=oldnode_under.name}):get_definition()
olddef_under = olddef_under or minetest.nodedef_default 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 node under is buildable_to, place into it instead (eg. snow)
if olddef_under.buildable_to then 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 end
node = minetest.get_node(place_to) local level = minetest.get_node_level(place_to)
level = minetest.get_node_level(place_to)
if level == 63 then if level == 63 then
minetest.set_node(place_to, {name="default:snowblock"}) minetest.set_node(place_to, {name="default:snowblock"})
else else
minetest.set_node_level(place_to, level+7) minetest.set_node_level(place_to, level+7)
end 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) local itemstack, placed = minetest.item_place_node(itemstack, placer, pointed_thing)
return itemstack, placed return itemstack, placed
end end
itemstack:take_item() itemstack:take_item()
return itemstack return itemstack
end, end,
on_use = snow_shoot_snowball -- This line is from the 'Snow' mod, on_use = snow_shoot_snowball
-- the reset is default Minetest. ~ LazyJ
}) })
@ -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 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. 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 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 *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. 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 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 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 "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 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" 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 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 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. 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 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,}) minetest.override_item("default:snow", {buildable_to = false,})
end end
end end
--]] --]]

View File

@ -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 -- next section of stairsplus stuff. ~LazyJ
if (minetest.get_modpath("moreblocks")) 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. -- stairsplus nodes aren't recorded in the logs. Shelved till I can concentrate on it again.
-- ~ LazyJ -- ~ LazyJ
@ -134,7 +134,7 @@ end
end end
return itemstack return itemstack
end end
-- Upside down slabs -- Upside down slabs
if p0.y-1 == p1.y then if p0.y-1 == p1.y then
-- Turn into full block if pointing at a existing slab -- 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 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 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 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 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. a melts value of 2 instead of 1 because they are not full blocks.
~ LazyJ ~ 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 ndef = minetest.registered_nodes["default:ice"]
local groups = {} local groups = {}
for k, v in pairs(ndef.groups) do groups[k] = v end for k, v in pairs(ndef.groups) do groups[k] = v end
stairsplus:register_all("moreblocks", "ice", "default:ice", { stairsplus:register_all("moreblocks", "ice", "default:ice", {
description = ndef.description, description = ndef.description,
paramtype2 = "facedir", 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 -- function in the ABMs.lua file. ~ LazyJ
groups = {cracky=1, crumbly=1, choppy=1, oddly_breakable_by_hand=1, melts=2, icemaker=1}, groups = {cracky=1, crumbly=1, choppy=1, oddly_breakable_by_hand=1, melts=2, icemaker=1},
sounds = default.node_sound_glass_defaults(), sounds = default.node_sound_glass_defaults(),
tiles = ndef.tiles, tiles = ndef.tiles,
-- Because of the "use_texture_alpha" line, that gives ice transparency, I couldn't combine -- 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 -- default ice and default snowblocks in a list like MoreBlocks does. ~ LazyJ
use_texture_alpha = true, use_texture_alpha = true,
sunlight_propagates = true, sunlight_propagates = true,
-- This "on_place" line makes placing these nodes recorded in the logs. -- This "on_place" line makes placing these nodes recorded in the logs.
-- Useful for investigating griefings and determining ownership -- Useful for investigating griefings and determining ownership
-- BUT these nodes will nolonger auto-rotate into position. ~ LazyJ -- BUT these nodes will nolonger auto-rotate into position. ~ LazyJ
--on_place = minetest.item_place, --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 -- also double as dirt_with_frost which adds subtlety to the winterscape. ~ LazyJ
on_construct = function(pos) on_construct = function(pos)
pos.y = pos.y - 1 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 ndef = minetest.registered_nodes["default:snowblock"]
local groups = {} local groups = {}
for k, v in pairs(ndef.groups) do groups[k] = v end for k, v in pairs(ndef.groups) do groups[k] = v end
stairsplus:register_all("moreblocks", "snowblock", "default:snowblock", { stairsplus:register_all("moreblocks", "snowblock", "default:snowblock", {
description = ndef.description, description = ndef.description,
paramtype2 = "facedir", 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 -- in the ABMs.lua file. ~ LazyJ
groups = {cracky=3, crumbly=3, choppy=3, oddly_breakable_by_hand=3, melts=2, icemaker=1}, groups = {cracky=3, crumbly=3, choppy=3, oddly_breakable_by_hand=3, melts=2, icemaker=1},
tiles = ndef.tiles, 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 -- BUT these nodes will nolonger auto-rotate into position. ~ LazyJ
--on_place = minetest.item_place, --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 -- dirt_with_snow could also double as dirt_with_frost
-- which adds subtlety to the winterscape. ~ LazyJ -- which adds subtlety to the winterscape. ~ LazyJ
on_construct = function(pos) on_construct = function(pos)
@ -313,7 +313,7 @@ for _, name in pairs(snow_nodes) do
-- Picking up were we left off... ~ LazyJ -- 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 -- also double as dirt_with_frost which adds subtlety to the winterscape. ~ LazyJ
on_construct = function(pos) on_construct = function(pos)
pos.y = pos.y - 1 pos.y = pos.y - 1
@ -336,7 +336,7 @@ for _, name in pairs(snow_nodes) do
}) })
end 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 -- down to here, "return" nothing and "end" this script. ~ LazyJ
return return
end end

View File

@ -1,6 +1,7 @@
--Global config and function table. --Global config and function table.
snow = { snow = {
legacy = true, snowball_gravity = 100/109,
snowball_velocity = 19,
sleds = true, sleds = true,
enable_snowfall = true, enable_snowfall = true,
lighter_snowfall = false, lighter_snowfall = false,
@ -8,20 +9,21 @@ snow = {
smooth_biomes = true, smooth_biomes = true,
christmas_content = true, christmas_content = true,
smooth_snow = true, smooth_snow = true,
min_height = 50, min_height = 3,
} }
--Config documentation. --Config documentation.
local doc = { 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.", sleds = "Disable this to prevent sleds from being riden.",
enable_snowfall = "Enables falling snow.", enable_snowfall = "Enables falling snow.",
lighter_snowfall = "Reduces the amount of resources and fps used by snowfall.", lighter_snowfall = "Reduces the amount of resources and fps used by snowfall.",
debug = "Enables debug output.", debug = "Enables debug output. Currently it only prints mgv6 info.",
smooth_biomes = "Enables smooth transition of biomes", smooth_biomes = "Enables smooth transition of biomes (mgv6)",
christmas_content = "Disable this to remove christmas saplings from being found.",
smooth_snow = "Disable this to stop snow from being smoothed.", 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. --Manage config.
@ -64,7 +66,9 @@ local function loadConfig(path)
end end
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") local config = loadConfig(minetest.get_modpath("snow").."/config.txt")
if config then if config then
@ -79,7 +83,9 @@ end
for i,v in pairs(snow) do for i,v in pairs(snow) do
local t = type(v) 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) local v = minetest.setting_get("snow_"..i)
if v ~= nil then if v ~= nil then
if v == "true" then v = true end if v == "true" then v = true end
@ -90,18 +96,6 @@ for i,v in pairs(snow) do
end end
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 --MENU
@ -110,7 +104,8 @@ local get_formspec = function()
local formspec = "label[0,-0.3;Settings:]" local formspec = "label[0,-0.3;Settings:]"
for i,v in pairs(snow) do for i,v in pairs(snow) do
local t = type(v) local t = type(v)
if t == "string" or t == "number" then if t == "string"
or t == "number" then
p = p + 1.5 p = p + 1.5
formspec = formspec.."field[0.3,"..p..";2,1;snow:"..i..";"..i..";"..v.."]" formspec = formspec.."field[0.3,"..p..";2,1;snow:"..i..";"..i..";"..v.."]"
elseif t == "boolean" then elseif t == "boolean" then
@ -124,22 +119,27 @@ local get_formspec = function()
end end
minetest.register_on_player_receive_fields(function(player, formname, fields) minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname == "snow:menu" then if formname ~= "snow:menu" then
for i,v in pairs(snow) do return
local t = type(v) end
if t == "string" or t == "number" or t == "boolean" then for i,v in pairs(snow) do
if fields["snow:"..i] then local t = type(v)
if t == "string" then if t == "string" or t == "number" or t == "boolean" then
snow[i] = fields["snow:"..i] 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
if t == "number" then end
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
end end
@ -149,7 +149,8 @@ end)
minetest.register_chatcommand("snow", { minetest.register_chatcommand("snow", {
description = "Show a menu for various actions", description = "Show a menu for various actions",
privs = {server=true}, 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()) minetest.show_formspec(name, "snow:menu", get_formspec())
end, end,
}) })

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 B

View File

@ -1,67 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="16"
height="16"
id="svg2"
version="1.1"
inkscape:version="0.48.4 r9939"
sodipodi:docname="inkscape_default_ice.svg">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="45.4375"
inkscape:cx="6.8335626"
inkscape:cy="8"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:showpageshadow="false"
inkscape:window-width="1328"
inkscape:window-height="895"
inkscape:window-x="197"
inkscape:window-y="70"
inkscape:window-maximized="0" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-1036.3622)">
<rect
style="fill:#91d2ff;fill-rule:evenodd;stroke:none;fill-opacity:1;opacity:0.90000000000000002"
id="rect2985"
width="16"
height="16"
x="0"
y="1036.3622"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90"
inkscape:export-filename="/home/trickpaint/Minetest/Minetest_game_stuff/049_modtest/worlds/developing_snow_overhaul/worldmods/snow_developing/snow/textures/default_ice.png" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 206 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 189 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 350 B

Binary file not shown.