Introduced the ability to register a fallback or layer generator with
arguments, updated simple generator to allow switching between different content ids for the terrain generation, i.e. it can now switch between stone and sandstone (the one registered is sandstone, the fallback does not specify arguments during registration so it uses a default, stone).
This commit is contained in:
parent
35d768d79f
commit
2c2cba19ee
|
@ -33,18 +33,39 @@ function multi_map.get_offset_y(y)
|
||||||
return y - center_point
|
return y - center_point
|
||||||
end
|
end
|
||||||
|
|
||||||
function multi_map.register_fallback_generator(generator)
|
function multi_map.register_fallback_generator(...)
|
||||||
multi_map.fallback_generator = generator
|
local arg = {...}
|
||||||
|
local generator
|
||||||
|
local arguments
|
||||||
|
|
||||||
|
if arg[2] then
|
||||||
|
generator = arg[1]
|
||||||
|
arguments = arg[2]
|
||||||
|
else
|
||||||
|
generator = arg[1]
|
||||||
|
end
|
||||||
|
multi_map.fallback_generator = { generator = generator, arguments = arguments }
|
||||||
end
|
end
|
||||||
|
|
||||||
function multi_map.register_generator(...)
|
function multi_map.register_generator(...)
|
||||||
local arg = {...}
|
local arg = {...}
|
||||||
local position
|
local position
|
||||||
local generator
|
local generator
|
||||||
|
local arguments
|
||||||
|
|
||||||
if arg[2] then
|
if arg[3] then
|
||||||
position = arg[1]
|
position = arg[1]
|
||||||
generator = arg[2]
|
generator = arg[2]
|
||||||
|
arguments = arg[3]
|
||||||
|
print(arguments)
|
||||||
|
elseif arg[2] then
|
||||||
|
if type(arg[1]) == "function" then
|
||||||
|
generator = arg[1]
|
||||||
|
arguments = arg[2]
|
||||||
|
else
|
||||||
|
position = arg[1]
|
||||||
|
generator = arg[2]
|
||||||
|
end
|
||||||
else
|
else
|
||||||
generator = arg[1]
|
generator = arg[1]
|
||||||
end
|
end
|
||||||
|
@ -56,7 +77,7 @@ function multi_map.register_generator(...)
|
||||||
t = {}
|
t = {}
|
||||||
multi_map.generators[i] = t
|
multi_map.generators[i] = t
|
||||||
end
|
end
|
||||||
table.insert(t, generator)
|
table.insert(t, { generator = generator, arguments = arguments })
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local t = multi_map.generators[position]
|
local t = multi_map.generators[position]
|
||||||
|
@ -64,7 +85,7 @@ function multi_map.register_generator(...)
|
||||||
t = {}
|
t = {}
|
||||||
multi_map.generators[position] = t
|
multi_map.generators[position] = t
|
||||||
end
|
end
|
||||||
table.insert(t, generator)
|
table.insert(t, { generator = generator, arguments = arguments })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -83,6 +104,7 @@ end
|
||||||
local firstrun = true
|
local firstrun = true
|
||||||
-- Global helpers for mapgens
|
-- Global helpers for mapgens
|
||||||
multi_map.c_stone = nil
|
multi_map.c_stone = nil
|
||||||
|
multi_map.c_sandstone = nil
|
||||||
multi_map.c_air = nil
|
multi_map.c_air = nil
|
||||||
multi_map.c_water = nil
|
multi_map.c_water = nil
|
||||||
multi_map.c_lava = nil
|
multi_map.c_lava = nil
|
||||||
|
@ -98,6 +120,7 @@ end)
|
||||||
minetest.register_on_generated(function(minp, maxp)
|
minetest.register_on_generated(function(minp, maxp)
|
||||||
if firstrun then
|
if firstrun then
|
||||||
multi_map.c_stone = minetest.get_content_id("default:stone")
|
multi_map.c_stone = minetest.get_content_id("default:stone")
|
||||||
|
multi_map.c_sandstone = minetest.get_content_id("default:sandstone")
|
||||||
multi_map.c_air = minetest.get_content_id("air")
|
multi_map.c_air = minetest.get_content_id("air")
|
||||||
multi_map.c_water = minetest.get_content_id("default:water_source")
|
multi_map.c_water = minetest.get_content_id("default:water_source")
|
||||||
multi_map.c_lava = minetest.get_content_id("default:lava_source")
|
multi_map.c_lava = minetest.get_content_id("default:lava_source")
|
||||||
|
@ -145,14 +168,14 @@ minetest.register_on_generated(function(minp, maxp)
|
||||||
local t = multi_map.generators[multi_map.current_layer]
|
local t = multi_map.generators[multi_map.current_layer]
|
||||||
if not t then
|
if not t then
|
||||||
if multi_map.fallback_generator then
|
if multi_map.fallback_generator then
|
||||||
multi_map.fallback_generator(multi_map.current_layer, minp, maxp, offset_minp, offset_maxp)
|
multi_map.fallback_generator.generator(multi_map.current_layer, minp, maxp, offset_minp, offset_maxp, multi_map.fallback_generator.arguments)
|
||||||
else
|
else
|
||||||
minetest.log("error", "Generator for layer "..multi_map.current_layer.." missing and no fallback specified, exiting mapgen!")
|
minetest.log("error", "Generator for layer "..multi_map.current_layer.." missing and no fallback specified, exiting mapgen!")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
for i,f in ipairs(t) do
|
for i,f in ipairs(t) do
|
||||||
f(multi_map.current_layer, minp, maxp, offset_minp, offset_maxp)
|
f.generator(multi_map.current_layer, minp, maxp, offset_minp, offset_maxp, f.arguments)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,6 +6,7 @@ dofile(multi_map_generators_path.."/mmgen_simple.lua")
|
||||||
dofile(multi_map_generators_path.."/mmgen_testauri.lua")
|
dofile(multi_map_generators_path.."/mmgen_testauri.lua")
|
||||||
|
|
||||||
multi_map.register_fallback_generator(mmgen_simple.generate)
|
multi_map.register_fallback_generator(mmgen_simple.generate)
|
||||||
|
multi_map.register_generator(10, mmgen_simple.generate, "default:sandstone")
|
||||||
multi_map.register_generator(11, mmgen_testauri.generate)
|
multi_map.register_generator(11, mmgen_testauri.generate)
|
||||||
multi_map.register_generator(12, mmgen_testauri.generate)
|
multi_map.register_generator(12, mmgen_testauri.generate)
|
||||||
multi_map.register_generator(13, mmgen_testauri.generate)
|
multi_map.register_generator(13, mmgen_testauri.generate)
|
||||||
|
|
|
@ -1,15 +1,24 @@
|
||||||
mmgen_simple = {}
|
mmgen_simple = {}
|
||||||
|
|
||||||
function mmgen_simple.generate(current_layer, minp, maxp, offset_minp, offset_maxp)
|
function mmgen_simple.generate(current_layer, minp, maxp, offset_minp, offset_maxp, content_id)
|
||||||
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
||||||
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
|
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
|
||||||
local vm_data = vm:get_data()
|
local vm_data = vm:get_data()
|
||||||
|
|
||||||
|
local c_ground
|
||||||
|
if content_id then
|
||||||
|
c_ground = minetest.get_content_id(content_id)
|
||||||
|
else
|
||||||
|
c_ground = multi_map.c_stone
|
||||||
|
end
|
||||||
|
|
||||||
if offset_minp.y >= 0 then
|
if offset_minp.y >= 0 then
|
||||||
multi_map.generate_singlenode_chunk(minp, maxp, area, vm_data, multi_map.c_air)
|
multi_map.generate_singlenode_chunk(minp, maxp, area, vm_data, multi_map.c_air)
|
||||||
vm:set_lighting({day=15, night=0})
|
vm:set_lighting({day=15, night=0})
|
||||||
else
|
else
|
||||||
multi_map.generate_singlenode_chunk(minp, maxp, area, vm_data, multi_map.c_stone)
|
multi_map.generate_singlenode_chunk(minp, maxp, area, vm_data, c_ground)
|
||||||
end
|
end
|
||||||
|
|
||||||
vm:set_data(vm_data)
|
vm:set_data(vm_data)
|
||||||
vm:calc_lighting(false)
|
vm:calc_lighting(false)
|
||||||
vm:write_to_map(false)
|
vm:write_to_map(false)
|
||||||
|
|
Loading…
Reference in New Issue