forked from Mirrorlandia_minetest/minetest
Ore: Add Blob ore type
This commit is contained in:
parent
8c98f497d9
commit
900fa26965
@ -562,9 +562,9 @@ All default ores are of the uniformly-distributed scatter type.
|
|||||||
The height of the blob is randomly scattered, with a maximum height of clust_size.
|
The height of the blob is randomly scattered, with a maximum height of clust_size.
|
||||||
clust_scarcity and clust_num_ores are ignored.
|
clust_scarcity and clust_num_ores are ignored.
|
||||||
This is essentially an improved version of the so-called "stratus" ore seen in some unofficial mods.
|
This is essentially an improved version of the so-called "stratus" ore seen in some unofficial mods.
|
||||||
- claylike - NOT YET IMPLEMENTED
|
- blob
|
||||||
Places ore if there are no more than clust_scarcity number of specified nodes within a Von Neumann
|
Creates a roundish blob of ore according to 3d perlin noise described by noise_params. The maximum
|
||||||
neighborhood of clust_size radius.
|
size of the blob is clust_size, and clust_scarcity has the same meaning as with scatter type.
|
||||||
|
|
||||||
|
|
||||||
Ore attributes
|
Ore attributes
|
||||||
|
@ -178,12 +178,12 @@ void OreSheet::generate(ManualMapVoxelManipulator *vm, int seed,
|
|||||||
if (!noise) {
|
if (!noise) {
|
||||||
int sx = nmax.X - nmin.X + 1;
|
int sx = nmax.X - nmin.X + 1;
|
||||||
int sz = nmax.Z - nmin.Z + 1;
|
int sz = nmax.Z - nmin.Z + 1;
|
||||||
noise = new Noise(&np, seed, sx, sz);
|
noise = new Noise(&np, 0, sx, sz);
|
||||||
}
|
}
|
||||||
noise->seed = seed + y_start;
|
noise->seed = seed + y_start;
|
||||||
noise->perlinMap2D(nmin.X, nmin.Z);
|
noise->perlinMap2D(nmin.X, nmin.Z);
|
||||||
|
|
||||||
int index = 0;
|
size_t index = 0;
|
||||||
for (int z = nmin.Z; z <= nmax.Z; z++)
|
for (int z = nmin.Z; z <= nmax.Z; z++)
|
||||||
for (int x = nmin.X; x <= nmax.X; x++) {
|
for (int x = nmin.X; x <= nmax.X; x++) {
|
||||||
float noiseval = noise->result[index++];
|
float noiseval = noise->result[index++];
|
||||||
@ -204,3 +204,60 @@ void OreSheet::generate(ManualMapVoxelManipulator *vm, int seed,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void OreBlob::generate(ManualMapVoxelManipulator *vm, int seed, u32 blockseed,
|
||||||
|
v3s16 nmin, v3s16 nmax)
|
||||||
|
{
|
||||||
|
PseudoRandom pr(blockseed + 2404);
|
||||||
|
MapNode n_ore(c_ore, 0, ore_param2);
|
||||||
|
|
||||||
|
int volume = (nmax.X - nmin.X + 1) *
|
||||||
|
(nmax.Y - nmin.Y + 1) *
|
||||||
|
(nmax.Z - nmin.Z + 1);
|
||||||
|
int csize = clust_size;
|
||||||
|
int nblobs = volume / clust_scarcity;
|
||||||
|
|
||||||
|
if (!noise)
|
||||||
|
noise = new Noise(&np, seed, csize, csize, csize);
|
||||||
|
|
||||||
|
for (int i = 0; i != nblobs; i++) {
|
||||||
|
int x0 = pr.range(nmin.X, nmax.X - csize + 1);
|
||||||
|
int y0 = pr.range(nmin.Y, nmax.Y - csize + 1);
|
||||||
|
int z0 = pr.range(nmin.Z, nmax.Z - csize + 1);
|
||||||
|
|
||||||
|
bool noise_generated = false;
|
||||||
|
noise->seed = blockseed + i;
|
||||||
|
|
||||||
|
size_t index = 0;
|
||||||
|
for (int z1 = 0; z1 != csize; z1++)
|
||||||
|
for (int y1 = 0; y1 != csize; y1++)
|
||||||
|
for (int x1 = 0; x1 != csize; x1++, index++) {
|
||||||
|
u32 i = vm->m_area.index(x0 + x1, y0 + y1, z0 + z1);
|
||||||
|
if (!CONTAINS(c_wherein, vm->m_data[i].getContent()))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Lazily generate noise only if there's a chance of ore being placed
|
||||||
|
// This simple optimization makes calls 6x faster on average
|
||||||
|
if (!noise_generated) {
|
||||||
|
noise_generated = true;
|
||||||
|
noise->perlinMap3D(x0, y0, z0);
|
||||||
|
}
|
||||||
|
|
||||||
|
float noiseval = noise->result[index];
|
||||||
|
|
||||||
|
float xdist = x1 - csize / 2;
|
||||||
|
float ydist = y1 - csize / 2;
|
||||||
|
float zdist = z1 - csize / 2;
|
||||||
|
|
||||||
|
noiseval -= (sqrt(xdist * xdist + ydist * ydist + zdist * zdist) / csize);
|
||||||
|
|
||||||
|
if (noiseval < nthresh)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
vm->m_data[i] = n_ore;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
28
src/mg_ore.h
28
src/mg_ore.h
@ -47,9 +47,9 @@ class ManualMapVoxelManipulator;
|
|||||||
|
|
||||||
|
|
||||||
enum OreType {
|
enum OreType {
|
||||||
ORE_SCATTER,
|
ORE_TYPE_SCATTER,
|
||||||
ORE_SHEET,
|
ORE_TYPE_SHEET,
|
||||||
ORE_CLAYLIKE
|
ORE_TYPE_BLOB,
|
||||||
};
|
};
|
||||||
|
|
||||||
extern FlagDesc flagdesc_ore[];
|
extern FlagDesc flagdesc_ore[];
|
||||||
@ -78,7 +78,7 @@ public:
|
|||||||
|
|
||||||
size_t placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
|
size_t placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
|
||||||
virtual void generate(ManualMapVoxelManipulator *vm, int seed,
|
virtual void generate(ManualMapVoxelManipulator *vm, int seed,
|
||||||
u32 blockseed, v3s16 nmin, v3s16 nmax) = 0;
|
u32 blockseed, v3s16 nmin, v3s16 nmax) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class OreScatter : public Ore {
|
class OreScatter : public Ore {
|
||||||
@ -86,7 +86,7 @@ public:
|
|||||||
static const bool NEEDS_NOISE = false;
|
static const bool NEEDS_NOISE = false;
|
||||||
|
|
||||||
virtual void generate(ManualMapVoxelManipulator *vm, int seed,
|
virtual void generate(ManualMapVoxelManipulator *vm, int seed,
|
||||||
u32 blockseed, v3s16 nmin, v3s16 nmax);
|
u32 blockseed, v3s16 nmin, v3s16 nmax);
|
||||||
};
|
};
|
||||||
|
|
||||||
class OreSheet : public Ore {
|
class OreSheet : public Ore {
|
||||||
@ -94,7 +94,15 @@ public:
|
|||||||
static const bool NEEDS_NOISE = true;
|
static const bool NEEDS_NOISE = true;
|
||||||
|
|
||||||
virtual void generate(ManualMapVoxelManipulator *vm, int seed,
|
virtual void generate(ManualMapVoxelManipulator *vm, int seed,
|
||||||
u32 blockseed, v3s16 nmin, v3s16 nmax);
|
u32 blockseed, v3s16 nmin, v3s16 nmax);
|
||||||
|
};
|
||||||
|
|
||||||
|
class OreBlob : public Ore {
|
||||||
|
public:
|
||||||
|
static const bool NEEDS_NOISE = true;
|
||||||
|
|
||||||
|
virtual void generate(ManualMapVoxelManipulator *vm, int seed,
|
||||||
|
u32 blockseed, v3s16 nmin, v3s16 nmax);
|
||||||
};
|
};
|
||||||
|
|
||||||
class OreManager : public GenElementManager {
|
class OreManager : public GenElementManager {
|
||||||
@ -108,12 +116,12 @@ public:
|
|||||||
Ore *create(int type)
|
Ore *create(int type)
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ORE_SCATTER:
|
case ORE_TYPE_SCATTER:
|
||||||
return new OreScatter;
|
return new OreScatter;
|
||||||
case ORE_SHEET:
|
case ORE_TYPE_SHEET:
|
||||||
return new OreSheet;
|
return new OreSheet;
|
||||||
//case ORE_CLAYLIKE: //TODO: implement this!
|
case ORE_TYPE_BLOB:
|
||||||
// return new OreClaylike;
|
return new OreBlob;
|
||||||
default:
|
default:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -68,9 +68,9 @@ struct EnumString ModApiMapgen::es_MapgenObject[] =
|
|||||||
|
|
||||||
struct EnumString ModApiMapgen::es_OreType[] =
|
struct EnumString ModApiMapgen::es_OreType[] =
|
||||||
{
|
{
|
||||||
{ORE_SCATTER, "scatter"},
|
{ORE_TYPE_SCATTER, "scatter"},
|
||||||
{ORE_SHEET, "sheet"},
|
{ORE_TYPE_SHEET, "sheet"},
|
||||||
{ORE_CLAYLIKE, "claylike"},
|
{ORE_TYPE_BLOB, "blob"},
|
||||||
{0, NULL},
|
{0, NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -642,7 +642,7 @@ int ModApiMapgen::l_register_ore(lua_State *L)
|
|||||||
OreManager *oremgr = getServer(L)->getEmergeManager()->oremgr;
|
OreManager *oremgr = getServer(L)->getEmergeManager()->oremgr;
|
||||||
|
|
||||||
enum OreType oretype = (OreType)getenumfield(L, index,
|
enum OreType oretype = (OreType)getenumfield(L, index,
|
||||||
"ore_type", es_OreType, ORE_SCATTER);
|
"ore_type", es_OreType, ORE_TYPE_SCATTER);
|
||||||
Ore *ore = oremgr->create(oretype);
|
Ore *ore = oremgr->create(oretype);
|
||||||
if (!ore) {
|
if (!ore) {
|
||||||
errorstream << "register_ore: ore_type " << oretype << " not implemented";
|
errorstream << "register_ore: ore_type " << oretype << " not implemented";
|
||||||
|
Loading…
Reference in New Issue
Block a user