diff --git a/dungeon.lua b/dungeon.lua new file mode 100644 index 0000000..0d1ef24 --- /dev/null +++ b/dungeon.lua @@ -0,0 +1,19 @@ + +minetest.set_gen_notify("dungeon") + +minetest.register_on_generated(function(minp, maxp, blockseed) + + local notif = minetest.get_mapgen_object("gennotify") + + if not notif then return end + + local locations = notif.dungeon + + if not locations then return end + + for i, location in ipairs(locations) do + if math.random(3) == 1 then + minetest.place_node(location, { name = "loot:loot_node" }) + end + end +end) diff --git a/init.lua b/init.lua index aceb938..8be4354 100644 --- a/init.lua +++ b/init.lua @@ -67,7 +67,11 @@ end loot.modpath = modpath local vaults = minetest.setting_getbool("loot_vaults") - -if vaults then dofile(modpath .. "loot_vault.lua") end +local no_d_loot = minetest.setting_getbool("no_dungeon_loot") dofile(modpath .. "default_loot.lua") + +dofile(modpath .. "loot_node.lua") +if vaults then dofile(modpath .. "loot_vault.lua") end +if not no_d_loot then dofile(modpath .. "dungeon.lua") end + diff --git a/loot_node.lua b/loot_node.lua new file mode 100644 index 0000000..6edeffe --- /dev/null +++ b/loot_node.lua @@ -0,0 +1,33 @@ + +-- Node that turns into a chest containing some loot +minetest.register_node("loot:loot_node", + { drawtype = "airlike", + pointable = false, + walkable = false, + diggable = false, +}) + + +minetest.register_abm({ + nodenames = {"loot:loot_node"}, + interval = 1, + chance = 1, + action = function(pos) + minetest.remove_node(pos) + minetest.place_node(pos, {name = "default:chest"}) + local inv = minetest.get_meta(pos):get_inventory() + + local valuable_count = math.random(1,3) + local generic_count = math.random(0,10) + + local valuables = loot.generate_loot("valuable", valuable_count) + local loots = loot.generate_loot("generic", generic_count) + + for i, v in ipairs(valuables) do + table.insert(loots,v) + end + + inv:set_list("main", loots) + end, +}) + diff --git a/loot_vault.lua b/loot_vault.lua index c6fe16c..08f9c40 100644 --- a/loot_vault.lua +++ b/loot_vault.lua @@ -1,39 +1,5 @@ -- Creates loot vaults - --- Node that turns into a chest containing some loot -minetest.register_node("loot:loot_node", - { drawtype = "airlike", - pointable = false, - walkable = false, - diggable = false, -}) - - -minetest.register_abm({ - nodenames = {"loot:loot_node"}, - interval = 1, - chance = 1, - action = function(pos) - minetest.remove_node(pos) - minetest.place_node(pos, {name = "default:chest"}) - local inv = minetest.get_meta(pos):get_inventory() - - local valuable_count = math.random(1,3) - local generic_count = math.random(0,10) - - local valuables = loot.generate_loot("valuable", valuable_count) - local loots = loot.generate_loot("generic", generic_count) - - for i, v in ipairs(valuables) do - table.insert(loots,v) - end - - inv:set_list("main", loots) - end, -}) - - local mts = loot.modpath .. "loot_vault.mts" minetest.register_on_generated(function(minp, maxp, seed) @@ -63,22 +29,3 @@ minetest.register_on_generated(function(minp, maxp, seed) true) end) - -minetest.set_gen_notify("dungeon") - -minetest.register_on_generated(function(minp, maxp, blockseed) - - local notif = minetest.get_mapgen_object("gennotify") - - if not notif then return end - - local locations = notif.dungeon - - if not locations then return end - - for i, location in ipairs(locations) do - if math.random(3) == 1 then - minetest.place_node(location, { name = "loot:loot_node" }) - end - end -end)