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

View File

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