From d82769a68acef93a3daa68f908299e92d837f12f Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 5 Sep 2019 01:14:39 +0200 Subject: [PATCH] Save mapdata in world directory --- DEVELOPERS.md | 7 ++++--- mods/tutorial_mapgen/init.lua | 13 +++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/DEVELOPERS.md b/DEVELOPERS.md index cdfcbad..c66c84d 100644 --- a/DEVELOPERS.md +++ b/DEVELOPERS.md @@ -16,9 +16,8 @@ The tutorial castle is saved in the game itself in schematics and other binary m 6. Edit the map to your likings 7. Grant yourselves the `tutorialmap` privilege 8. Use `/tsave` command to save the map -9. Test your world: Disable the two settings from steps 2 and 3, create a new world and test it -The changes will end up in `mods/tutorial_mapgen/mapdata`. If everything worked, you can now commit the changes, use them in a patch or whatever. +The changes will end up in `/mapdata`. Copy this directory to `/mods/tutorial_mapgen`, overwriting files, if neccessary. If you want to edit item spawn positions, see the details below. @@ -41,7 +40,9 @@ tutorial_debug_edit_item_spawners = true This enables the `/treset` and `/tsave` commands to help editing the schematic. It also forces the Tutorial to only generate the raw castle, not the grasslands. Also, the item spawners become visible. Create a new world in Creative Mode. Now edit the map to your likings using your instant digging power and the creative inventory. You can of course WorldEdit to speed up the process. -If you're finished, grant yourself the `tutorialmap` privilege and use the `/tsave` command. This updates the map files in `mods/tutorial_mapgen/mapdata`. Note that there are limits as for how big the tutorial castle can be. +If you're finished, grant yourself the `tutorialmap` privilege and use the `/tsave` command. This updates the map files in `/mapdata`. Note that there are limits as for how big the tutorial castle can be. + +Copy the contents of this directory to the `tutorial_mapgen` mod under `mapdata` and overwrite files as neccessary. Test your changes by creating a new world. If everything went fine, you can commit your changes now. ### About item spawners To place items in the map, you must use the item spawners, these are simple nodes that spawn items. They have 2 states: active and inactive. diff --git a/mods/tutorial_mapgen/init.lua b/mods/tutorial_mapgen/init.lua index e4c3b83..2669023 100644 --- a/mods/tutorial_mapgen/init.lua +++ b/mods/tutorial_mapgen/init.lua @@ -16,6 +16,7 @@ local c_grass = minetest.get_content_id("default:grass_5") -- Directory where the map data will be stored tutorial.map_directory = minetest.get_modpath("tutorial_mapgen").."/mapdata/" +tutorial.map_save_directory = minetest.get_worldpath().."/mapdata/" local insecure_environment = minetest.request_insecure_environment() @@ -233,9 +234,12 @@ local function load_region(minp, filename, vmanip, rotation, replacements, force end local function save_schematic() + minetest.log("action", "[tutorial_mapgen] Map data save requested") + minetest.chat_send_all("Saving map data, please wait ...") local success = true + minetest.mkdir(tutorial.map_save_directory) for k,sector in pairs(tutorial.map_sector) do - local filename = tutorial.map_directory .. "sector_"..k + local filename = tutorial.map_save_directory .. "sector_"..k local minp = sector local maxp = { x = sector.x + sector.l, @@ -247,6 +251,9 @@ local function save_schematic() success = false end end + if success then + minetest.chat_send_all("Map data saved to: "..tutorial.map_save_directory) + end return success end @@ -305,9 +312,7 @@ if map_editing then description = "Saves the tutorial map", privs = {tutorialmap=true}, func = function(name, param) - if save_schematic() then - minetest.chat_send_player(name, "Tutorial World schematic saved") - else + if not save_schematic() then minetest.chat_send_player(name, "An error occurred while saving Tutorial World schematic") end end,