Use voxelmanip for on_dignode, air spread, hydroponic saturation and soil drying

This commit is contained in:
Mat 2014-07-14 13:52:30 +01:00
parent d7e546bae9
commit 0557561d65
2 changed files with 116 additions and 48 deletions

View File

@ -76,28 +76,45 @@ minetest.register_on_dignode(function(pos, oldnode, digger)
local x = pos.x local x = pos.x
local y = pos.y local y = pos.y
local z = pos.z local z = pos.z
for i = -1,1 do local c_lsair = minetest.get_content_id("moonrealm:air")
local c_vacuum = minetest.get_content_id("moonrealm:vacuum")
local vm = minetest.get_voxel_manip()
local pos1 = {x=x-1, y=y-1, z=z-1}
local pos2 = {x=x+1, y=y+1, z=z+1}
local emin, emax = vm:read_from_map(pos1, pos2)
local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
local data = vm:get_data()
local vic = area:index(x, y, z)
for j = -1,1 do for j = -1,1 do
for k = -1,1 do for k = -1,1 do
if not (i == 0 and j == 0 and k == 0) then local vi = area:index(x-1, y+j, z+k)
local nodename = minetest.get_node({x=x+i,y=y+j,z=z+k}).name for i = -1,1 do
if nodename == "moonrealm:air" then if not (i == 0 and j == 0 and k == 0) then
local spread = minetest.get_meta({x=x+i,y=y+j,z=z+k}):get_int("spread") local nodid = data[vi]
if spread > 0 then if nodid == c_lsair then
minetest.add_node({x=x,y=y,z=z},{name="moonrealm:air"}) local spread = minetest.get_meta({x=x+i,y=y+j,z=z+k}):get_int("spread")
minetest.get_meta(pos):set_int("spread", (spread - 1)) if spread > 0 then
print ("[moonrealm] MR air flows into hole "..(spread - 1)) data[vic] = c_lsair
return minetest.get_meta(pos):set_int("spread", (spread - 1))
vm:set_data(data)
vm:write_to_map()
vm:update_map()
print ("[moonrealm] MR air flows into hole")
return
end
end 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
vi = vi + 1
end end
end end
end end
end data[vic] = c_vacuum
vm:set_data(data)
vm:write_to_map()
vm:update_map()
print ("[moonrealm] Vacuum flows into hole")
end) end)
-- ABMs -- ABMs
@ -106,39 +123,55 @@ end)
minetest.register_abm({ minetest.register_abm({
nodenames = {"moonrealm:air"}, nodenames = {"moonrealm:air"},
neighbors = {"moonrealm:vacuum", "air"}, neighbors = {"moonrealm:vacuum"},
interval = 11, interval = 13,
chance = 9, chance = 9,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
local spread = minetest.get_meta(pos):get_int("spread") local spread = minetest.get_meta(pos):get_int("spread")
if spread <= 0 then if spread <= 0 then
return return
end end
local x = pos.x local x = pos.x
local y = pos.y local y = pos.y
local z = pos.z local z = pos.z
for i = -1,1 do local c_lsair = minetest.get_content_id("moonrealm:air")
local c_vacuum = minetest.get_content_id("moonrealm:vacuum")
local vm = minetest.get_voxel_manip()
local pos1 = {x=x-1, y=y-1, z=z-1}
local pos2 = {x=x+1, y=y+1, z=z+1}
local emin, emax = vm:read_from_map(pos1, pos2)
local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
local data = vm:get_data()
for j = -1,1 do for j = -1,1 do
for k = -1,1 do for k = -1,1 do
if not (i == 0 and j == 0 and k == 0) then local vi = area:index(x-1, y+j, z+k)
local nodename = minetest.get_node({x=x+i,y=y+j,z=z+k}).name for i = -1,1 do
if nodename == "moonrealm:vacuum" if not (i == 0 and j == 0 and k == 0) then
or nodename == "air" then local nodid = data[vi]
minetest.add_node({x=x+i,y=y+j,z=z+k},{name="moonrealm:air"}) if nodid == c_vacuum then
minetest.get_meta({x=x+i,y=y+j,z=z+k}):set_int("spread", (spread - 1)) data[vi] = c_lsair
print ("[moonrealm] MR air spreads "..(spread - 1)) minetest.get_meta({x=x+i,y=y+j,z=z+k}):set_int("spread", (spread - 1))
print ("[moonrealm] MR air spreads")
end
end end
vi = vi + 1
end end
end end
end end
end
vm:set_data(data)
vm:write_to_map()
vm:update_map()
end end
}) })
-- Hydroponic saturation -- Hydroponic saturation
minetest.register_abm({ minetest.register_abm({
nodenames = {"moonrealm:hlsource", "moonrealm:hlflowing"}, nodenames = {"moonrealm:hlsource"},
neighbors = {"moonrealm:dust", "moonrealm:dustprint1", "moonrealm:dustprint2"}, neighbors = {"moonrealm:dust", "moonrealm:dustprint1", "moonrealm:dustprint2"},
interval = 29, interval = 29,
chance = 9, chance = 9,
@ -146,21 +179,40 @@ minetest.register_abm({
local x = pos.x local x = pos.x
local y = pos.y local y = pos.y
local z = pos.z 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. local c_dust = minetest.get_content_id("moonrealm:dust")
local c_dustp1 = minetest.get_content_id("moonrealm:dustprint1")
local c_dustp2 = minetest.get_content_id("moonrealm:dustprint2")
local c_soil = minetest.get_content_id("moonrealm:soil")
local vm = minetest.get_voxel_manip()
local pos1 = {x=x-2, y=y-4, z=z-2}
local pos2 = {x=x+2, y=y, z=z+2}
local emin, emax = vm:read_from_map(pos1, pos2)
local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
local data = vm:get_data()
for j = -4,0 do
for k = -2,2 do for k = -2,2 do
if not (i == 0 and j == 0 and k == 0) then local vi = area:index(x-2, y+j, z+k)
local nodename = minetest.get_node({x=x+i,y=y+j,z=z+k}).name for i = -2,2 do
if nodename == "moonrealm:dust" if not (i == 0 and j == 0 and k == 0) then
or nodename == "moonrealm:dustprint1" local nodid = data[vi]
or nodename == "moonrealm:dustprint2" then if nodid == c_dust
minetest.add_node({x=x+i,y=y+j,z=z+k},{name="moonrealm:soil"}) or nodid == c_dustp1
print ("[moonrealm] Hydroponic liquid saturates") or nodid == c_dustp2 then
data[vi] = c_soil
print ("[moonrealm] Hydroponic liquid saturates")
end
end end
vi = vi + 1
end end
end end
end end
end
vm:set_data(data)
vm:write_to_map()
vm:update_map()
end end
}) })
@ -169,24 +221,42 @@ minetest.register_abm({
minetest.register_abm({ minetest.register_abm({
nodenames = {"moonrealm:soil"}, nodenames = {"moonrealm:soil"},
interval = 31, interval = 31,
chance = 27, chance = 9,
action = function(pos, node) action = function(pos, node)
local x = pos.x local x = pos.x
local y = pos.y local y = pos.y
local z = pos.z local z = pos.z
for i = -2, 2 do local c_dust = minetest.get_content_id("moonrealm:dust")
for j = 0, 4 do -- search above for liquid local c_hlsource = minetest.get_content_id("moonrealm:hlsource")
local vm = minetest.get_voxel_manip()
local pos1 = {x=x-2, y=y, z=z-2}
local pos2 = {x=x+2, y=y+4, z=z+2}
local emin, emax = vm:read_from_map(pos1, pos2)
local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
local data = vm:get_data()
local vic = area:index(x, y, z)
for j = 0, 4 do
for k = -2, 2 do for k = -2, 2 do
if not (i == 0 and j == 0 and k == 0) then local vi = area:index(x-2, y+j, z+k)
local nodename = minetest.get_node({x=x+i,y=y+j,z=z+k}).name for i = -2, 2 do
if nodename == "moonrealm:hlsource" or nodename == "moonrealm:hlflowing" then if not (i == 0 and j == 0 and k == 0) then
return local nodid = data[vi]
if nodid == c_hlsource then
return
end
end end
vi = vi + 1
end end
end end
end end
end data[vic] = c_dust
minetest.add_node(pos,{name="moonrealm:dust"})
vm:set_data(data)
vm:write_to_map()
vm:update_map()
print ("[moonrealm] Moon soil dries") print ("[moonrealm] Moon soil dries")
end, end,
}) })

View File

@ -3,8 +3,6 @@
-- Depends default -- Depends default
-- Licenses: code WTFPL, textures CC BY-SA -- Licenses: code WTFPL, textures CC BY-SA
-- speed increase by using voxelmanip for scanning chunk below / initialising stability table
-- LVM appletree, new design, spawn with LVM
-- TODO -- TODO
-- on-dignode, air, hydroponics, soil drying by LVM too -- on-dignode, air, hydroponics, soil drying by LVM too