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

@ -3,10 +3,9 @@ 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)))
action = function(pos, node)
minetest.add_node(pos,{name="default:snow"})
minetest.set_node_level(pos, level)
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
@ -44,12 +45,14 @@ minetest.register_abm({
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)
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,6 +75,7 @@ minetest.register_abm({
minetest.add_node(pos,{name="air"})
end
end)
--]]
end
nodeupdate(pos)
end,
@ -88,7 +92,7 @@ minetest.register_abm({
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)
action = function(pos)
minetest.add_node(pos,{name="default:ice"})
end,
})
@ -99,36 +103,27 @@ minetest.register_abm({
neighbors = {"default:water_source"},
interval = 20,
chance = 4,
action = function(pos, node, active_object_count, active_object_count_wider)
action = function(pos, node)
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)})
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
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)})
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,
@ -142,8 +137,9 @@ minetest.register_abm({
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"})
action = function(pos, node)
node.name = "default:mossycobble"
minetest.add_node(pos, node)
end,
})
@ -155,33 +151,28 @@ minetest.register_abm({
nodenames = {"snow:sapling_pine"},
interval = 10,
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
-- 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
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:tree"})
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
else
end
end
})
@ -195,22 +186,19 @@ minetest.register_abm({
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
})

View File

@ -68,30 +68,30 @@ 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 minetest = minetest
local perlin1 = minetest.get_perlin(112,3, 0.5, 150)
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
env:add_node(pos,node)
minetest.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})
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 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})
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
env:remove_node(pos)
minetest.env:spawn_tree(pos, xmas_tree)
minetest.remove_node(pos)
minetest.spawn_tree(pos, xmas_tree)
else
minetest.env:spawn_tree(pos, pine_tree)
minetest.spawn_tree(pos, pine_tree)
end
if snow then
local x,z = pos.x,pos.z