From fc1a6d754e18456b27313fcfc23084216cae06dc Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Sun, 12 Feb 2023 13:06:08 -0700 Subject: [PATCH] add mapgen --- collectible_lore/items.lua | 21 ++++++++++++++------- collectible_lore/locale/template.txt | 10 ++++++++++ df_caverns/init.lua | 3 ++- df_caverns/lorebooks.lua | 20 ++++++++++++++++++++ df_caverns/mod.conf | 2 +- 5 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 df_caverns/lorebooks.lua diff --git a/collectible_lore/items.lua b/collectible_lore/items.lua index 796496a..63e854e 100644 --- a/collectible_lore/items.lua +++ b/collectible_lore/items.lua @@ -87,6 +87,8 @@ end minetest.register_node("collectible_lore:cairn", { description = S("Cairn"), + _doc_items_longdesc = S("A cairn of rocks constructed by a previous explorer to protect documents and supplies."), + _doc_items_usagehelp = S("The first time you discover a cairn like this, it may reveal to you some new record or piece of lore. Afterward it can be used as a public storage location."), drawtype = "nodebox", tiles = {df_dependencies.texture_cobble, df_dependencies.texture_cobble, df_dependencies.texture_cobble .. "^(collectible_lore_cairn_marker.png^[opacity:100)"}, is_ground_content = true, @@ -138,8 +140,8 @@ minetest.register_node("collectible_lore:cairn", { local inv = meta:get_inventory() inv:set_size("main", 8*4) - local nearby = cairn_area:get_areas_in_area(vector.subtract(pos, cairn_spacing/2), vector.add(pos, cairn_spacing/2)) - if next(nearby) then + local nearby = collectible_lore.are_cairns_close_to_pos(pos) + if nearby then minetest.log("error", "Cairn placed too close to other cairns. Placed at: " .. minetest.pos_to_string(pos)) for _,data in pairs(nearby) do minetest.log("error", "nearby: " .. minetest.pos_to_string(data.min)) @@ -173,13 +175,16 @@ collectible_lore.get_nearby_cairns = function(pos, spacing) return nil end -collectible_lore.place_cairn = function(pos) +collectible_lore.are_cairns_close_to_pos = function(pos) local nearby = collectible_lore.get_nearby_cairns(pos, cairn_spacing) - if nearby then return end + if nearby then return nearby end + return false +end + +collectible_lore.place_cairn = function(pos) + if collectible_lore.are_cairns_close_to_pos(pos) then return end minetest.set_node(pos, {name="collectible_lore:cairn"}) - local def = minetest.registered_nodes["collectible_lore:cairn"] - def.on_construct(pos) - --minetest.set_node({x=pos.x, y=pos.y+1, z=pos.z}, {name=torch_node_name}) + --minetest.debug("placed " .. minetest.pos_to_string(pos)) end local player_state = {} @@ -230,6 +235,8 @@ end minetest.register_craftitem("collectible_lore:satchel", { description = S("Collectibles Satchel"), + _doc_items_longdesc = S("A satchel containing various documents you've recovered in your travels."), + _doc_items_usagehelp = S("The documents and lore you've unlocked are not tied to a specific satchel, any satchel will let you view your personal collection."), inventory_image = "collectible_lore_satchel.png", stack_max = 99, on_use = function(itemstack, user, pointed_thing) diff --git a/collectible_lore/locale/template.txt b/collectible_lore/locale/template.txt index 07c236c..5371f45 100644 --- a/collectible_lore/locale/template.txt +++ b/collectible_lore/locale/template.txt @@ -13,10 +13,20 @@ Administrative control of collectibles= ### items.lua ### = + +A cairn of rocks constructed by a previous explorer to protect documents and supplies.= + +A satchel containing various documents you've recovered in your travels.= + Cairn= Collected: @1/@2= Collectibles Satchel= Exit= + +The documents and lore you've unlocked are not tied to a specific satchel, any satchel will let you view your personal collection.= + +The first time you discover a cairn like this, it may reveal to you some new record or piece of lore. Afterward it can be used as a public storage location.= + View= You've already collected the lore hidden in this cairn.= You've found a collectible item of lore titled:@n@1= diff --git a/df_caverns/init.lua b/df_caverns/init.lua index ceeee01..df260a4 100644 --- a/df_caverns/init.lua +++ b/df_caverns/init.lua @@ -18,4 +18,5 @@ dofile(modpath.."/lava_sea.lua") dofile(modpath.."/underworld.lua") dofile(modpath.."/primordial.lua") dofile(modpath.."/dungeon_loot.lua") -dofile(modpath.."/growth_restrictions.lua") \ No newline at end of file +dofile(modpath.."/growth_restrictions.lua") +dofile(modpath.."/lorebooks.lua") \ No newline at end of file diff --git a/df_caverns/lorebooks.lua b/df_caverns/lorebooks.lua new file mode 100644 index 0000000..93454d8 --- /dev/null +++ b/df_caverns/lorebooks.lua @@ -0,0 +1,20 @@ +if not minetest.get_modpath("df_lorebooks") then return end + +local foundations = {"group:stone", "group:dirt", "group:soil"} + +minetest.register_on_generated(function(minp, maxp, blockseed) + if maxp.y > 0 or maxp.y < df_caverns.config.primordial_min then return end + + -- using after so that all other mapgen should be finished fiddling with stuff by the time this runs + minetest.after(1, function(minp, maxp) + local middle = vector.divide(vector.add(minp, maxp), 2) + if collectible_lore.are_cairns_close_to_pos(middle) then return end -- quick and dirty check to discard mapblocks close to other cairns + local possibles = minetest.find_nodes_in_area_under_air(minp, maxp, foundations) + if next(possibles) then + local target = possibles[math.random(#possibles)] + target.y=target.y+1 + collectible_lore.place_cairn(target) + end + end, minp, maxp) + +end) \ No newline at end of file diff --git a/df_caverns/mod.conf b/df_caverns/mod.conf index 4a9ab59..3f1c1f4 100644 --- a/df_caverns/mod.conf +++ b/df_caverns/mod.conf @@ -1,4 +1,4 @@ name = df_caverns description = Adds vast underground caverns in the style of Dwarf Fortress, complete with underground flora in diverse biomes. Also adds stalactite/stalagmite decorations in the smaller tunnels. depends = df_dependencies, subterrane, df_trees, df_mapitems, -optional_depends = df_farming, ice_sprites, oil, df_underworld_items, magma_conduits, bones_loot, named_waypoints, name_generator, fireflies, chasms, big_webs, mcl_flowers, mine_gas, bubblesponge \ No newline at end of file +optional_depends = df_farming, ice_sprites, oil, df_underworld_items, magma_conduits, bones_loot, named_waypoints, name_generator, fireflies, chasms, big_webs, mcl_flowers, mine_gas, bubblesponge, df_lorebooks \ No newline at end of file