Skip to content
Permalink
Browse files

Decoration API: Add flag for placement on liquid surface

Add findLiquidSurface() function to mapgen.cpp
Update lua_api.txt
  • Loading branch information
paramat committed Oct 21, 2015
1 parent c328478 commit 59fa117d13ba881f6f5e77c94f5a4ce6adb9647f
Showing with 38 additions and 8 deletions.
  1. +8 −5 doc/lua_api.txt
  2. +20 −0 src/mapgen.cpp
  3. +1 −0 src/mapgen.h
  4. +8 −3 src/mg_decoration.cpp
  5. +1 −0 src/mg_decoration.h
@@ -801,15 +801,13 @@ Decoration types
----------------
The varying types of decorations that can be placed.

The default value is `simple`, and is currently the only type supported.

### `simple`
Creates a 1 times `H` times 1 column of a specified node (or a random node from
a list, if a decoration list is specified). Can specify a certain node it must
spawn next to, such as water or lava, for example. Can also generate a
decoration of random height between a specified lower and upper bound.
This type of decoration is intended for placement of grass, flowers, cacti,
papyri, and so on.
papyri, waterlilies and so on.

### `schematic`
Copies a box of `MapNodes` from a specified schematic file (or raw description).
@@ -848,8 +846,8 @@ Schematic attributes
--------------------
See section "Flag Specifier Format".

Currently supported flags: `place_center_x`, `place_center_y`,
`place_center_z`, `force_placement`.
Currently supported flags: `place_center_x`, `place_center_y`, `place_center_z`,
`force_placement`.

* `place_center_x`: Placement of this decoration is centered along the X axis.
* `place_center_y`: Placement of this decoration is centered along the Y axis.
@@ -3418,6 +3416,11 @@ Definition tables
-- ^ Minimum and maximum `y` positions these decorations can be generated at.
-- ^ This parameter refers to the `y` position of the decoration base, so
-- the actual maximum height would be `height_max + size.Y`.
flags = "liquid_surface",
-- ^ Flags for all decoration types.
-- ^ "liquid_surface": Instead of placement on the highest solid surface
-- ^ in a mapchunk column, placement is on the highest liquid surface.
-- ^ Placement is disabled if solid nodes are found above the liquid surface.

----- Simple-type parameters
decoration = "default:grass",
@@ -161,6 +161,26 @@ s16 Mapgen::findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax)
}


// Returns -MAX_MAP_GENERATION_LIMIT if not found or if ground is found first
s16 Mapgen::findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax)
{
v3s16 em = vm->m_area.getExtent();
u32 i = vm->m_area.index(p2d.X, ymax, p2d.Y);
s16 y;

for (y = ymax; y >= ymin; y--) {
MapNode &n = vm->m_data[i];
if (ndef->get(n).walkable)
return -MAX_MAP_GENERATION_LIMIT;
else if (ndef->get(n).isLiquid())
break;

vm->m_area.add_y(em, i, -1);
}
return (y >= ymin) ? y : -MAX_MAP_GENERATION_LIMIT;
}


void Mapgen::updateHeightmap(v3s16 nmin, v3s16 nmax)
{
if (!heightmap)
@@ -166,6 +166,7 @@ class Mapgen {
static u32 getBlockSeed2(v3s16 p, int seed);
s16 findGroundLevelFull(v2s16 p2d);
s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
s16 findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax);
void updateHeightmap(v3s16 nmin, v3s16 nmax);
void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);

@@ -30,6 +30,7 @@ FlagDesc flagdesc_deco[] = {
{"place_center_y", DECO_PLACE_CENTER_Y},
{"place_center_z", DECO_PLACE_CENTER_Z},
{"force_placement", DECO_FORCE_PLACEMENT},
{"liquid_surface", DECO_LIQUID_SURFACE},
{NULL, 0}
};

@@ -124,9 +125,13 @@ size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)

int mapindex = carea_size * (z - nmin.Z) + (x - nmin.X);

s16 y = mg->heightmap ?
mg->heightmap[mapindex] :
mg->findGroundLevel(v2s16(x, z), nmin.Y, nmax.Y);
s16 y = -MAX_MAP_GENERATION_LIMIT;
if (flags & DECO_LIQUID_SURFACE)
y = mg->findLiquidSurface(v2s16(x, z), nmin.Y, nmax.Y);
else if (mg->heightmap)
y = mg->heightmap[mapindex];
else
y = mg->findGroundLevel(v2s16(x, z), nmin.Y, nmax.Y);

if (y < nmin.Y || y > nmax.Y ||
y < y_min || y > y_max)
@@ -41,6 +41,7 @@ enum DecorationType {
#define DECO_PLACE_CENTER_Z 0x04
#define DECO_USE_NOISE 0x08
#define DECO_FORCE_PLACEMENT 0x10
#define DECO_LIQUID_SURFACE 0x20

extern FlagDesc flagdesc_deco[];

0 comments on commit 59fa117

Please sign in to comment.
You can’t perform that action at this time.