From 331d08b1567cf023695832e4ab593d33720b9290 Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Thu, 6 May 2021 20:28:37 -0600 Subject: [PATCH] make subterrane cross-compatible with minetest_game and mineclone2 --- dependencies.lua | 28 ++++++++++++++++++++++++++++ init.lua | 24 ++++++++++++------------ mod.conf | 3 ++- 3 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 dependencies.lua diff --git a/dependencies.lua b/dependencies.lua new file mode 100644 index 0000000..f5635f6 --- /dev/null +++ b/dependencies.lua @@ -0,0 +1,28 @@ +subterrane.dependencies = {} + +local default_modpath = minetest.get_modpath("default") +local mcl_core_modpath = minetest.get_modpath("mcl_core") + +assert(default_modpath or mcl_core_modpath, "[subterrane] This mod requires either minetest_game (default) or Mineclone2 (mcl_core) to be installed") + +if default_modpath then + +subterrane.dependencies.stone = "default:stone" +subterrane.dependencies.clay = "default:clay" +subterrane.dependencies.desert_stone = "default:desert_stone" +subterrane.dependencies.sandstone = "default:sandstone" +subterrane.dependencies.water = "default:water_source" +subterrane.dependencies.obsidian = "default:obsidian" + +elseif mcl_core_modpath then + +subterrane.dependencies.stone = "mcl_core:stone" +subterrane.dependencies.clay = "mcl_core:clay" +subterrane.dependencies.desert_stone = "mcl_core:redsandstone" +subterrane.dependencies.sandstone = "mcl_core:sandstone" +subterrane.dependencies.water = "mcl_core:water_source" +subterrane.dependencies.obsidian = "mcl_core:obsidian" + +end + +minetest.after(0, function() subterrane.dependencies = nil end) -- ensure these are only used during initialization, to avoid polluting the global namespace with irrelevancies \ No newline at end of file diff --git a/init.lua b/init.lua index d4ca6ff..b96e81e 100644 --- a/init.lua +++ b/init.lua @@ -4,15 +4,21 @@ -- Depends default -- License: code MIT -local c_stone = minetest.get_content_id("default:stone") -local c_clay = minetest.get_content_id("default:clay") -local c_desert_stone = minetest.get_content_id("default:desert_stone") -local c_sandstone = minetest.get_content_id("default:sandstone") +subterrane = {} --create a container for functions and constants + +local modpath = minetest.get_modpath(minetest.get_current_modname()) + +dofile(modpath.."/dependencies.lua") + +local c_stone = minetest.get_content_id(subterrane.dependencies.stone) +local c_clay = minetest.get_content_id(subterrane.dependencies.clay) +local c_desert_stone = minetest.get_content_id(subterrane.dependencies.desert_stone) +local c_sandstone = minetest.get_content_id(subterrane.dependencies.sandstone) local c_air = minetest.get_content_id("air") -local c_water = minetest.get_content_id("default:water_source") +local c_water = minetest.get_content_id(subterrane.dependencies.water) -local c_obsidian = minetest.get_content_id("default:obsidian") +local c_obsidian = minetest.get_content_id(subterrane.dependencies.obsidian) local c_cavern_air = c_air local c_warren_air = c_air @@ -28,14 +34,8 @@ local c_lava_set -- will be populated with a set of nodes that count as lava -- Performance instrumentation local t_start = os.clock() -subterrane = {} --create a container for functions and constants - subterrane.registered_layers = {} ---grab a shorthand for the filepath of the mod -local modpath = minetest.get_modpath(minetest.get_current_modname()) - ---load companion lua files dofile(modpath.."/defaults.lua") dofile(modpath.."/features.lua") -- some generic cave features useful for a variety of mapgens dofile(modpath.."/player_spawn.lua") -- Function for spawning a player in a giant cavern diff --git a/mod.conf b/mod.conf index 20ab629..8f3396e 100644 --- a/mod.conf +++ b/mod.conf @@ -1,3 +1,4 @@ name = subterrane description = A mapgen helper mod that facilitates the creation of vast underground caverns -depends = default, mapgen_helper \ No newline at end of file +optional_depends = default, mcl_core +depends = mapgen_helper \ No newline at end of file