diff --git a/src/mapgen.cpp b/src/mapgen.cpp
index d1171e29d6459edc55c54727500d8ce05bcb4790..7f7c4e2409f46cd24fd07fca44e85db2a9b9a4e1 100644
--- a/src/mapgen.cpp
+++ b/src/mapgen.cpp
@@ -67,33 +67,37 @@ FlagDesc flagdesc_gennotify[] = {
 
 Mapgen::Mapgen()
 {
-	generating    = false;
-	id            = -1;
-	seed          = 0;
-	water_level   = 0;
-	flags         = 0;
-
-	vm          = NULL;
-	ndef        = NULL;
-	heightmap   = NULL;
-	biomemap    = NULL;
+	generating  = false;
+	id          = -1;
+	seed        = 0;
+	water_level = 0;
+	flags       = 0;
+
+	vm        = NULL;
+	ndef      = NULL;
+	heightmap = NULL;
+	biomemap  = NULL;
+	heatmap   = NULL;
+	humidmap  = NULL;
 }
 
 
 Mapgen::Mapgen(int mapgenid, MapgenParams *params, EmergeManager *emerge) :
 	gennotify(emerge->gen_notify_on, &emerge->gen_notify_on_deco_ids)
 {
-	generating    = false;
-	id            = mapgenid;
-	seed          = (int)params->seed;
-	water_level   = params->water_level;
-	flags         = params->flags;
-	csize         = v3s16(1, 1, 1) * (params->chunksize * MAP_BLOCKSIZE);
+	generating  = false;
+	id          = mapgenid;
+	seed        = (int)params->seed;
+	water_level = params->water_level;
+	flags       = params->flags;
+	csize       = v3s16(1, 1, 1) * (params->chunksize * MAP_BLOCKSIZE);
 
 	vm        = NULL;
 	ndef      = NULL;
 	heightmap = NULL;
 	biomemap  = NULL;
+	heatmap   = NULL;
+	humidmap  = NULL;
 }
 
 
diff --git a/src/mapgen.h b/src/mapgen.h
index a1cc8af534eb2e10461c171ebc5544b648b3a9df..74fca4f5a356200bb8693597157a9bebbdafe8ea 100644
--- a/src/mapgen.h
+++ b/src/mapgen.h
@@ -152,6 +152,8 @@ class Mapgen {
 	u32 blockseed;
 	s16 *heightmap;
 	u8 *biomemap;
+	float *heatmap;
+	float *humidmap;
 	v3s16 csize;
 
 	GenerateNotifier gennotify;
diff --git a/src/mapgen_v5.cpp b/src/mapgen_v5.cpp
index f748e7b8652b1dafe599624389a970ebdb330129..4d1c0df1d67d7252e606835ebfecf1a0af74289c 100644
--- a/src/mapgen_v5.cpp
+++ b/src/mapgen_v5.cpp
@@ -58,6 +58,8 @@ MapgenV5::MapgenV5(int mapgenid, MapgenParams *params, EmergeManager *emerge)
 
 	this->biomemap  = new u8[csize.X * csize.Z];
 	this->heightmap = new s16[csize.X * csize.Z];
+	this->heatmap   = NULL;
+	this->humidmap  = NULL;
 
 	MapgenV5Params *sp = (MapgenV5Params *)params->sparams;
 	this->spflags      = sp->spflags;
@@ -341,6 +343,9 @@ void MapgenV5::calculateNoise()
 		noise_heat->result[i] += noise_heat_blend->result[i];
 		noise_humidity->result[i] += noise_humidity_blend->result[i];
 	}
+
+	heatmap = noise_heat->result;
+	humidmap = noise_humidity->result;
 	//printf("calculateNoise: %dus\n", t.stop());
 }
 
diff --git a/src/mapgen_v5.h b/src/mapgen_v5.h
index 911975e7fdc9894e680edbae3e2c460f2a374c20..a6fdc2b2b8eac6c13adfc9ff79cd9867c2e0ce6a 100644
--- a/src/mapgen_v5.h
+++ b/src/mapgen_v5.h
@@ -24,9 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #define LARGE_CAVE_DEPTH -256
 
-/////////////////// Mapgen V5 flags
-//#define MGV5_   0x01
-
 class BiomeManager;
 
 extern FlagDesc flagdesc_mapgen_v5[];
diff --git a/src/mapgen_v7.cpp b/src/mapgen_v7.cpp
index 6e97c2c1635da3c0143b8f0645d98e334e19a718..c32bf3882b8f63ff08bf5147689c4997b97868bb 100644
--- a/src/mapgen_v7.cpp
+++ b/src/mapgen_v7.cpp
@@ -59,8 +59,10 @@ MapgenV7::MapgenV7(int mapgenid, MapgenParams *params, EmergeManager *emerge)
 	this->ystride = csize.X;
 	this->zstride = csize.X * (csize.Y + 2);
 
-	this->biomemap  = new u8[csize.X * csize.Z];
-	this->heightmap = new s16[csize.X * csize.Z];
+	this->biomemap        = new u8[csize.X * csize.Z];
+	this->heightmap       = new s16[csize.X * csize.Z];
+	this->heatmap         = NULL;
+	this->humidmap        = NULL;
 	this->ridge_heightmap = new s16[csize.X * csize.Z];
 
 	MapgenV7Params *sp = (MapgenV7Params *)params->sparams;
@@ -376,6 +378,9 @@ void MapgenV7::calculateNoise()
 		noise_heat->result[i] += noise_heat_blend->result[i];
 		noise_humidity->result[i] += noise_humidity_blend->result[i];
 	}
+
+	heatmap = noise_heat->result;
+	humidmap = noise_humidity->result;
 	//printf("calculateNoise: %dus\n", t.stop());
 }
 
diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp
index 1a462adf72c7a95d0383960e3c506a049acaec12..2d67e2f29e032c13f370b163c015aec07a047124 100644
--- a/src/script/lua_api/l_mapgen.cpp
+++ b/src/script/lua_api/l_mapgen.cpp
@@ -510,21 +510,26 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L)
 
 		return 1;
 	}
-	case MGOBJ_HEATMAP: { // Mapgen V7 specific objects
-	case MGOBJ_HUMIDMAP:
-		if (strcmp(emerge->params.mg_name.c_str(), "v7"))
+	case MGOBJ_HEATMAP: {
+		if (!mg->heatmap)
 			return 0;
 
-		MapgenV7 *mgv7 = (MapgenV7 *)mg;
+		lua_newtable(L);
+		for (size_t i = 0; i != maplen; i++) {
+			lua_pushnumber(L, mg->heatmap[i]);
+			lua_rawseti(L, -2, i + 1);
+		}
+
+		return 1;
+	}
 
-		float *arr = (mgobj == MGOBJ_HEATMAP) ?
-			mgv7->noise_heat->result : mgv7->noise_humidity->result;
-		if (!arr)
+	case MGOBJ_HUMIDMAP: {
+		if (!mg->humidmap)
 			return 0;
 
 		lua_newtable(L);
 		for (size_t i = 0; i != maplen; i++) {
-			lua_pushnumber(L, arr[i]);
+			lua_pushnumber(L, mg->humidmap[i]);
 			lua_rawseti(L, -2, i + 1);
 		}