add ores
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
[
|
||||||
|
{"struct": "coal_ore0", "rarity": 22000}
|
||||||
|
]
|
||||||
@@ -1,13 +1,32 @@
|
|||||||
function place_structures(x, z, w, d, seed, hmap, chunk_height)
|
BLOCKS_PER_CHUNK = 65536
|
||||||
local placements = {}
|
|
||||||
for i=1,10 do
|
local _, dir = parse_path(__DIR__)
|
||||||
local sx = math.random() * w
|
ores = file.read_combined_list(dir.."/ores.json")
|
||||||
local sz = math.random() * d
|
|
||||||
local sy = math.random() * (chunk_height * 0.5)
|
local function place_ores(placements, x, z, w, d, seed, hmap, chunk_height)
|
||||||
if sy < hmap:at(sx, sz) * chunk_height - 6 then
|
for _, ore in ipairs(ores) do
|
||||||
table.insert(placements, {"coal_ore0", {sx, sy, sz}, math.random()*4})
|
local count = BLOCKS_PER_CHUNK / ore.rarity
|
||||||
|
|
||||||
|
-- average count is less than 1
|
||||||
|
local addchance = math.fmod(count, 1.0)
|
||||||
|
if math.random() < addchance then
|
||||||
|
count = count + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
for i=1,count do
|
||||||
|
local sx = math.random() * w
|
||||||
|
local sz = math.random() * d
|
||||||
|
local sy = math.random() * (chunk_height * 0.5)
|
||||||
|
if sy < hmap:at(sx, sz) * chunk_height - 6 then
|
||||||
|
table.insert(placements, {ore.struct, {sx, sy, sz}, math.random()*4})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function place_structures(x, z, w, d, seed, hmap, chunk_height)
|
||||||
|
local placements = {}
|
||||||
|
place_ores(placements, x, z, w, d, seed, hmap, chunk_height)
|
||||||
return placements
|
return placements
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -23,7 +42,7 @@ function generate_heightmap(x, y, w, h, seed, s)
|
|||||||
map.noiseSeed = seed
|
map.noiseSeed = seed
|
||||||
map:noise({x, y}, 0.8*s, 4, 0.02)
|
map:noise({x, y}, 0.8*s, 4, 0.02)
|
||||||
map:cellnoise({x, y}, 0.1*s, 3, 0.3, umap, vmap)
|
map:cellnoise({x, y}, 0.1*s, 3, 0.3, umap, vmap)
|
||||||
map:add(0.4)
|
map:add(0.7)
|
||||||
|
|
||||||
local rivermap = Heightmap(w, h)
|
local rivermap = Heightmap(w, h)
|
||||||
rivermap.noiseSeed = seed
|
rivermap.noiseSeed = seed
|
||||||
@@ -32,7 +51,6 @@ function generate_heightmap(x, y, w, h, seed, s)
|
|||||||
rivermap:mul(2.0)
|
rivermap:mul(2.0)
|
||||||
rivermap:pow(0.15)
|
rivermap:pow(0.15)
|
||||||
rivermap:max(0.3)
|
rivermap:max(0.3)
|
||||||
map:add(0.3)
|
|
||||||
map:mul(rivermap)
|
map:mul(rivermap)
|
||||||
return map
|
return map
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -212,5 +212,6 @@ void ContentLoader::loadGenerator(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
load_biomes(def, biomesFiles);
|
load_biomes(def, biomesFiles);
|
||||||
def.script = scripting::load_generator(def, scriptFile);
|
def.script = scripting::load_generator(
|
||||||
|
def, scriptFile, pack->id+":generators/"+name+".files");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,7 +149,8 @@ namespace scripting {
|
|||||||
|
|
||||||
std::unique_ptr<GeneratorScript> load_generator(
|
std::unique_ptr<GeneratorScript> load_generator(
|
||||||
const GeneratorDef& def,
|
const GeneratorDef& def,
|
||||||
const fs::path& file
|
const fs::path& file,
|
||||||
|
const std::string& dirPath
|
||||||
);
|
);
|
||||||
|
|
||||||
/// @brief Load package-specific world script
|
/// @brief Load package-specific world script
|
||||||
|
|||||||
@@ -126,12 +126,20 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<GeneratorScript> scripting::load_generator(
|
std::unique_ptr<GeneratorScript> scripting::load_generator(
|
||||||
const GeneratorDef& def, const fs::path& file
|
const GeneratorDef& def, const fs::path& file, const std::string& dirPath
|
||||||
) {
|
) {
|
||||||
auto env = create_environment();
|
auto env = create_environment();
|
||||||
auto L = lua::get_main_thread();
|
auto L = lua::get_main_thread();
|
||||||
lua::stackguard _(L);
|
lua::stackguard _(L);
|
||||||
|
|
||||||
|
lua::pushenv(L, *env);
|
||||||
|
lua::pushstring(L, dirPath);
|
||||||
|
lua::setfield(L, "__DIR__");
|
||||||
|
lua::pushstring(L, dirPath + "/script.lua");
|
||||||
|
lua::setfield(L, "__FILE__");
|
||||||
|
|
||||||
|
lua::pop(L);
|
||||||
|
|
||||||
if (fs::exists(file)) {
|
if (fs::exists(file)) {
|
||||||
lua::pop(L, load_script(*env, "generator", file));
|
lua::pop(L, load_script(*env, "generator", file));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user