From be967e44b48e00801df12d2f3c84f81bff879751 Mon Sep 17 00:00:00 2001 From: Beha Date: Sun, 8 Jan 2017 19:23:47 -0500 Subject: [PATCH] Initial Commit, with ruined desert towers. --- LICENSE.md | 28 +++++++ README.md | 3 + defaults.lua | 0 depends.txt | 2 + dungeon.lua | 30 +++++++ init.lua | 127 ++++++++++++++++++++++++++++++ schematics/ruin_desert_sand_1.mts | Bin 0 -> 358 bytes structures.lua | 66 ++++++++++++++++ 8 files changed, 256 insertions(+) create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 defaults.lua create mode 100644 depends.txt create mode 100644 dungeon.lua create mode 100644 init.lua create mode 100644 schematics/ruin_desert_sand_1.mts create mode 100644 structures.lua diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..1d0adbc --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,28 @@ +License for Code +---------------- + +Copyright (c) 2016-2017 Beha + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + +License for Textures, Models and Sounds +--------------------------------------- + +CC BY-SA 4.0. Created by Beha. diff --git a/README.md b/README.md new file mode 100644 index 0000000..3073fc0 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Ancient World + +This mod adds random decrepit structures across the world. diff --git a/defaults.lua b/defaults.lua new file mode 100644 index 0000000..e69de29 diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..bc8765f --- /dev/null +++ b/depends.txt @@ -0,0 +1,2 @@ +default +kingdoms_meta? diff --git a/dungeon.lua b/dungeon.lua new file mode 100644 index 0000000..3a5bdd9 --- /dev/null +++ b/dungeon.lua @@ -0,0 +1,30 @@ +local function place_item(tab) + local items = ancient_world.probability_list(ancient_world.registered_items) + local pos = tab[math.random(1, (#tab or 4))] + pos.y = pos.y - 1 + local n = core.get_node_or_nil(pos) + if n and n.name ~= "air" then + pos.y = pos.y + 1 + local name = items[math.random(1, #items)] + --Failsafe + if minetest.registered_nodes[name] then + core.set_node(pos, {name = name}) + else + kingdoms.log("warning", "Tried to place unregistered node "..name.." in dungeon.") + end + end +end + +core.set_gen_notify("dungeon") +core.register_on_generated(function(minp, maxp, blockseed) + local ntf = core.get_mapgen_object("gennotify") + if ntf and ntf.dungeon and #ntf.dungeon > 0 then + core.after(3, place_item, table.copy(ntf.dungeon)) + if math.random(1, 100) < 25 then + core.after(3, place_item, table.copy(ntf.dungeon)) + end + if math.random(1, 100) < 25 then + core.after(3, place_item, table.copy(ntf.dungeon)) + end + end +end) diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..64a7228 --- /dev/null +++ b/init.lua @@ -0,0 +1,127 @@ +-- Function to execute more files. +local modpath = minetest.get_modpath("ancient_world") +local function domodfile(f) + dofile(modpath .. '/' .. f) +end + +-- Mod namespace. +ancient_world = { + config = {}, + log = function() end, +} + +if rawget(_G, kingdoms) then + ancient_world.config = kingdoms.config_table("ancient_world") + ancient_world.log = kingdoms.log_function("ancient_world") +end + +function ancient_world.probability_list(t) + local ret = {} + for k,v in pairs(t) do + for i=1,v do + table.insert(ret, k) + end + end + return ret +end + +ancient_world.registered_items = {} +function ancient_world.register_item(name, probability) + ancient_world.registered_items[name] = math.ceil((probability or 3) * 100) +end + +local defaultitems = { + ["default:mese"] = 1, + ["default:diamondblock"] = 1, + + ["default:goldblock"] = 2, + ["default:copperblock"] = 2, + + ["default:bronzeblock"] = 3, + ["default:steelblock"] = 3, + + ["default:obsidian"] = 3, + ["default:coalblock"] = 3, +} + +for k,v in pairs(defaultitems) do + ancient_world.register_item(k, v) +end + +ancient_world.registry = {} +function ancient_world.register(name, def) + local d = { + offset = {x=0, y=0, z=0}, + limit_y = {max = 31000, min = -31000}, + } + for k,v in pairs(def) do + d[k] = v + end + ancient_world.registry[name] = d +end + +domodfile("defaults.lua") +domodfile("dungeon.lua") +domodfile("structures.lua") + +if rawget(_G, kingdoms) then + ancient_world.log("action", "Loaded.") + kingdoms.mod_ready("ancient_world") +end + +minetest.register_on_generated(function(minp, maxp, seed) + local items = ancient_world.probability_list(ancient_world.registered_items) + for name,def in pairs(ancient_world.registry) do + if math.random(1, 10000) <= (def.chance * 100) then + local possible = {} + if def.type == "decoration" then + possible = minetest.find_nodes_in_area_under_air( + {x=minp.x, y=math.max(minp.y, def.limit_y.min), z=minp.z}, + {x=maxp.x, y=math.min(maxp.y, def.limit_y.max), z=maxp.z}, + def.on) + end + if #possible > 0 then + local r = table.copy(def.replacements or {}) + if def.random_replacements then + for k,v in pairs(def.random_replacements) do + if v == true then + r[k] = items[math.random(1, #items)] + else + r[k] = v[math.random(1, #v)] + end + end + end + local pos = vector.add(possible[math.random(1, #possible)], def.offset) + minetest.place_schematic(pos, def.schematic, "random") + + -- Very Hacky Solution due to minetest.place_schematic carrying the replacements parameter between calls. + -- This parses the schematic file manually, then replaces appropriate nodes between all possible positions. + local schematic_size = {} + local sf = io.open(def.schematic, "rb") + sf:read(6) + schematic_size.x = string.byte(sf:read(1)) * 0xFF + string.byte(sf:read(1)) + schematic_size.y = string.byte(sf:read(1)) * 0xFF + string.byte(sf:read(1)) + schematic_size.z = string.byte(sf:read(1)) * 0xFF + string.byte(sf:read(1)) + sf:close() + for k,v in pairs(r) do + local positions = minetest.find_nodes_in_area(vector.subtract(pos, schematic_size), vector.add(maxp, schematic_size), {k}) + if positions then + for _,p in ipairs(positions) do + minetest.set_node(p, {name=v}) + end + end + end + -- End Very Hacky Solution + end + end + end +end) + +for n=1,10 do + minetest.register_node("ancient_world:placeholder_"..tostring(n), { + description = "Placeholder "..tostring(n), + tiles = {"default_cloud.png"}, + sounds = default.node_sound_stone_defaults(), + groups = {cracky = 1, not_in_creative_inventory = 1}, + }) +end diff --git a/schematics/ruin_desert_sand_1.mts b/schematics/ruin_desert_sand_1.mts new file mode 100644 index 0000000000000000000000000000000000000000..205a031eb27ef70e8af35910512a5d9f814a75d8 GIT binary patch literal 358 zcmeYb3HD`RVPIttWMHdD2Mp{C!YQd~iKRIuRw=2)sYNC6#ff<-3}P@r5U;o-KQA?@ zC^I>mfjKd=h=ISNATcks*eWTpC_XJGv4lYcraC7vB_*{ezPKbcHHSf}xCE%W*s3@u zF$ruck~z|edC8fnc_s1X`9(P?Rs}hU$*CFnIUvo36?5KBxhZs5fx}gB%l^CZ{%gXn z>CAl#~KGtl3ljKElE%#qhgtRN3y5T{bU@(pQKX zKkOEaeH?ovD=U7@dcjTAAm2FMOKc`JNWwGv^m8Vwz!iQ5r zMEcgLJiUGK)zW;i|KV>HkD7n`^yhWE=}RBEc@