1
0
Fork 0

use swap_node instead of set_node in mapgen, tweaks to end

This commit is contained in:
kno10 2024-09-05 21:28:47 +02:00
parent e746ef46a9
commit 465b4162e7
11 changed files with 83 additions and 72 deletions

View File

@ -1131,3 +1131,16 @@ if not vector.in_area then
(pos.z >= min.z) and (pos.z <= max.z)
end
end
if not minetest.bulk_swap_node then -- maybe in 5.10 https://github.com/minetest/minetest/pull/15043
minetest.bulk_swap_node = function(pos_list, node)
-- for dense and large sets, we could also try a VManip, but often this enough for now
local swap_node = minetest.swap_node
for _, pos in ipairs(pos_list) do
swap_node(pos, node)
end
end
-- async emerge environment, untested:
if minetest.set_node == minetest.swap_node then minetest.bulk_swap_node = minetest.bulk_set_node end
end

View File

@ -3542,11 +3542,11 @@ local function mangrove_root_gennotify(t, minp, maxp, blockseed)
if minetest.get_item_group(n, "water") > 0 then
local wl = "mcl_mangrove:water_logged_roots"
if n:find("river") then wl = "mcl_mangrove:river_water_logged_roots" end
minetest.bulk_set_node(minetest.find_nodes_in_area(v, vector.offset(v, 0, -l, 0), {"group:water"}), {name = wl})
minetest.bulk_swap_node(minetest.find_nodes_in_area(v, vector.offset(v, 0, -l, 0), {"group:water"}), {name = wl})
elseif n == "mcl_mud:mud" then
minetest.bulk_set_node(minetest.find_nodes_in_area(v, vector.offset(v, 0, -l, 0), {"mcl_mud:mud"}), {name = "mcl_mangrove:mangrove_mud_roots"})
minetest.bulk_swap_node(minetest.find_nodes_in_area(v, vector.offset(v, 0, -l, 0), {"mcl_mud:mud"}), {name = "mcl_mangrove:mangrove_mud_roots"})
elseif n == "air" then
minetest.bulk_set_node(minetest.find_nodes_in_area(v, vector.offset(v, 0, -l, 0), {"air"}), {name = "mcl_mangrove:mangrove_roots"})
minetest.bulk_swap_node(minetest.find_nodes_in_area(v, vector.offset(v, 0, -l, 0), {"air"}), {name = "mcl_mangrove:mangrove_roots"})
end
end
end

View File

