Use voxelmanip to set the correct param2 for nodes

Voxelmanip is now used to set the correct `param2` for the nodes which use biome colouring or, in the case of seagrass, the correct meshoption.
This commit is contained in:
FossFanatic 2023-04-03 14:35:24 +00:00 committed by Gitea
parent d53ea65da8
commit 76bf98b26c
1 changed files with 106 additions and 48 deletions

View File

@ -290,6 +290,60 @@ local function set_grass_palette(minp,maxp,data2,area,biomemap,nodes)
return lvm_used
end
local function set_foliage_palette(minp,maxp,data2,area,biomemap,nodes)
-- Flat area at y=0 to read biome 3 times faster than 5.3.0.get_biome_data(pos).biome: 43us vs 125us per iteration:
if not biomemap then return end
local aream = VoxelArea:new({MinEdge={x=minp.x, y=0, z=minp.z}, MaxEdge={x=maxp.x, y=0, z=maxp.z}})
local nodes = minetest.find_nodes_in_area(minp, maxp, nodes)
for n=1, #nodes do
local n = nodes[n]
local p_pos = area:index(n.x, n.y, n.z)
local b_pos = aream:index(n.x, 0, n.z)
local bn = minetest.get_biome_name(biomemap[b_pos])
if bn then
local biome = minetest.registered_biomes[bn]
if biome and biome._mcl_biome_type and biome._mcl_foliage_palette_index then
data2[p_pos] = biome._mcl_foliage_palette_index
lvm_used = true
end
end
end
return lvm_used
end
local function set_water_palette(minp,maxp,data2,area,biomemap,nodes)
-- Flat area at y=0 to read biome 3 times faster than 5.3.0.get_biome_data(pos).biome: 43us vs 125us per iteration:
if not biomemap then return end
local aream = VoxelArea:new({MinEdge={x=minp.x, y=0, z=minp.z}, MaxEdge={x=maxp.x, y=0, z=maxp.z}})
local nodes = minetest.find_nodes_in_area(minp, maxp, nodes)
for n=1, #nodes do
local n = nodes[n]
local p_pos = area:index(n.x, n.y, n.z)
local b_pos = aream:index(n.x, 0, n.z)
local bn = minetest.get_biome_name(biomemap[b_pos])
if bn then
local biome = minetest.registered_biomes[bn]
if biome and biome._mcl_biome_type and biome._mcl_water_palette_index then
data2[p_pos] = biome._mcl_water_palette_index
lvm_used = true
end
end
end
return lvm_used
end
local function set_seagrass_param2(minp,maxp,data2,area,biomemap,nodes)
local aream = VoxelArea:new({MinEdge={x=minp.x, y=0, z=minp.z}, MaxEdge={x=maxp.x, y=0, z=maxp.z}})
local nodes = minetest.find_nodes_in_area(minp, maxp, nodes)
for n=1, #nodes do
local n = nodes[n]
local p_pos = area:index(n.x, n.y, n.z)
data2[p_pos] = 3
lvm_used = true
end
return lvm_used
end
-- Below the bedrock, generate air/void
local function world_structure(vm, data, data2, emin, emax, area, minp, maxp, blockseed)
local biomemap --ymin, ymax
@ -346,16 +400,9 @@ local function world_structure(vm, data, data2, emin, emax, area, minp, maxp, bl
end
local function block_fixes_grass(vm, data, data2, emin, emax, area, minp, maxp, blockseed)
if maxp.y < mcl_vars.mg_overworld_min then
--minetest.log("Exit grass fix")
return
else
--minetest.log("Grass fixes")
end
local biomemap = minetest.get_mapgen_object("biomemap")
local lvm_used = false
local pr = PseudoRandom(blockseed)
if minp.y <= mcl_vars.mg_overworld_max and maxp.y >= mcl_vars.mg_overworld_min then
-- Set param2 (=color) of nodes which use the grass colour palette.
lvm_used = set_grass_palette(minp,maxp,data2,area,biomemap,{"group:grass_palette"})
@ -363,6 +410,37 @@ local function block_fixes_grass(vm, data, data2, emin, emax, area, minp, maxp,
return lvm_used
end
local function block_fixes_foliage(vm, data, data2, emin, emax, area, minp, maxp, blockseed)
local biomemap = minetest.get_mapgen_object("biomemap")
local lvm_used = false
local pr = PseudoRandom(blockseed)
if minp.y <= mcl_vars.mg_overworld_max and maxp.y >= mcl_vars.mg_overworld_min then
-- Set param2 (=color) of nodes which use the foliage colour palette.
lvm_used = set_foliage_palette(minp,maxp,data2,area,biomemap,{"group:foliage_palette"})
end
return lvm_used
end
local function block_fixes_water(vm, data, data2, emin, emax, area, minp, maxp, blockseed)
local biomemap = minetest.get_mapgen_object("biomemap")
local lvm_used = false
local pr = PseudoRandom(blockseed)
if minp.y <= mcl_vars.mg_overworld_max and maxp.y >= mcl_vars.mg_overworld_min then
-- Set param2 (=color) of nodes which use the water colour palette.
lvm_used = set_water_palette(minp,maxp,data2,area,biomemap,{"group:water_palette"})
end
return lvm_used
end
local function block_fixes_seagrass(vm, data, data2, emin, emax, area, minp, maxp, blockseed)
local lvm_used = false
local pr = PseudoRandom(blockseed)
if minp.y <= mcl_vars.mg_overworld_max and maxp.y >= mcl_vars.mg_overworld_min then
-- Set param2 of seagrass to 3.
lvm_used = set_seagrass_param2(minp,maxp,data2,area,biomemap,{"group:seagrass"})
end
return lvm_used
end
-- End block fixes:
local function end_basic(vm, data, data2, emin, emax, area, minp, maxp, blockseed)
@ -391,6 +469,9 @@ end, 9999, true)
if mg_name ~= "v6" and mg_name ~= "singlenode" then
mcl_mapgen_core.register_generator("block_fixes_grass", block_fixes_grass, nil, 9999, true)
mcl_mapgen_core.register_generator("block_fixes_foliage", block_fixes_foliage, nil, 9999, true)
mcl_mapgen_core.register_generator("block_fixes_water", block_fixes_water, nil, 9999, true)
mcl_mapgen_core.register_generator("block_fixes_seagrass", block_fixes_seagrass, nil, 9999, true)
end
if mg_name == "v6" then
@ -467,28 +548,6 @@ minetest.register_lbm({
end
})
minetest.register_on_generated(function(minp, maxp, blockseed) -- Set correct palette indexes of foliage in new mapblocks.
local pos1, pos2 = vector.offset(minp, -16, -16, -16), vector.offset(maxp, 16, 16, 16)
local foliage = minetest.find_nodes_in_area(pos1, pos2, {"group:foliage_palette", "group:foliage_palette_wallmounted"})
for _, fpos in pairs(foliage) do
local fnode = minetest.get_node(fpos)
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)
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)
end
end
end
end
)
minetest.register_lbm({
label = "Fix water palette indexes", -- Set correct palette indexes of water in old mapblocks.
name = "mcl_mapgen_core:fix_water_palette_indexes",
@ -503,16 +562,15 @@ minetest.register_lbm({
end
})
minetest.register_on_generated(function(minp, maxp, blockseed) -- Set correct palette indexes of water in new mapblocks.
local pos1, pos2 = vector.offset(minp, -16, -16, -16), vector.offset(maxp, 16, 16, 16)
local water = minetest.find_nodes_in_area(pos1, pos2, {"group:water_palette"})
for _, wpos in pairs(water) do
local wnode = minetest.get_node(wpos)
local water_palette_index = mcl_util.get_palette_indexes_from_pos(wpos).water_palette_index
if wnode.param2 ~= water_palette_index then
wnode.param2 = water_palette_index
minetest.set_node(wpos, wnode)
minetest.register_lbm({
label = "Fix incorrect seagrass", -- Set correct param2 of seagrass in old mapblocks.
name = "mcl_mapgen_core:fix_incorrect_seagrass",
nodenames = {"group:seagrass"},
run_at_every_load = false,
action = function(pos, node)
if node.param2 ~= 3 then
node.param2 = 3
minetest.set_node(pos, node)
end
end
end
)
})