diff --git a/multi_map_core/core.lua b/multi_map_core/core.lua index a22bb17..57c9889 100644 --- a/multi_map_core/core.lua +++ b/multi_map_core/core.lua @@ -4,13 +4,14 @@ multi_map.layers_start_chunk = 0 -- Y level where to start generating layers, in multi_map.layer_height_chunks = 32 -- Height of each layer, in chunks -- Either MT engine defaults or derived from above values, to be used for more readable calculations -multi_map.layer_height = multi_map.layer_height_chunks * 80 -multi_map.layers_start = multi_map.layers_start_chunk * 80 +multi_map.layer_height = nil +multi_map.half_layer_height = nil +multi_map.layers_start = nil +multi_map.current_layer = nil + multi_map.map_height = 61840 multi_map.map_min = -30912 multi_map.map_max = 30927 -multi_map.half_layer_height = multi_map.layer_height / 2 -multi_map.current_layer = nil -- Can be overridden with someone's own values multi_map.bedrock = "multi_map_core:bedrock" -- Node to use to fill the bottom of a layer @@ -84,6 +85,10 @@ function multi_map.get_offset_y(y, current_layer) l = multi_map.current_layer end + if not l then + return y + end + local center_point = multi_map.map_min + multi_map.layers_start + (l * multi_map.layer_height) + multi_map.half_layer_height if center_point > 0 and y > 0 then @@ -301,7 +306,7 @@ end function multi_map.get_layer_name(layer) if multi_map.layer_names[layer] then return multi_map.layer_names[layer] - elseif not multi_map.generators[layer] then + elseif multi_map.fallback_generator then return multi_map.fallback_generator.name end end @@ -356,17 +361,26 @@ multi_map.node = setmetatable({}, { -- Simple init, does a sanity check of the settings and sets the mapgen to singlenode minetest.register_on_mapgen_init(function(mapgen_params) - if multi_map.layers_start + (multi_map.number_of_layers * multi_map.layer_height) > multi_map.map_height then - minetest.log("error", "[multi_map] Number of layers for the given layer height exceeds map height!") - end minetest.set_mapgen_params({mgname="singlenode"}) end) local firstrun = true +function multi_map.initialized() + return not firstrun +end + -- Here all the magic (or should I say mess...) happens! minetest.register_on_generated(function(minp, maxp) if firstrun then + multi_map.layer_height = multi_map.layer_height_chunks * 80 + multi_map.layers_start = multi_map.layers_start_chunk * 80 + multi_map.half_layer_height = multi_map.layer_height / 2 + + if multi_map.layers_start + (multi_map.number_of_layers * multi_map.layer_height) > multi_map.map_height then + minetest.log("error", "[multi_map] Number of layers for the given layer height exceeds map height!") + end + minetest.log("action", "[multi_map]") minetest.log("action", "[multi_map] First on_generated call started, module state:") minetest.log("action", "[multi_map]") @@ -377,7 +391,7 @@ minetest.register_on_generated(function(minp, maxp) multi_map.set_current_layer(minp.y) local sidelen = maxp.x - minp.x + 1 - if multi_map.current_layer >= multi_map.number_of_layers then + if not multi_map.current_layer or multi_map.current_layer >= multi_map.number_of_layers then return end diff --git a/multi_map_core/debug.lua b/multi_map_core/debug.lua index 1aa8090..118cc50 100644 --- a/multi_map_core/debug.lua +++ b/multi_map_core/debug.lua @@ -5,6 +5,7 @@ function multi_map.log_state() minetest.log("action", "[multi_map] - Number of layers: "..multi_map.number_of_layers) minetest.log("action", "[multi_map] - Layers start at: "..(multi_map.map_min + multi_map.layers_start)) minetest.log("action", "[multi_map] - Layer height: "..multi_map.layer_height) + minetest.log("action", "[multi_map] - HUD enabled: "..tostring(multi_map.hud.enabled)) minetest.log("action", "[multi_map]") minetest.log("action", "[multi_map] Registered generators") diff --git a/multi_map_core/hud.lua b/multi_map_core/hud.lua index 68ecbab..ea7d20e 100644 --- a/multi_map_core/hud.lua +++ b/multi_map_core/hud.lua @@ -27,7 +27,7 @@ minetest.register_on_leaveplayer(function(player) end) function multi_map.update_hud(player) - if not multi_map.hud.enabled then + if not multi_map.hud.enabled or not multi_map.initialized() then return end @@ -38,7 +38,7 @@ function multi_map.update_hud(player) local hud_text = "" - if multi_map.hud.display_layer or multi_map.hud.display_layer_name then + if layer and (multi_map.hud.display_layer or multi_map.hud.display_layer_name) then hud_text = hud_text..multi_map.hud.layer_label if multi_map.hud.display_layer then diff --git a/multi_map_generators/init.lua b/multi_map_generators/init.lua index 257cfd4..e5a3319 100644 --- a/multi_map_generators/init.lua +++ b/multi_map_generators/init.lua @@ -3,12 +3,20 @@ local multi_map_generators_path = minetest.get_modpath("multi_map_generators") dofile(multi_map_generators_path.."/mmgen_levels.lua") --dofile(multi_map_generators_path.."/mmgen_lvm_example.lua") 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("Default Simple", mmgen_simple.generate) -multi_map.register_generator(9, mmgen_simple.generate, "default:sandstone") -multi_map.set_layer_name(9, "Desert") -multi_map.register_generator(10, mmgen_levels.generate) -multi_map.register_generator(11, mmgen_testauri.generate) -multi_map.register_generator(12, mmgen_testauri.generate) -multi_map.register_generator(13, mmgen_levels.generate) +--multi_map.register_fallback_generator("Default Simple", mmgen_simple.generate) +--multi_map.register_generator(9, mmgen_simple.generate, "default:sandstone") +--multi_map.set_layer_name(9, "Desert") +--multi_map.register_generator(10, mmgen_levels.generate) +--multi_map.register_generator(11, mmgen_testauri.generate) +--multi_map.register_generator(12, mmgen_testauri.generate) +--multi_map.register_generator(13, mmgen_levels.generate) + +multi_map.number_of_layers = 38 +multi_map.layers_start_chunk = 0 +multi_map.layer_height_chunks = 20 + +multi_map.register_fallback_generator("Default Levels", mmgen_levels.generate) +multi_map.register_generator(19, mmgen_levels.generate) +multi_map.set_layer_name(19, "Central Layer")