forked from VoxeLibre/VoxeLibre
Add a LBM to fix grass palette indexes on older worlds
This commit is contained in:
parent
c1cde073c8
commit
3afb42b2f7
|
@ -289,6 +289,27 @@ local function set_palette(minp,maxp,data2,area,biomemap,nodes)
|
||||||
return lvm_used
|
return lvm_used
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function set_palette(minp,maxp,data2,area,biomemap,nodes) -- Like set_palette, but to fix already set palletes.
|
||||||
|
-- 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 then
|
||||||
|
data2[p_pos] = biome._mcl_grass_palette_index
|
||||||
|
lvm_used = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return lvm_used
|
||||||
|
end
|
||||||
|
|
||||||
-- Below the bedrock, generate air/void
|
-- Below the bedrock, generate air/void
|
||||||
local function world_structure(vm, data, data2, emin, emax, area, minp, maxp, blockseed)
|
local function world_structure(vm, data, data2, emin, emax, area, minp, maxp, blockseed)
|
||||||
local biomemap --ymin, ymax
|
local biomemap --ymin, ymax
|
||||||
|
@ -349,8 +370,8 @@ local function block_fixes(vm, data, data2, emin, emax, area, minp, maxp, blocks
|
||||||
local lvm_used = false
|
local lvm_used = false
|
||||||
local pr = PseudoRandom(blockseed)
|
local pr = PseudoRandom(blockseed)
|
||||||
if minp.y <= mcl_vars.mg_overworld_max and maxp.y >= mcl_vars.mg_overworld_min then
|
if minp.y <= mcl_vars.mg_overworld_max and maxp.y >= mcl_vars.mg_overworld_min then
|
||||||
-- Set param2 (=color) of sugar cane and grass
|
-- Set param2 (=color) of nodes that currently use the grass colour palette.
|
||||||
lvm_used = set_palette(minp,maxp,data2,area,biomemap,{"mcl_core:reeds","mcl_core:dirt_with_grass","mcl_core:dirt_with_grass_snow"})
|
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"})
|
||||||
end
|
end
|
||||||
return lvm_used
|
return lvm_used
|
||||||
end
|
end
|
||||||
|
@ -417,3 +438,31 @@ mcl_mapgen_core.register_generator("structures",nil, function(minp, maxp, blocks
|
||||||
end
|
end
|
||||||
return false, false, false
|
return false, false, false
|
||||||
end, 100, true)
|
end, 100, true)
|
||||||
|
|
||||||
|
local DEFAULT_INDEX = 0
|
||||||
|
minetest.register_lbm({
|
||||||
|
label = "Fix 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,
|
||||||
|
action = function(pos, node)
|
||||||
|
local biome_data = minetest.get_biome_data(pos)
|
||||||
|
if biome_data then
|
||||||
|
local biome = biome_data.biome
|
||||||
|
local biome_name = minetest.get_biome_name(biome)
|
||||||
|
local reg_biome = minetest.registered_biomes[biome_name]
|
||||||
|
if reg_biome then
|
||||||
|
node.param2 = reg_biome._mcl_grass_palette_index
|
||||||
|
-- Fall back to default palette index
|
||||||
|
if not node.param2 then
|
||||||
|
node.param2 = DEFAULT_INDEX
|
||||||
|
end
|
||||||
|
minetest.set_node(pos, node)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
node.param2 = DEFAULT_INDEX
|
||||||
|
minetest.set_node(pos, node)
|
||||||
|
return
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in New Issue