mirror of
http://repo.or.cz/minetest_pyramids/tsm_pyramids.git
synced 2025-01-09 07:50:18 +01:00
Use bulk_set_node to improve efficiency
This commit is contained in:
parent
bd38820a32
commit
b00f540567
31
init.lua
31
init.lua
@ -83,16 +83,16 @@ local function can_replace(pos)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function underground(pos, stone, sand)
|
local function make_foundation_part(pos, set_to_stone)
|
||||||
local p2 = pos
|
local p2 = pos
|
||||||
local cnt = 0
|
local cnt = 0
|
||||||
local mat = stone
|
|
||||||
p2.y = p2.y-1
|
p2.y = p2.y-1
|
||||||
while can_replace(p2)==true do
|
while can_replace(p2)==true do
|
||||||
cnt = cnt+1
|
cnt = cnt+1
|
||||||
if cnt > 25 then break end
|
if cnt > 25 then
|
||||||
if cnt>math.random(2,4) then mat = stone end
|
break
|
||||||
minetest.set_node(p2, {name=mat})
|
end
|
||||||
|
table.insert(set_to_stone, table.copy(p2))
|
||||||
p2.y = p2.y-1
|
p2.y = p2.y-1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -117,22 +117,35 @@ local function make_entrance(pos, brick, sand, flood_sand)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function make(pos, brick, sandstone, stone, sand, ptype, room_id)
|
local function make_pyramid(pos, brick, sandstone, stone, sand)
|
||||||
|
local set_to_brick = {}
|
||||||
|
local set_to_sand = {}
|
||||||
|
local set_to_stone = {}
|
||||||
-- Build pyramid
|
-- Build pyramid
|
||||||
for iy=0,math.random(10,11),1 do
|
for iy=0,math.random(10,11),1 do
|
||||||
for ix=iy,22-iy,1 do
|
for ix=iy,22-iy,1 do
|
||||||
for iz=iy,22-iy,1 do
|
for iz=iy,22-iy,1 do
|
||||||
if iy <1 then underground({x=pos.x+ix,y=pos.y,z=pos.z+iz}, stone, sand) end
|
if iy < 1 then
|
||||||
minetest.set_node({x=pos.x+ix,y=pos.y+iy,z=pos.z+iz}, {name=brick})
|
make_foundation_part({x=pos.x+ix,y=pos.y,z=pos.z+iz}, set_to_stone)
|
||||||
|
end
|
||||||
|
table.insert(set_to_brick, {x=pos.x+ix,y=pos.y+iy,z=pos.z+iz})
|
||||||
for yy=1,10-iy,1 do
|
for yy=1,10-iy,1 do
|
||||||
local n = minetest.get_node({x=pos.x+ix,y=pos.y+iy+yy,z=pos.z+iz})
|
local n = minetest.get_node({x=pos.x+ix,y=pos.y+iy+yy,z=pos.z+iz})
|
||||||
if n and n.name and n.name == stone then
|
if n and n.name and n.name == stone then
|
||||||
minetest.set_node({x=pos.x+ix,y=pos.y+iy+yy,z=pos.z+iz},{name=sand})
|
table.insert(set_to_sand, {x=pos.x+ix,y=pos.y+iy+yy,z=pos.z+iz})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
minetest.bulk_set_node(set_to_stone , {name=stone})
|
||||||
|
minetest.bulk_set_node(set_to_brick, {name=brick})
|
||||||
|
minetest.bulk_set_node(set_to_sand, {name=sand})
|
||||||
|
end
|
||||||
|
|
||||||
|
local function make(pos, brick, sandstone, stone, sand, ptype, room_id)
|
||||||
|
-- Build pyramid
|
||||||
|
make_pyramid(pos, brick, sandstone, stone, sand)
|
||||||
-- Build room
|
-- Build room
|
||||||
local ok, msg, flood_sand = tsm_pyramids.make_room(pos, ptype, room_id)
|
local ok, msg, flood_sand = tsm_pyramids.make_room(pos, ptype, room_id)
|
||||||
-- Place mummy spawner
|
-- Place mummy spawner
|
||||||
|
4
room.lua
4
room.lua
@ -690,6 +690,7 @@ function tsm_pyramids.make_traps(pos, stype)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function tsm_pyramids.flood_sand(pos, stype)
|
function tsm_pyramids.flood_sand(pos, stype)
|
||||||
|
local set_to_sand = {}
|
||||||
local nn = "default:sand"
|
local nn = "default:sand"
|
||||||
if stype == "desert" then
|
if stype == "desert" then
|
||||||
nn = "default:desert_sand"
|
nn = "default:desert_sand"
|
||||||
@ -704,11 +705,12 @@ function tsm_pyramids.flood_sand(pos, stype)
|
|||||||
for iy=0,h,1 do
|
for iy=0,h,1 do
|
||||||
local p = {x=hole.x+ix,y=hole.y+iy,z=hole.z+iz}
|
local p = {x=hole.x+ix,y=hole.y+iy,z=hole.z+iz}
|
||||||
if minetest.get_node(p).name == "air" then
|
if minetest.get_node(p).name == "air" then
|
||||||
minetest.set_node(p, {name=nn})
|
table.insert(set_to_sand, p)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
minetest.bulk_set_node(set_to_sand, {name=nn})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user