aboutsummaryrefslogtreecommitdiff
path: root/src/mapgen.cpp
diff options
context:
space:
mode:
authorparamat <mat.gregory@virginmedia.com>2015-10-21 08:51:59 +0100
committerparamat <mat.gregory@virginmedia.com>2015-10-23 21:30:20 +0100
commit59fa117d13ba881f6f5e77c94f5a4ce6adb9647f (patch)
tree43c26bb908a117de4471a442626812fea942c3ea /src/mapgen.cpp
parentc32847838d72c327031520c48b76607b63da4ccc (diff)
downloadminetest-59fa117d13ba881f6f5e77c94f5a4ce6adb9647f.tar.gz
minetest-59fa117d13ba881f6f5e77c94f5a4ce6adb9647f.tar.bz2
minetest-59fa117d13ba881f6f5e77c94f5a4ce6adb9647f.zip
Decoration API: Add flag for placement on liquid surface
Add findLiquidSurface() function to mapgen.cpp Update lua_api.txt
Diffstat (limited to 'src/mapgen.cpp')
-rw-r--r--src/mapgen.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/mapgen.cpp b/src/mapgen.cpp
index f5046459e..8a77000fa 100644
--- a/src/mapgen.cpp
+++ b/src/mapgen.cpp
@@ -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)