mirror of
https://github.com/luanti-org/minetest_game.git
synced 2025-05-20 22:33:16 -04:00
176 lines
4.5 KiB
Lua
176 lines
4.5 KiB
Lua
-- Space apple tree
|
|
|
|
function moonrealm_appletree(pos)
|
|
local x = pos.x
|
|
local y = pos.y
|
|
local z = pos.z
|
|
for j = -2, -1 do
|
|
local nodename = minetest.get_node({x=x,y=y+j,z=z}).name
|
|
if nodename ~= "moonrealm:soil" then
|
|
return
|
|
end
|
|
end
|
|
for j = 1, 5 do
|
|
local nodename = minetest.get_node({x=x,y=y+j,z=z}).name
|
|
if nodename ~= "moonrealm:air" then
|
|
return
|
|
end
|
|
end
|
|
for j = -2, 4 do
|
|
if j >= 1 then
|
|
for i = -2, 2 do
|
|
for k = -2, 2 do
|
|
local nodename = minetest.get_node({x=x+i,y=y+j+1,z=z+k}).name
|
|
if math.random() > (math.abs(i) + math.abs(k)) / 16 then
|
|
if math.random(13) == 2 then
|
|
minetest.add_node({x=pos.x+i,y=pos.y+j+1,z=pos.z+k},{name="default:apple"})
|
|
else
|
|
minetest.add_node({x=pos.x+i,y=pos.y+j+1,z=pos.z+k},{name="moonrealm:leaves"})
|
|
end
|
|
else
|
|
minetest.add_node({x=x+i,y=y+j+1,z=z+k},{name="moonrealm:air"})
|
|
minetest.get_meta({x=x+i,y=y+j+1,z=z+k}):set_int("spread", 16)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
minetest.add_node({x=pos.x,y=pos.y+j,z=pos.z},{name="default:tree"})
|
|
end
|
|
print ("[moonrealm] Appletree sapling grows")
|
|
end
|
|
|
|
-- Vacuum or air flows into a dug hole
|
|
|
|
minetest.register_on_dignode(function(pos, oldnode, digger)
|
|
local x = pos.x
|
|
local y = pos.y
|
|
local z = pos.z
|
|
for i = -1,1 do
|
|
for j = -1,1 do
|
|
for k = -1,1 do
|
|
if not (i == 0 and j == 0 and k == 0) then
|
|
local nodename = minetest.get_node({x=x+i,y=y+j,z=z+k}).name
|
|
if nodename == "moonrealm:air" then
|
|
local spread = minetest.get_meta({x=x+i,y=y+j,z=z+k}):get_int("spread")
|
|
if spread > 0 then
|
|
minetest.add_node({x=x,y=y,z=z},{name="moonrealm:air"})
|
|
minetest.get_meta(pos):set_int("spread", (spread - 1))
|
|
print ("[moonrealm] MR air flows into hole "..(spread - 1))
|
|
return
|
|
end
|
|
elseif nodename == "moonrealm:vacuum" then
|
|
minetest.add_node({x=x,y=y,z=z},{name="moonrealm:vacuum"})
|
|
print ("[moonrealm] Vacuum flows into hole")
|
|
return
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end)
|
|
|
|
minetest.register_on_mapgen_init(function(mgparams)
|
|
minetest.set_mapgen_params({mgname="singlenode"})
|
|
end)
|
|
|
|
-- ABMs
|
|
|
|
-- Air spreads
|
|
|
|
minetest.register_abm({
|
|
nodenames = {"moonrealm:air"},
|
|
neighbors = {"moonrealm:vacuum", "air"},
|
|
interval = 11,
|
|
chance = 9,
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
local spread = minetest.get_meta(pos):get_int("spread")
|
|
if spread <= 0 then
|
|
return
|
|
end
|
|
local x = pos.x
|
|
local y = pos.y
|
|
local z = pos.z
|
|
for i = -1,1 do
|
|
for j = -1,1 do
|
|
for k = -1,1 do
|
|
if not (i == 0 and j == 0 and k == 0) then
|
|
local nodename = minetest.get_node({x=x+i,y=y+j,z=z+k}).name
|
|
if nodename == "moonrealm:vacuum"
|
|
or nodename == "air" then
|
|
minetest.add_node({x=x+i,y=y+j,z=z+k},{name="moonrealm:air"})
|
|
minetest.get_meta({x=x+i,y=y+j,z=z+k}):set_int("spread", (spread - 1))
|
|
print ("[moonrealm] MR air spreads "..(spread - 1))
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
})
|
|
|
|
-- Hydroponic saturation
|
|
|
|
minetest.register_abm({
|
|
nodenames = {"moonrealm:hlsource", "moonrealm:hlflowing"},
|
|
neighbors = {"moonrealm:dust", "moonrealm:dustprint1", "moonrealm:dustprint2"},
|
|
interval = 29,
|
|
chance = 9,
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
local x = pos.x
|
|
local y = pos.y
|
|
local z = pos.z
|
|
for i = -2,2 do
|
|
for j = -4,0 do -- saturates out and downwards to pos.y - 4, a 5x5 cube.
|
|
for k = -2,2 do
|
|
if not (i == 0 and j == 0 and k == 0) then
|
|
local nodename = minetest.get_node({x=x+i,y=y+j,z=z+k}).name
|
|
if nodename == "moonrealm:dust"
|
|
or nodename == "moonrealm:dustprint1"
|
|
or nodename == "moonrealm:dustprint2" then
|
|
minetest.add_node({x=x+i,y=y+j,z=z+k},{name="moonrealm:soil"})
|
|
print ("[moonrealm] Hydroponic liquid saturates")
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
})
|
|
|
|
-- Soil drying
|
|
|
|
minetest.register_abm({
|
|
nodenames = {"moonrealm:soil"},
|
|
interval = 31,
|
|
chance = 27,
|
|
action = function(pos, node)
|
|
local x = pos.x
|
|
local y = pos.y
|
|
local z = pos.z
|
|
for i = -2, 2 do
|
|
for j = 0, 4 do -- search above for liquid
|
|
for k = -2, 2 do
|
|
if not (i == 0 and j == 0 and k == 0) then
|
|
local nodename = minetest.get_node({x=x+i,y=y+j,z=z+k}).name
|
|
if nodename == "moonrealm:hlsource" or nodename == "moonrealm:hlflowing" then
|
|
return
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
minetest.add_node(pos,{name="moonrealm:dust"})
|
|
print ("[moonrealm] Moon soil dries")
|
|
end,
|
|
})
|
|
|
|
-- Space appletree from sapling
|
|
|
|
minetest.register_abm({
|
|
nodenames = {"moonrealm:sapling"},
|
|
interval = 57,
|
|
chance = 3,
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
moonrealm_appletree(pos)
|
|
end,
|
|
})
|