coffer dam

master
Izzy 2019-06-30 14:44:59 -06:00
parent 8252946140
commit e4f0831a83
2 changed files with 139 additions and 0 deletions

View File

@ -17,6 +17,7 @@ dofile(modpath.."/metals.lua")
dofile(modpath.."/geodes.lua")
dofile(modpath.."/hotsprings.lua")
dofile(modpath.."/structures/ziggurat.lua")
dofile(modpath.."/structures/coffer_dam.lua")
-- core
dofile(modpath.."/minetunnels.lua")

138
structures/coffer_dam.lua Normal file
View File

@ -0,0 +1,138 @@
local function drop_column(pos, node, maxdrop)
local maxd = pos.y - maxdrop
local p = {x=pos.x, y=pos.y, z=pos.z}
while p.y >= maxd do
local n = minetest.get_node(p)
local def = minetest.registered_nodes[n.name]
if def.groups.liquid then
minetest.set_node(p, {name=node})
else
break
end
p.y = p.y - 1
end
end
local function drop_wall(start, length, dir, node, maxdrop)
local p = {x=start.x, y=start.y, z=start.z}
for i = 1,length do
drop_column(p, node, maxdrop)
p = vector.add(p, dir)
end
end
local function drop_octagon(center, rad)
drop_wall(vector.add(center, {x=rad*2, y=0, z=rad}), rad*2+1, {x=0,y=0,z=-1}, "default:cobble", 10)
drop_wall(vector.add(center, {x=-rad*2, y=0, z=-rad}), rad*2+1, {x=0,y=0,z=1}, "default:cobble", 10)
drop_wall(vector.add(center, {x=rad, y=0, z=rad*2}), rad*2+1, {x=-1,y=0,z=0}, "default:cobble", 10)
drop_wall(vector.add(center, {x=-rad, y=0, z=-rad*2}), rad*2+1, {x=1,y=0,z=0}, "default:cobble", 10)
drop_wall(vector.add(center, {x=rad, y=0, z=-rad*2}), rad, {x=1,y=0,z=1}, "default:cobble", 10)
drop_wall(vector.add(center, {x=-rad, y=0, z=rad*2}), rad, {x=-1,y=0,z=-1}, "default:cobble", 10)
drop_wall(vector.add(center, {x=-rad, y=0, z=-rad*2}), rad, {x=-1,y=0,z=1}, "default:cobble", 10)
drop_wall(vector.add(center, {x=rad, y=0, z=rad*2}), rad, {x=1,y=0,z=-1}, "default:cobble", 10)
-- drop_wall(vector.add(center, {x=-rad, y=0, z=rad/2}), rad/2, {x=1,y=0,z=-1}, "default:cobble", 10)
end
local function freeze_top(pos, cb)
local stack = {}
local out = {}
table.insert(stack, pos)
local function process()
local i = 0
while #stack > 0 do
local nn = math.random(#stack)
-- print("index "..nn .. " of "..#stack)
local p = table.remove(stack, nn)
-- print(dump(p))
local n = minetest.get_node(p)
if n.name == "default:water_source" then
table.insert(out, p)
minetest.set_node(p, {name="default:ice"})
table.insert(stack, vector.add(p, {x=1, y=0, z=0}))
table.insert(stack, vector.add(p, {x=-1, y=0, z=0}))
table.insert(stack, vector.add(p, {x=0, y=0, z=1}))
table.insert(stack, vector.add(p, {x=0, y=0, z=-1}))
if #stack > 0 and i > 5 then
minetest.after(1, process)
return
elseif #stack == 0 then
cb(out)
end
i = i + 1
end
end
cb(out)
end
process()
end
local function clear_water(pts, maxd, top_off)
for _,p in ipairs(pts) do
drop_column({x=p.x, y=p.y-top_off, z=p.z}, "air", maxd - top_off)
end
end
local function remove_points(pts, lvl)
for _,p in ipairs(pts) do
minetest.set_node({x=p.x, y=p.y-lvl, z=p.z}, {name="air"})
end
end
minetest.register_node("potions:coffer_dam_seed", {
description = "Coffer Dam Seed",
drawtype = "node",
tiles = {"default_stone_brick.png"},
groups = {cracky=3,},
liquids_pointable=true,
on_construct = function(pos)
minetest.set_node(pos, {name="default:water_source"})
drop_octagon(pos, 3)
freeze_top(pos, function(pts)
-- print("points "..#pts)
clear_water(pts, 10, 1)
minetest.after(2, remove_points, pts, 0)
end)
end
})