Initial Commit, with ruined desert towers.

master
Beha 2017-01-08 19:23:47 -05:00
commit be967e44b4
8 changed files with 256 additions and 0 deletions

28
LICENSE.md Normal file
View File

@ -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.

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# Ancient World
This mod adds random decrepit structures across the world.

0
defaults.lua Normal file
View File

2
depends.txt Normal file
View File

@ -0,0 +1,2 @@
default
kingdoms_meta?

30
dungeon.lua Normal file
View File

@ -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)

127
init.lua Normal file
View File

@ -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

Binary file not shown.

66
structures.lua Normal file
View File

@ -0,0 +1,66 @@
-- Old guardtower/outpost upon desert sand.
ancient_world.register("ancient_world:ruin_desert_sand_1:desert_sand", {
schematic = minetest.get_modpath("ancient_world") .. "/schematics/ruin_desert_sand_1.mts",
chance = 0.1,
type = "decoration",
offset = {
x = 0,
y = -8,
z = 0,
},
limit_y = {
max = 31000,
min = -8,
},
on = {"default:desert_sand"},
random_replacements = {
["ancient_world:placeholder_1"] = true,
},
})
-- Normal sand.
ancient_world.register("ancient_world:ruin_desert_sand_1:sand", {
schematic = minetest.get_modpath("ancient_world") .. "/schematics/ruin_desert_sand_1.mts",
chance = 0.1,
type = "decoration",
offset = {
x = 0,
y = -8,
z = 0,
},
limit_y = {
max = 31000,
min = -8,
},
on = {"default:sand"},
replacements = {
["default:desert_sand"] = "default:sand",
},
random_replacements = {
["ancient_world:placeholder_1"] = true,
},
})
-- Silver sand.
ancient_world.register("ancient_world:ruin_desert_sand_1:silver_sand", {
schematic = minetest.get_modpath("ancient_world") .. "/schematics/ruin_desert_sand_1.mts",
chance = 0.1,
type = "decoration",
offset = {
x = 0,
y = -8,
z = 0,
},
limit_y = {
max = 31000,
min = -8,
},
on = {"default:silver_sand"},
replacements = {
["default:desert_sand"] = "default:silver_sand",
},
random_replacements = {
["ancient_world:placeholder_1"] = true,
},
})