1
0
mirror of https://github.com/Splizard/minetest-mod-snow.git synced 2024-11-06 01:50:19 +01:00

short code

This commit is contained in:
HybridDog 2015-03-06 19:22:45 +01:00
parent e889cbc6a4
commit de76f5dc62
2 changed files with 145 additions and 157 deletions

View File

@ -1,13 +1,12 @@
--Backwards Compatability.
minetest.register_abm({
nodenames = {"snow:snow1","snow:snow2","snow:snow3","gsnow4","snow:snow5","snow:snow6","snow:snow7","snow:snow8"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local level = 7*(tonumber(node.name:sub(-1)))
minetest.add_node(pos,{name="default:snow"})
minetest.set_node_level(pos, level)
end,
nodenames = {"snow:snow1","snow:snow2","snow:snow3","gsnow4","snow:snow5","snow:snow6","snow:snow7","snow:snow8"},
interval = 1,
chance = 1,
action = function(pos, node)
minetest.add_node(pos,{name="default:snow"})
minetest.set_node_level(pos, 7*(tonumber(node.name:sub(-1))))
end,
})
@ -19,12 +18,14 @@ minetest.register_abm({
interval = 2,
chance = 20,
action = function(pos, node)
local above = {x=pos.x, y=pos.y+1, z=pos.z}
local name = minetest.get_node(above).name
local name = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name
local nodedef = minetest.registered_nodes[name]
if name ~= "ignore" and nodedef
and not ((nodedef.sunlight_propagates or nodedef.paramtype == "light")
and nodedef.liquidtype == "none") then
if name ~= "ignore"
and nodedef
and not (
(nodedef.sunlight_propagates or nodedef.paramtype == "light")
and nodedef.liquidtype == "none"
) then
minetest.set_node(pos, {name = "default:dirt"})
end
end
@ -40,16 +41,18 @@ minetest.register_abm({
--3: one water_flowing
minetest.register_abm({
nodenames = {"group:melts"},
neighbors = {"group:igniter","default:torch","default:furnace_active","group:hot"},
interval = 2,
chance = 2,
action = function(pos, node, active_object_count, active_object_count_wider)
nodenames = {"group:melts"},
neighbors = {"group:igniter","default:torch","default:furnace_active","group:hot"},
interval = 2,
chance = 2,
action = function(pos, node)
local intensity = minetest.get_item_group(node.name,"melts")
if intensity == 1 then
minetest.add_node(pos,{name="default:water_source"})
elseif intensity == 2 then
--[[ This was causing "melts=2" nodes to just disappear so I changed it to replace the
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
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)
@ -63,7 +66,7 @@ minetest.register_abm({
check_place({x=pos.x,y=pos.y+1,z=pos.z},{name="default:water_flowing"})
check_place({x=pos.x,y=pos.y-1,z=pos.z},{name="default:water_flowing"})
elseif intensity == 3 then
--]]
--]
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
@ -72,9 +75,10 @@ minetest.register_abm({
minetest.add_node(pos,{name="air"})
end
end)
end
--]]
end
nodeupdate(pos)
end,
end,
})
@ -83,68 +87,60 @@ minetest.register_abm({
--Freezing
--Water freezes when in contact with snow.
minetest.register_abm({
nodenames = {"default:water_source"},
-- Added "group:icemaker" and snowbrick. ~ LazyJ
neighbors = {"default:snow", "default:snowblock", "snow:snow_brick", "group:icemaker"},
interval = 20,
chance = 4,
action = function(pos, node, active_object_count, active_object_count_wider)
nodenames = {"default:water_source"},
-- Added "group:icemaker" and snowbrick. ~ LazyJ
neighbors = {"default:snow", "default:snowblock", "snow:snow_brick", "group:icemaker"},
interval = 20,
chance = 4,
action = function(pos)
minetest.add_node(pos,{name="default:ice"})
end,
end,
})
--Freeze Ice according to it's param2 value.
minetest.register_abm({
nodenames = {"default:ice"},
neighbors = {"default:water_source"},
interval = 20,
chance = 4,
action = function(pos, node, active_object_count, active_object_count_wider)
if node.param2 > 0 then
if math.random(2) == 2 and minetest.get_node({x=pos.x+1, y=pos.y, z=pos.z}).name == "default:water_source" then
minetest.add_node({x=pos.x+1, y=pos.y, z=pos.z},{name="default:ice", param2 = math.random(0,node.param2-1)})
end
if math.random(2) == 2 and minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z}).name == "default:water_source" then
minetest.add_node({x=pos.x-1, y=pos.y, z=pos.z},{name="default:ice", param2 = math.random(0,node.param2-1)})
end
if math.random(2) == 2 and minetest.get_node({x=pos.x, y=pos.y, z=pos.z-1}).name == "default:water_source" then
minetest.add_node({x=pos.x, y=pos.y, z=pos.z-1},{name="default:ice", param2 = math.random(0,node.param2-1)})
end
if math.random(2) == 2 and minetest.get_node({x=pos.x, y=pos.y, z=pos.z+1}).name == "default:water_source" then
minetest.add_node({x=pos.x, y=pos.y, z=pos.z+1},{name="default:ice", param2 = math.random(0,node.param2-1)})
end
if math.random(2) == 2 and minetest.get_node({x=pos.x+1, y=pos.y, z=pos.z-1}).name == "default:water_source" then
minetest.add_node({x=pos.x+1, y=pos.y, z=pos.z-1},{name="default:ice", param2 = math.random(0,node.param2-1)})
end
if math.random(2) == 2 and minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z+1}).name == "default:water_source" then
minetest.add_node({x=pos.x-1, y=pos.y, z=pos.z+1},{name="default:ice", param2 = math.random(0,node.param2-1)})
end
if math.random(2) == 2 and minetest.get_node({x=pos.x+1, y=pos.y, z=pos.z+1}).name == "default:water_source" then
minetest.add_node({x=pos.x+1, y=pos.y, z=pos.z+1},{name="default:ice", param2 = math.random(0,node.param2-1)})
end
if math.random(2) == 2 and minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z-1}).name == "default:water_source" then
minetest.add_node({x=pos.x-1, y=pos.y, z=pos.z-1},{name="default:ice", param2 = math.random(0,node.param2-1)})
nodenames = {"default:ice"},
neighbors = {"default:water_source"},
interval = 20,
chance = 4,
action = function(pos, node)
if node.param2 > 0 then
for l = 0,1 do
for i = -1,1,2 do
for _,p in pairs({
{x=pos.x+i, z=pos.z-l*i},
{x=pos.x+l*i, z=pos.z+i}
}) do
if math.random(2) == 2 then
p.y = pos.y
if minetest.get_node(p).name == "default:water_source" then
minetest.add_node(p,{name="default:ice", param2 = math.random(0,node.param2-1)})
end
end
end
end
end
if math.random(8) == 8 then
minetest.add_node({x=pos.x, y=pos.y, z=pos.z}, {name="default:water_source"})
minetest.add_node(pos, {name="default:water_source"})
else
minetest.add_node({x=pos.x, y=pos.y, z=pos.z}, {name="default:ice", param2 = 0})
minetest.add_node(pos, {name="default:ice", param2 = 0})
end
end
end,
end,
})
--Spread moss to cobble.
minetest.register_abm({
nodenames = {"default:cobble"},
neighbors = {"snow:moss"},
interval = 20,
chance = 6,
action = function(pos, node, active_object_count, active_object_count_wider)
minetest.add_node(pos,{name="default:mossycobble"})
end,
nodenames = {"default:cobble"},
neighbors = {"snow:moss"},
interval = 20,
chance = 6,
action = function(pos, node)
node.name = "default:mossycobble"
minetest.add_node(pos, node)
end,
})
@ -152,35 +148,30 @@ minetest.register_abm({
--Grow Pine Saplings
minetest.register_abm({
nodenames = {"snow:sapling_pine"},
interval = 10,
chance = 50,
action = function(pos, node, active_object_count, active_object_count_wider)
nodenames = {"snow:sapling_pine"},
interval = 10,
chance = 50,
action = function(pos, node)
-- Check if there is enough vertical-space for the sapling to grow without
-- hitting anything else. ~ LazyJ, 2014_04_10
if -- 'If' there is air in each of the 8 nodes dirctly above the sapling,... ~LazyJ
minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name == "air" and
minetest.get_node({x=pos.x, y=pos.y+2, z=pos.z}).name == "air" and
minetest.get_node({x=pos.x, y=pos.y+3, z=pos.z}).name == "air" and
minetest.get_node({x=pos.x, y=pos.y+4, z=pos.z}).name == "air" and
minetest.get_node({x=pos.x, y=pos.y+5, z=pos.z}).name == "air" and
minetest.get_node({x=pos.x, y=pos.y+6, z=pos.z}).name == "air" and
minetest.get_node({x=pos.x, y=pos.y+7, z=pos.z}).name == "air" and
minetest.get_node({x=pos.x, y=pos.y+8, z=pos.z}).name == "air"
then -- 'then' let the sapling grow into a tree. ~ LazyJ
-- 'If' there is air in each of the 8 nodes dirctly above the sapling,... ~LazyJ
for i = 1,8 do
if minetest.get_node({x=pos.x, y=pos.y+i, z=pos.z}).name ~= "air" then
return
end
end
-- 'then' let the sapling grow into a tree. ~ LazyJ
snow.make_pine(pos,false)
-- This finds the sapling under the grown tree. ~ LazyJ
if minetest.get_node({x = pos.x, y = pos.y, z = pos.z}).name == "snow:sapling_pine" then
-- This switches the sapling to a tree trunk. ~ LazyJ
minetest.set_node(pos, {name="default:tree"})
-- 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
else
-- This finds the sapling under the grown tree. ~ LazyJ
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
-- grepping the server logs too. ~ LazyJ
minetest.log("action", "A pine sapling grows into a tree at "..minetest.pos_to_string(pos))
end
end
})
@ -190,27 +181,24 @@ minetest.register_abm({
--Grow Christmas Tree Saplings
minetest.register_abm({
nodenames = {"snow:xmas_tree"},
interval = 10,
chance = 50,
action = function(pos, node, active_object_count, active_object_count_wider)
nodenames = {"snow:xmas_tree"},
interval = 10,
chance = 50,
action = function(pos, node, active_object_count, active_object_count_wider)
if -- 'If' there is air in each of the 8 nodes dirctly above the sapling,... ~LazyJ
minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name == "air" and
minetest.get_node({x=pos.x, y=pos.y+2, z=pos.z}).name == "air" and
minetest.get_node({x=pos.x, y=pos.y+3, z=pos.z}).name == "air" and
minetest.get_node({x=pos.x, y=pos.y+4, z=pos.z}).name == "air" and
minetest.get_node({x=pos.x, y=pos.y+5, z=pos.z}).name == "air" and
minetest.get_node({x=pos.x, y=pos.y+6, z=pos.z}).name == "air" and
minetest.get_node({x=pos.x, y=pos.y+7, z=pos.z}).name == "air" and
minetest.get_node({x=pos.x, y=pos.y+8, z=pos.z}).name == "air"
then -- 'then' let the sapling grow into a tree. ~ LazyJ
-- 'If' there is air in each of the 8 nodes dirctly above the sapling,... ~LazyJ
for i = 1,8 do
if minetest.get_node({x=pos.x, y=pos.y+i, z=pos.z}).name ~= "air" then
return
end
end
-- 'then' let the sapling grow into a tree. ~ LazyJ
snow.make_pine(pos,false,true)
minetest.log("action", "A pine sapling grows into a Christmas tree at "..minetest.pos_to_string(pos)) -- ~ LazyJ
else -- 'Else', if there isn't air in each of the 8 nodes above the sapling,
--else -- 'Else', if there isn't air in each of the 8 nodes above the sapling,
-- then don't anything; including not allowing the sapling to grow.
-- ~ LazyJ, 2014_04_10
end
end
--end
end
})

View File

@ -68,59 +68,59 @@ local xmas_tree = {
--Makes pine tree
function snow.make_pine(pos,snow,xmas)
local env = minetest.env
local perlin1 = env:get_perlin(112,3, 0.5, 150)
local try_node = function(pos, node)
local n = env:get_node(pos).name
if n == "air" or n == "ignore" then
env:add_node(pos,node)
end
end
--Clear ground.
for x=-1,1 do
for z=-1,1 do
if env:get_node({x=pos.x+x,y=pos.y,z=pos.z+z}).name == "default:snow" then
env:remove_node({x=pos.x+x,y=pos.y,z=pos.z+z})
end
if env:get_node({x=pos.x+x,y=pos.y,z=pos.z+z}).name == "default:snowblock" then
env:remove_node({x=pos.x+x,y=pos.y,z=pos.z+z})
end
end
end
if xmas then
env:remove_node(pos)
minetest.env:spawn_tree(pos, xmas_tree)
else
minetest.env:spawn_tree(pos, pine_tree)
end
if snow then
local x,z = pos.x,pos.z
try_node({x=x+1,y=pos.y+3,z=z+1},{name="default:snow"})
try_node({x=x-1,y=pos.y+3,z=z-1},{name="default:snow"})
try_node({x=x-1,y=pos.y+3,z=z+1},{name="default:snow"})
try_node({x=x+1,y=pos.y+3,z=z-1},{name="default:snow"})
try_node({x=x+1,y=pos.y+5,z=z},{name="default:snow"})
try_node({x=x-1,y=pos.y+5,z=z},{name="default:snow"})
try_node({x=x,y=pos.y+5,z=z+1},{name="default:snow"})
try_node({x=x,y=pos.y+5,z=z-1},{name="default:snow"})
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
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="default:snow"})
end
local minetest = minetest
local perlin1 = minetest.get_perlin(112,3, 0.5, 150)
local try_node = function(pos, node)
local n = minetest.get_node(pos).name
if n == "air" 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})
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)
minetest.spawn_tree(pos, xmas_tree)
else
minetest.spawn_tree(pos, pine_tree)
end
if snow then
local x,z = pos.x,pos.z
try_node({x=x+1,y=pos.y+3,z=z+1},{name="default:snow"})
try_node({x=x-1,y=pos.y+3,z=z-1},{name="default:snow"})
try_node({x=x-1,y=pos.y+3,z=z+1},{name="default:snow"})
try_node({x=x+1,y=pos.y+3,z=z-1},{name="default:snow"})
try_node({x=x+1,y=pos.y+5,z=z},{name="default:snow"})
try_node({x=x-1,y=pos.y+5,z=z},{name="default:snow"})
try_node({x=x,y=pos.y+5,z=z+1},{name="default:snow"})
try_node({x=x,y=pos.y+5,z=z-1},{name="default:snow"})
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
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="default:snow"})
end
end
--Makes pine tree
function snow.voxelmanip_pine(pos,a,data)
local c_snow = minetest.get_content_id("default:snow")
local c_pine_needles = minetest.get_content_id("snow:needles")
local c_pinetree = minetest.get_content_id("default:pinetree")
local c_air = minetest.get_content_id("air")
local c_snow = minetest.get_content_id("default:snow")
local c_pine_needles = minetest.get_content_id("snow:needles")
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