-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MapGen: extend
minetest
with .register_on_dungeon_generated()
. Re…
- Loading branch information
Showing
3 changed files
with
43 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
|
||
-- As for now, this mod used only for translations of builtin functionality. | ||
-- Translations need to be removed after it appears in MT (#1187). | ||
local mod_path = minetest.get_modpath(minetest.get_current_modname()) | ||
local require = function(name) return dofile(mod_path .. "/src/" .. name:gsub("%.", "/") .. ".lua") end | ||
|
||
require("mapgen") | ||
|
||
-- Translations (`./locale/__builtin.ru.tr`) need to be removed after it appears in MT (#1187). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
|
||
local on_generated_is_registered = false | ||
local on_dungeon_generated_handlers = {} | ||
|
||
--- @param callback fun(minp:Position, maxp:Position, data:table, area:VoxelArea, room_centers:Position[]) | ||
minetest.register_on_dungeon_generated = function(callback) | ||
table.insert(on_dungeon_generated_handlers, callback) | ||
|
||
if on_generated_is_registered then | ||
return | ||
end | ||
|
||
minetest.set_gen_notify("dungeon") | ||
minetest.register_on_generated(function(minp, maxp, seed) | ||
local notify = minetest.get_mapgen_object("gennotify") | ||
if not notify or not notify.dungeon then | ||
return | ||
end | ||
|
||
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip") | ||
local area = VoxelArea:new({ MinEdge = emin, MaxEdge = emax }) | ||
local data = vm:get_data() | ||
|
||
for _, on_dungeon_generated_handler in pairs(on_dungeon_generated_handlers) do | ||
on_dungeon_generated_handler(minp, maxp, data, area, notify.dungeon) | ||
end | ||
|
||
vm:set_data(data) | ||
vm:calc_lighting() | ||
vm:write_to_map() | ||
end) | ||
on_generated_is_registered = true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters