1
0
Fork 0

Add LBMs, ABMs, and more

This commit adds 1 new LBM (for foliage) and 2 new ABMs (one for foliage, and one for grass).

This also adds a new generator so any new maps created will have biome coloured leaves with a faster method. (Vines are excluded from this generator since I don't know yet how to get those to work with this.)
texture_conversion_wool
FossFanatic 2023-02-08 16:17:33 +00:00
parent 07f332f0cd
commit b95ebb3fca
1 changed files with 115 additions and 5 deletions

View File

@ -268,7 +268,7 @@ local function set_layers(data, area, content_id, check, min, max, minp, maxp, l
return lvm_used
end
local function set_palette(minp,maxp,data2,area,biomemap,nodes)
local function set_grass_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}})
@ -289,6 +289,27 @@ local function set_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
-- Below the bedrock, generate air/void
local function world_structure(vm, data, data2, emin, emax, area, minp, maxp, blockseed)
local biomemap --ymin, ymax
@ -344,13 +365,24 @@ local function world_structure(vm, data, data2, emin, emax, area, minp, maxp, bl
return lvm_used, lvm_used, deco, ores
end
local function block_fixes(vm, data, data2, emin, emax, area, minp, maxp, blockseed)
local function block_fixes_grass(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 grass colour palette.
lvm_used = set_palette(minp,maxp,data2,area,biomemap,{"mcl_core:dirt_with_grass", "mcl_flowers:tallgrass", "mcl_flowers:double_grass", "mcl_flowers:double_grass_top", "mcl_flowers:fern", "mcl_flowers:double_fern", "mcl_flowers:double_fern_top", "mcl_core:reeds", "mcl_core:dirt_with_grass_snow"})
lvm_used = set_grass_palette(minp,maxp,data2,area,biomemap,{"mcl_core:dirt_with_grass", "mcl_flowers:tallgrass", "mcl_flowers:double_grass", "mcl_flowers:double_grass_top", "mcl_flowers:fern", "mcl_flowers:double_fern", "mcl_flowers:double_fern_top", "mcl_core:reeds", "mcl_core:dirt_with_grass_snow"})
end
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
@ -382,7 +414,8 @@ mcl_mapgen_core.register_generator("end_fixes", end_basic, function(minp,maxp)
end, 9999, true)
if mg_name ~= "v6" and mg_name ~= "singlenode" then
mcl_mapgen_core.register_generator("block_fixes", block_fixes, nil, 9999, true)
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)
end
if mg_name == "v6" then
@ -419,7 +452,7 @@ mcl_mapgen_core.register_generator("structures",nil, function(minp, maxp, blocks
end, 100, true)
minetest.register_lbm({
label = "Fix grass palette indexes",
label = "Fix grass palette indexes", -- This LBM fixes any incorrect grass palette indexes.
name = "mcl_mapgen_core:fix_grass_palette_indexes",
nodenames = {"mcl_core:dirt_with_grass", "mcl_flowers:tallgrass", "mcl_flowers:double_grass", "mcl_flowers:double_grass_top", "mcl_flowers:fern", "mcl_flowers:double_fern", "mcl_flowers:double_fern_top", "mcl_core:reeds", "mcl_core:dirt_with_grass_snow"},
run_at_every_load = true,
@ -436,3 +469,80 @@ minetest.register_lbm({
end
end,
})
minetest.register_abm({
label = "Fix grass palette indexes missed", -- This ABM fixes any incorrect grass palette indexes which were missed. Likely to be any grass from a schematic.
name = "mcl_mapgen_core:fix_grass_palette_indexes missed",
nodenames = {"mcl_core:dirt_with_grass", "mcl_flowers:tallgrass", "mcl_flowers:double_grass", "mcl_flowers:double_grass_top", "mcl_flowers:fern", "mcl_flowers:double_fern", "mcl_flowers:double_fern_top", "mcl_core:reeds", "mcl_core:dirt_with_grass_snow"},
neighbors = {"mcl_core:dirt_with_grass", "mcl_flowers:tallgrass", "mcl_flowers:double_grass", "mcl_flowers:double_grass_top", "mcl_flowers:fern", "mcl_flowers:double_fern", "mcl_flowers:double_fern_top", "mcl_core:reeds", "mcl_core:dirt_with_grass_snow"},
interval = 60,
chance = 1,
action = function(pos, node)
if mg_name ~= "v6" and mg_name ~= "singlenode" then
local biome_data = minetest.get_biome_data(pos)
local biome = biome_data.biome
local biome_name = minetest.get_biome_name(biome)
local reg_biome = minetest.registered_biomes[biome_name]
if node.param2 ~= reg_biome._mcl_grass_palette_index then
node.param2 = reg_biome._mcl_grass_palette_index
minetest.set_node(pos, node)
end
end
end,
})
minetest.register_lbm({
label = "Fix foliage palette indexes", -- This LBM fixes any incorrect foliage palette indexes
name = "mcl_mapgen_core:fix_foliage_palette_indexes",
nodenames = {"group:foliage_palette", "group:foliage_palette_wallmounted"},
run_at_every_load = true,
action = function(pos, node)
if mg_name ~= "v6" and mg_name ~= "singlenode" then
local biome_data = minetest.get_biome_data(pos)
local biome = biome_data.biome
local biome_name = minetest.get_biome_name(biome)
local reg_biome = minetest.registered_biomes[biome_name]
if node.param2 ~= reg_biome._mcl_foliage_palette_index and node.name ~= "mcl_core:vine" then
node.param2 = reg_biome._mcl_foliage_palette_index
minetest.set_node(pos, node)
elseif node.name == "mcl_core:vine" then
local biome_param2 = reg_biome._mcl_foliage_palette_index
local rotation_param2 = node.param2
local final_param2 = (biome_param2 * 8) + rotation_param2
if node.param2 ~= final_param2 and rotation_param2 < 6 then
node.param2 = final_param2
minetest.set_node(pos, node)
end
end
end
end,
})
minetest.register_abm({
label = "Fix foliage palette indexes missed", -- This ABM fixes any incorrect foliage palette indexes which were missed. Likely to be any foliage from a player sapling.
name = "mcl_mapgen_core:fix_foliage_palette_indexes missed",
nodenames = {"group:foliage_palette", "group:foliage_palette_wallmounted"},
neighbors = {"group:foliage_palette", "group:foliage_palette_wallmounted"},
interval = 60,
chance = 1,
action = function(pos, node)
if mg_name ~= "v6" and mg_name ~= "singlenode" then
local biome_data = minetest.get_biome_data(pos)
local biome = biome_data.biome
local biome_name = minetest.get_biome_name(biome)
local reg_biome = minetest.registered_biomes[biome_name]
if node.param2 ~= reg_biome._mcl_foliage_palette_index and node.name ~= "mcl_core:vine" then
node.param2 = reg_biome._mcl_foliage_palette_index
minetest.set_node(pos, node)
elseif node.name == "mcl_core:vine" then
local biome_param2 = reg_biome._mcl_foliage_palette_index
local rotation_param2 = node.param2
local final_param2 = (biome_param2 * 8) + rotation_param2
if node.param2 ~= final_param2 and rotation_param2 < 6 then
node.param2 = final_param2
minetest.set_node(pos, node)
end
end
end
end,
})