mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-22 10:31:06 +01:00
fixing registration of node functions
"#registered_generators" was attempting to count a non-array table and was always returning 0. So every node function registered was named "mod_1" and overwrote each other in that index. also, "nodes" wasn't counting node_functions, it was counting lvm_functions.
This commit is contained in:
parent
77cb2277cd
commit
1a09b5c132
1 changed files with 5 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
mcl_mapgen_core = {}
|
mcl_mapgen_core = {}
|
||||||
local registered_generators = {}
|
local registered_generators = {}
|
||||||
|
local registered_generators_count = 0
|
||||||
|
|
||||||
local lvm, nodes, param2 = 0, 0, 0
|
local lvm, nodes, param2 = 0, 0, 0
|
||||||
local lvm_buffer = {}
|
local lvm_buffer = {}
|
||||||
|
@ -1866,7 +1867,7 @@ minetest.register_on_generated(function(minp, maxp, blockseed)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function minetest.register_on_generated(node_function)
|
function minetest.register_on_generated(node_function)
|
||||||
mcl_mapgen_core.register_generator("mod_"..tostring(#registered_generators+1), nil, node_function)
|
mcl_mapgen_core.register_generator("mod_"..minetest.get_current_modname().."_"..tostring(registered_generators_count+1), nil, node_function)
|
||||||
end
|
end
|
||||||
|
|
||||||
function mcl_mapgen_core.register_generator(id, lvm_function, node_function, priority, needs_param2)
|
function mcl_mapgen_core.register_generator(id, lvm_function, node_function, priority, needs_param2)
|
||||||
|
@ -1875,7 +1876,7 @@ function mcl_mapgen_core.register_generator(id, lvm_function, node_function, pri
|
||||||
local priority = priority or 5000
|
local priority = priority or 5000
|
||||||
|
|
||||||
if lvm_function then lvm = lvm + 1 end
|
if lvm_function then lvm = lvm + 1 end
|
||||||
if lvm_function then nodes = nodes + 1 end
|
if node_function then nodes = nodes + 1 end
|
||||||
if needs_param2 then param2 = param2 + 1 end
|
if needs_param2 then param2 = param2 + 1 end
|
||||||
|
|
||||||
local new_record = {
|
local new_record = {
|
||||||
|
@ -1886,6 +1887,7 @@ function mcl_mapgen_core.register_generator(id, lvm_function, node_function, pri
|
||||||
}
|
}
|
||||||
|
|
||||||
registered_generators[id] = new_record
|
registered_generators[id] = new_record
|
||||||
|
registered_generators_count = registered_generators_count + 1
|
||||||
table.sort(registered_generators, function(a, b)
|
table.sort(registered_generators, function(a, b)
|
||||||
return (a.i < b.i) or ((a.i == b.i) and a.vf and (b.vf == nil))
|
return (a.i < b.i) or ((a.i == b.i) and a.vf and (b.vf == nil))
|
||||||
end)
|
end)
|
||||||
|
@ -1895,6 +1897,7 @@ function mcl_mapgen_core.unregister_generator(id)
|
||||||
if not registered_generators[id] then return end
|
if not registered_generators[id] then return end
|
||||||
local rec = registered_generators[id]
|
local rec = registered_generators[id]
|
||||||
registered_generators[id] = nil
|
registered_generators[id] = nil
|
||||||
|
registered_generators_count = registered_generators_count - 1
|
||||||
if rec.vf then lvm = lvm - 1 end
|
if rec.vf then lvm = lvm - 1 end
|
||||||
if rec.nf then nodes = nodes - 1 end
|
if rec.nf then nodes = nodes - 1 end
|
||||||
if rec.needs_param2 then param2 = param2 - 1 end
|
if rec.needs_param2 then param2 = param2 - 1 end
|
||||||
|
|
Loading…
Reference in a new issue