Skip to content

Commit 59fa117

Browse files
committedOct 23, 2015
Decoration API: Add flag for placement on liquid surface
Add findLiquidSurface() function to mapgen.cpp Update lua_api.txt
1 parent c328478 commit 59fa117

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed
 

Diff for: ‎doc/lua_api.txt

+8-5
Original file line numberDiff line numberDiff line change
@@ -801,15 +801,13 @@ Decoration types
801801
----------------
802802
The varying types of decorations that can be placed.
803803

804-
The default value is `simple`, and is currently the only type supported.
805-
806804
### `simple`
807805
Creates a 1 times `H` times 1 column of a specified node (or a random node from
808806
a list, if a decoration list is specified). Can specify a certain node it must
809807
spawn next to, such as water or lava, for example. Can also generate a
810808
decoration of random height between a specified lower and upper bound.
811809
This type of decoration is intended for placement of grass, flowers, cacti,
812-
papyri, and so on.
810+
papyri, waterlilies and so on.
813811

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

851-
Currently supported flags: `place_center_x`, `place_center_y`,
852-
`place_center_z`, `force_placement`.
849+
Currently supported flags: `place_center_x`, `place_center_y`, `place_center_z`,
850+
`force_placement`.
853851

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

34223425
----- Simple-type parameters
34233426
decoration = "default:grass",

Diff for: ‎src/mapgen.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,26 @@ s16 Mapgen::findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax)
161161
}
162162

163163

164+
// Returns -MAX_MAP_GENERATION_LIMIT if not found or if ground is found first
165+
s16 Mapgen::findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax)
166+
{
167+
v3s16 em = vm->m_area.getExtent();
168+
u32 i = vm->m_area.index(p2d.X, ymax, p2d.Y);
169+
s16 y;
170+
171+
for (y = ymax; y >= ymin; y--) {
172+
MapNode &n = vm->m_data[i];
173+
if (ndef->get(n).walkable)
174+
return -MAX_MAP_GENERATION_LIMIT;
175+
else if (ndef->get(n).isLiquid())
176+
break;
177+
178+
vm->m_area.add_y(em, i, -1);
179+
}
180+
return (y >= ymin) ? y : -MAX_MAP_GENERATION_LIMIT;
181+
}
182+
183+
164184
void Mapgen::updateHeightmap(v3s16 nmin, v3s16 nmax)
165185
{
166186
if (!heightmap)

Diff for: ‎src/mapgen.h

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class Mapgen {
166166
static u32 getBlockSeed2(v3s16 p, int seed);
167167
s16 findGroundLevelFull(v2s16 p2d);
168168
s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
169+
s16 findLiquidSurface(v2s16 p2d, s16 ymin, s16 ymax);
169170
void updateHeightmap(v3s16 nmin, v3s16 nmax);
170171
void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
171172

Diff for: ‎src/mg_decoration.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ FlagDesc flagdesc_deco[] = {
3030
{"place_center_y", DECO_PLACE_CENTER_Y},
3131
{"place_center_z", DECO_PLACE_CENTER_Z},
3232
{"force_placement", DECO_FORCE_PLACEMENT},
33+
{"liquid_surface", DECO_LIQUID_SURFACE},
3334
{NULL, 0}
3435
};
3536

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

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

127-
s16 y = mg->heightmap ?
128-
mg->heightmap[mapindex] :
129-
mg->findGroundLevel(v2s16(x, z), nmin.Y, nmax.Y);
128+
s16 y = -MAX_MAP_GENERATION_LIMIT;
129+
if (flags & DECO_LIQUID_SURFACE)
130+
y = mg->findLiquidSurface(v2s16(x, z), nmin.Y, nmax.Y);
131+
else if (mg->heightmap)
132+
y = mg->heightmap[mapindex];
133+
else
134+
y = mg->findGroundLevel(v2s16(x, z), nmin.Y, nmax.Y);
130135

131136
if (y < nmin.Y || y > nmax.Y ||
132137
y < y_min || y > y_max)

Diff for: ‎src/mg_decoration.h

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ enum DecorationType {
4141
#define DECO_PLACE_CENTER_Z 0x04
4242
#define DECO_USE_NOISE 0x08
4343
#define DECO_FORCE_PLACEMENT 0x10
44+
#define DECO_LIQUID_SURFACE 0x20
4445

4546
extern FlagDesc flagdesc_deco[];
4647

0 commit comments

Comments
 (0)
Please sign in to comment.