@ -432,7 +432,7 @@ minetest.register_lbm({
local grass_palette_index = mcl_util.get_palette_indexes_from_pos(pos).grass_palette_index
if node.param2 ~= grass_palette_index then
node.param2 = grass_palette_index
minetest.set_node(pos, node)
minetest.swap_node(pos, node)
end
end
})
@ -451,14 +451,14 @@ minetest.register_lbm({
minetest.place_node(vector.offset(pos, 0, 1, 0), node) -- Offset required, since otherwise the leaves sink one node for some reason.
elseif node.param2 ~= foliage_palette_index and node.name ~= "mcl_core:vine" then
node.param2 = foliage_palette_index
minetest.set_node(pos, node)
minetest.swap_node(pos, node)
elseif node.name == "mcl_core:vine" then
local biome_param2 = foliage_palette_index
local rotation_param2 = mcl_util.get_colorwallmounted_rotation(pos)
local final_param2 = (biome_param2 * 8) + rotation_param2
if node.param2 ~= final_param2 then
node.param2 = final_param2
minetest.set_node(pos, node)
minetest.swap_node(pos, node)
end
end
end
@ -473,7 +473,7 @@ minetest.register_lbm({
local water_palette_index = mcl_util.get_palette_indexes_from_pos(pos).water_palette_index
if node.param2 ~= water_palette_index then
node.param2 = water_palette_index
minetest.set_node(pos, node)
minetest.swap_node(pos, node)
end
end
})
@ -486,7 +486,7 @@ minetest.register_lbm({
action = function(pos, node)
if node.param2 ~= 3 then
node.param2 = 3
minetest.set_node(pos, node)
minetest.swap_node(pos, node)
end
end
})
@ -503,14 +503,14 @@ local function fix_foliage_missed(minp, maxp, blockseed)
local foliage_palette_index = mcl_util.get_palette_indexes_from_pos(fpos).foliage_palette_index
if fnode.param2 ~= foliage_palette_index and fnode.name ~= "mcl_core:vine" then
fnode.param2 = foliage_palette_index
minetest.set_node(fpos, fnode)
minetest.swap_node(fpos, fnode)
elseif fnode.name == "mcl_core:vine" then
local biome_param2 = foliage_palette_index
local rotation_param2 = mcl_util.get_colorwallmounted_rotation(fpos)
local final_param2 = (biome_param2 * 8) + rotation_param2
if fnode.param2 ~= final_param2 then
fnode.param2 = final_param2
minetest.set_node(fpos, fnode)
minetest.swap_node(fpos, fnode)
end
end
end

View File

@ -570,7 +570,7 @@ local function generate_mgv6_structures()
local function place_tree_if_free(pos, prev_result)
local nn = minetest.get_node(pos).name
if nn == "mcl_flowers:waterlily" or nn == "mcl_core:water_source" or nn == "mcl_core:water_flowing" or nn == "air" then
minetest.set_node(pos, {name="mcl_core:tree", param2=0})
minetest.swap_node(pos, {name="mcl_core:tree", param2=0})
return prev_result
else
return false
@ -676,9 +676,9 @@ local function generate_underground_mushrooms(minp, maxp, seed)
local l = minetest.get_node_light(bpos, 0.5)
if bpos.y >= min and bpos.y <= max and l and l <= 12 and pr_shroom:next(1,1000) < 4 then
if pr_shroom:next(1,2) == 1 then
minetest.set_node(bpos, {name = "mcl_mushrooms:mushroom_brown"})
minetest.swap_node(bpos, {name = "mcl_mushrooms:mushroom_brown"})
else
minetest.set_node(bpos, {name = "mcl_mushrooms:mushroom_red"})
minetest.swap_node(bpos, {name = "mcl_mushrooms:mushroom_red"})
end
end
end
@ -715,14 +715,14 @@ local function generate_nether_decorations(minp, maxp, seed)
special_deco(rack, function(bpos)
-- Eternal fire on netherrack
if pr_nether:next(1,100) <= 3 then
minetest.set_node(bpos, {name = "mcl_fire:eternal_fire"})
minetest.swap_node(bpos, {name = "mcl_fire:eternal_fire"})
end
end)
-- Eternal fire on magma cubes
special_deco(magma, function(bpos)
if pr_nether:next(1,150) == 1 then
minetest.set_node(bpos, {name = "mcl_fire:eternal_fire"})
minetest.swap_node(bpos, {name = "mcl_fire:eternal_fire"})
end
end)
@ -733,9 +733,9 @@ local function generate_nether_decorations(minp, maxp, seed)
if bpos.y > mcl_vars.mg_lava_nether_max + 6 and l and l <= 12 and pr_nether:next(1,1000) <= 4 then
-- TODO: Make mushrooms appear in groups, use Perlin noise
if pr_nether:next(1,2) == 1 then
minetest.set_node(bpos, {name = "mcl_mushrooms:mushroom_brown"})
minetest.swap_node(bpos, {name = "mcl_mushrooms:mushroom_brown"})
else
minetest.set_node(bpos, {name = "mcl_mushrooms:mushroom_red"})
minetest.swap_node(bpos, {name = "mcl_mushrooms:mushroom_red"})
end
end
end)
@ -744,7 +744,7 @@ local function generate_nether_decorations(minp, maxp, seed)
-- TODO: Spawn in Nether fortresses
special_deco(ssand, function(bpos)
if pr_nether:next(1, nether_wart_chance) == 1 then
minetest.set_node(bpos, {name = "mcl_nether:nether_wart"})
minetest.swap_node(bpos, {name = "mcl_nether:nether_wart"})
end
end)
end

View File

@ -50,7 +50,7 @@ vl_structures.register_structure("nether_bridge",{
table.insert(bricks,leg)
end
end
minetest.bulk_set_node(bricks, {name = "mcl_nether:nether_brick", param2 = 2})
minetest.bulk_swap_node(bricks, {name = "mcl_nether:nether_brick", param2 = 2})
end
})
@ -112,7 +112,7 @@ vl_structures.register_structure("nether_outpost_with_bridges",{
table.insert(bricks,leg)
end
end
minetest.bulk_set_node(bricks, {name = "mcl_nether:nether_brick", param2 = 2})
minetest.bulk_swap_node(bricks, {name = "mcl_nether:nether_brick", param2 = 2})
local p1, p2 = vector.offset(pos,-45,12,-45), vector.offset(pos,45,22,45)
vl_structures.spawn_mobs("mobs_mc:witherskeleton",{"mcl_blackstone:blackstone_chiseled_polished"},p1,p2,pr,5)

View File

@ -14,9 +14,9 @@ mcl_structures.spawn_end_gateway_portal = function(pos)
vl_structures.place_schematic(pos, 0, schematic, "0", { name="end_gateway_portal", prepare = false })
end
local function make_endspike(pos, width, height)
local function make_endspike(pos, rad, height)
-- FIXME: why find_nodes, not just use the circle?
local nn = minetest.find_nodes_in_area(vector.offset(pos, -width/2, 0, -width/2), vector.offset(pos, width/2, 0, width/2), {"air", "group:solid"})
local nn = minetest.find_nodes_in_area(vector.offset(pos, -rad, 0, -rad), vector.offset(pos, rad, 0, rad), {"air", "group:solid"})
table.sort(nn,function(a, b)
return vector.distance(pos, a) < vector.distance(pos, b)
end)
@ -26,20 +26,21 @@ local function make_endspike(pos, width, height)
table.insert(nodes, vector.offset(nn[i], 0, j, 0))
end
end
minetest.bulk_set_node(nodes, {name = "mcl_core:obsidian"})
minetest.bulk_swap_node(nodes, {name = "mcl_core:obsidian"})
return vector.offset(pos, 0, height, 0)
end
function make_cage(pos, width)
function make_cage(pos, rad)
if not xpanes then return end
local nodes = {}
local r = math.max(1, math.floor(width/2) - 2)
for x=-r,r do for y = 0,width do for z = -r,r do
if x == r or x == -r or z==r or z == -r then
table.insert(nodes,vector.add(pos,vector.new(x,y,z)))
end
end end end
minetest.bulk_set_node(nodes, {name = "xpanes:bar_flat"} )
local r = math.max(1, rad - 2)
for y = 0, rad * 2 do for xz = -r, r do
table.insert(nodes,vector.add(pos,vector.new(xz,y, r)))
table.insert(nodes,vector.add(pos,vector.new(xz,y,-r)))
table.insert(nodes,vector.add(pos,vector.new( r,y,xz)))
table.insert(nodes,vector.add(pos,vector.new(-r,y,xz)))
end end
minetest.bulk_swap_node(nodes, {name = "xpanes:bar_flat"} )
for _,p in pairs(nodes) do xpanes.update_pane(p) end
end
@ -60,35 +61,32 @@ mcl_mapgen_core.register_generator("end structures", nil, function(minp, maxp, b
if vector.in_area(pos, minp, maxp) then
local obby = minetest.find_nodes_in_area(vector.offset(pos,-2,0,-2),vector.offset(pos,2,0,2),{"air","mcl_end:end_stone"})
local air = minetest.find_nodes_in_area(vector.offset(pos,-2,1,-2),vector.offset(pos,2,3,2),{"air","mcl_end:end_stone"})
minetest.bulk_set_node(obby,{name="mcl_core:obsidian"})
minetest.bulk_set_node(air,{name="air"})
minetest.bulk_swap_node(obby,{name="mcl_core:obsidian"})
minetest.bulk_swap_node(air,{name="air"})
end
-- end exit portal and pillars
local pos = mcl_vars.mg_end_exit_portal_pos
if vector.in_area(pos, minp, maxp) then
pr = PcgRandom(worldseed)
local pr = PcgRandom(worldseed)
-- emerge pillars
for _, pos in ipairs(get_points_on_circle(vector.offset(mcl_vars.mg_end_exit_portal_pos, 0, -20, 0), 43, 10)) do
local d = pr:next(6,12)
local h = d * pr:next(4,6)
local p1, p2 = vector.offset(pos, -d / 2, 0, -d / 2), vector.offset(pos, d / 2, h + d, d / 2)
local p1, p2 = vector.offset(pos, -43-6, -10, -43-6), vector.offset(pos, 43+6, 12*6-10, 43+6)
minetest.emerge_area(p1, p2, function(_, _, calls_remaining)
if calls_remaining ~= 0 then return end
local s = make_endspike(pos,d,h)
minetest.set_node(vector.offset(s,0,1,0),{name="mcl_core:bedrock"})
minetest.add_entity(vector.offset(s,0,2,0),"mcl_end:crystal")
if pr:next(1,3) == 1 then
make_cage(vector.offset(s,0,1,0),d)
for _, p in ipairs(get_points_on_circle(vector.offset(pos, 0, -10, 0), 43, 10)) do
local rad = pr:next(3,6)
local top = make_endspike(p, rad, rad * 2 * pr:next(4,6) - 10)
minetest.swap_node(vector.offset(top, 0, 1, 0), {name = "mcl_core:bedrock"})
minetest.add_entity(vector.offset(top, 0, 2, 0), "mcl_end:crystal")
if pr:next(1, 3) == 1 then make_cage(vector.offset(top, 0, 1, 0), rad) end
end
end)
end
-- emerge end portal
local schematic = vl_structures.load_schematic(modpath.."/schematics/mcl_structures_end_exit_portal.mts")
vl_structures.place_schematic(pos, 0, schematic, "0", { name = "end portal", prepare = false,
after_place = function(pos,def,pr,pmin,pmax,size,rot)
-- spawn ender dragon
if minetest.settings:get_bool("only_peaceful_mobs", false) then return end
minetest.bulk_set_node(minetest.find_nodes_in_area(pmin, pmax, {"mcl_portals:portal_end"}), { name="air" })
minetest.bulk_swap_node(minetest.find_nodes_in_area(pmin, pmax, {"mcl_portals:portal_end"}), { name="air" })
local obj = minetest.add_entity(vector.offset(pos, 3, 11, 3), "mobs_mc:enderdragon")
if obj then
local dragon_entity = obj:get_luaentity()

View File

@ -33,14 +33,14 @@ local def = {
local rack = minetest.find_nodes_in_area(p1,p2,{"mcl_nether:netherrack"})
local brick = minetest.find_nodes_in_area(p1,p2,{"mcl_core:stonebrick"})
local obby = minetest.find_nodes_in_area(p1,p2,{"mcl_core:obsidian"})
minetest.bulk_set_node(get_replacements(gold,30,pr),{name="air"})
minetest.bulk_set_node(get_replacements(lava,20,pr),{name="mcl_nether:magma"})
minetest.bulk_set_node(get_replacements(rack,7,pr),{name="mcl_nether:magma"})
minetest.bulk_set_node(get_replacements(obby,30,pr),{name="mcl_core:crying_obsidian"})
minetest.bulk_set_node(get_replacements(obby,10,pr),{name="air"})
minetest.bulk_set_node(get_replacements(brick,50,pr),{name="mcl_core:stonebrickcracked"})
minetest.bulk_swap_node(get_replacements(gold,30,pr),{name="air"})
minetest.bulk_swap_node(get_replacements(lava,20,pr),{name="mcl_nether:magma"})
minetest.bulk_swap_node(get_replacements(rack,7,pr),{name="mcl_nether:magma"})
minetest.bulk_swap_node(get_replacements(obby,30,pr),{name="mcl_core:crying_obsidian"})
minetest.bulk_swap_node(get_replacements(obby,10,pr),{name="air"})
minetest.bulk_swap_node(get_replacements(brick,50,pr),{name="mcl_core:stonebrickcracked"})
brick = minetest.find_nodes_in_area(p1,p2,{"mcl_core:stonebrick"})
minetest.bulk_set_node(get_replacements(brick,50,pr),{name="mcl_core:stonebrickmossy"})
minetest.bulk_swap_node(get_replacements(brick,50,pr),{name="mcl_core:stonebrickmossy"})
end,
loot = {
["mcl_chests:chest_small" ] ={{

View File

@ -40,7 +40,7 @@ local function hut_placement_callback(pos,def,pr,p1,p2)
table.insert(tree,leg)
end
end
minetest.bulk_set_node(tree, {name = "mcl_core:tree", param2 = 2})
minetest.bulk_swap_node(tree, {name = "mcl_core:tree", param2 = 2})
spawn_witch(p1,p2)
end

View File

@ -33,8 +33,8 @@ local function makelake(pos,size,liquid,placein,border,pr,noair)
airtower(nn[i],air,20)
table.insert(lq,nn[i])
end
minetest.bulk_set_node(lq,{name=liquid})
minetest.bulk_set_node(air,{name="air"})
minetest.bulk_swap_node(lq,{name=liquid})
minetest.bulk_swap_node(air,{name="air"})
air = {}
local br = {}
for k,v in pairs(lq) do
@ -61,8 +61,8 @@ local function makelake(pos,size,liquid,placein,border,pr,noair)
end
end
end
minetest.bulk_set_node(br,{name=border})
minetest.bulk_set_node(air,{name="air"})
minetest.bulk_swap_node(br,{name=border})
minetest.bulk_swap_node(air,{name="air"})
return true
end)
return true
@ -258,8 +258,8 @@ vl_structures.register_structure("basalt_column",{
end
end
end
minetest.bulk_set_node(magma,{name="mcl_nether:magma"})
minetest.bulk_set_node(basalt,{name="mcl_blackstone:basalt"})
minetest.bulk_swap_node(magma,{name="mcl_nether:magma"})
minetest.bulk_swap_node(basalt,{name="mcl_blackstone:basalt"})
return true
end
})
@ -299,8 +299,8 @@ vl_structures.register_structure("basalt_pillar",{
end
end
end
minetest.bulk_set_node(basalt,{name="mcl_blackstone:basalt"})
minetest.bulk_set_node(magma,{name="mcl_nether:magma"})
minetest.bulk_swap_node(basalt,{name="mcl_blackstone:basalt"})
minetest.bulk_swap_node(magma,{name="mcl_nether:magma"})
return true
end
})
@ -333,7 +333,7 @@ vl_structures.register_structure("lavadelta",{
for i=1,pr:next(1,#nn) do
table.insert(lava,nn[i])
end
minetest.bulk_set_node(lava,{name="mcl_nether:nether_lava_source"})
minetest.bulk_swap_node(lava,{name="mcl_nether:nether_lava_source"})
local basalt = {}
local magma = {}
for _,v in pairs(lava) do
@ -348,8 +348,8 @@ vl_structures.register_structure("lavadelta",{
table.insert(magma,v)
end
end
minetest.bulk_set_node(basalt,{name="mcl_blackstone:basalt"})
minetest.bulk_set_node(magma,{name="mcl_nether:magma"})
minetest.bulk_swap_node(basalt,{name="mcl_blackstone:basalt"})
minetest.bulk_swap_node(magma,{name="mcl_nether:magma"})
return true
end
})

View File

@ -14,7 +14,7 @@ local path_ends = {}
function mcl_villages.clean_no_paths(minp, maxp)
local no_paths_nodes = minetest.find_nodes_in_area(minp, maxp, { "mcl_villages:no_paths" })
if #no_paths_nodes > 0 then
minetest.bulk_set_node(no_paths_nodes, { name = "air" })
minetest.bulk_swap_node(no_paths_nodes, { name = "air" })
end
end

View File

@ -378,8 +378,8 @@ local function Platform(p, radius, node, node2)
end
end
end
minetest.bulk_set_node(n1,node)
minetest.bulk_set_node(n2,node2)
minetest.bulk_swap_node(n1,node)
minetest.bulk_swap_node(n2,node2)
end
-- Chests