diff options
author | Perttu Ahola <celeron55@gmail.com> | 2012-03-28 20:46:05 +0300 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2012-03-28 22:01:21 +0300 |
commit | 9a1df7bf3879bc77025779f11f4a99943572931f (patch) | |
tree | 40bf1130087c6ccc02f98e83b9e54ecc6a005713 /src | |
parent | 81b9cfdfa47172171524a6a81bd5467581bfcbd3 (diff) | |
download | minetest-9a1df7bf3879bc77025779f11f4a99943572931f.tar.gz minetest-9a1df7bf3879bc77025779f11f4a99943572931f.tar.bz2 minetest-9a1df7bf3879bc77025779f11f4a99943572931f.zip |
Add blockseed to on_generated
Diffstat (limited to 'src')
-rw-r--r-- | src/mapgen.cpp | 16 | ||||
-rw-r--r-- | src/mapgen.h | 3 | ||||
-rw-r--r-- | src/scriptapi.cpp | 6 | ||||
-rw-r--r-- | src/scriptapi.h | 3 | ||||
-rw-r--r-- | src/server.cpp | 2 |
5 files changed, 24 insertions, 6 deletions
diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 46304cdf6..61718d910 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -193,6 +193,7 @@ void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0, } } +#if 0 static void make_jungletree(VoxelManipulator &vmanip, v3s16 p0, INodeDefManager *ndef) { @@ -280,7 +281,7 @@ static void make_jungletree(VoxelManipulator &vmanip, v3s16 p0, } } -void make_papyrus(VoxelManipulator &vmanip, v3s16 p0, +static void make_papyrus(VoxelManipulator &vmanip, v3s16 p0, INodeDefManager *ndef) { MapNode papyrusnode(ndef->getId("mapgen_papyrus")); @@ -295,7 +296,7 @@ void make_papyrus(VoxelManipulator &vmanip, v3s16 p0, } } -void make_cactus(VoxelManipulator &vmanip, v3s16 p0, +static void make_cactus(VoxelManipulator &vmanip, v3s16 p0, INodeDefManager *ndef) { MapNode cactusnode(ndef->getId("mapgen_cactus")); @@ -309,7 +310,9 @@ void make_cactus(VoxelManipulator &vmanip, v3s16 p0, p1.Y++; } } +#endif +#if 0 /* Dungeon making routines */ @@ -861,7 +864,9 @@ static void make_dungeon1(VoxelManipulator &vmanip, PseudoRandom &random, } } +#endif +#if 0 static void make_nc(VoxelManipulator &vmanip, PseudoRandom &random, INodeDefManager *ndef) { @@ -896,6 +901,7 @@ static void make_nc(VoxelManipulator &vmanip, PseudoRandom &random, vmanip.m_data[vmanip.m_area.index(p)] = MapNode(ndef->getId("mapgen_nyancat_rainbow")); } } +#endif /* Noise functions. Make sure seed is mangled differently in each one. @@ -1272,6 +1278,12 @@ bool get_have_sand(u64 seed, v2s16 p2d) return (sandnoise > -0.15); } +u32 get_blockseed(u64 seed, v3s16 p) +{ + s32 x=p.X, y=p.Y, z=p.Z; + return (u32)(seed%0x100000000ULL) + z*38134234 + y*42123 + x*23; +} + #define VMANIP_FLAG_CAVE VOXELFLAG_CHECKED1 void make_block(BlockMakeData *data) diff --git a/src/mapgen.h b/src/mapgen.h index 24a853bdc..3374c6782 100644 --- a/src/mapgen.h +++ b/src/mapgen.h @@ -36,6 +36,9 @@ namespace mapgen // Find out if block is completely underground bool block_is_underground(u64 seed, v3s16 blockpos); + // Get a pseudorandom seed for a position on the map + u32 get_blockseed(u64 seed, v3s16 p); + // Main map generation routine void make_block(BlockMakeData *data); diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index d2ded57c6..944b81a5e 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -4403,7 +4403,8 @@ void scriptapi_environment_step(lua_State *L, float dtime) } } -void scriptapi_environment_on_generated(lua_State *L, v3s16 minp, v3s16 maxp) +void scriptapi_environment_on_generated(lua_State *L, v3s16 minp, v3s16 maxp, + u32 blockseed) { realitycheck(L); assert(lua_checkstack(L, 20)); @@ -4423,7 +4424,8 @@ void scriptapi_environment_on_generated(lua_State *L, v3s16 minp, v3s16 maxp) // Call function push_v3s16(L, minp); push_v3s16(L, maxp); - if(lua_pcall(L, 2, 0, 0)) + lua_pushnumber(L, blockseed); + if(lua_pcall(L, 3, 0, 0)) script_error(L, "error: %s", lua_tostring(L, -1)); // value removed, keep key for next iteration } diff --git a/src/scriptapi.h b/src/scriptapi.h index f63cab368..373262888 100644 --- a/src/scriptapi.h +++ b/src/scriptapi.h @@ -51,7 +51,8 @@ bool scriptapi_on_chat_message(lua_State *L, const std::string &name, // On environment step void scriptapi_environment_step(lua_State *L, float dtime); // After generating a piece of map -void scriptapi_environment_on_generated(lua_State *L, v3s16 minp, v3s16 maxp); +void scriptapi_environment_on_generated(lua_State *L, v3s16 minp, v3s16 maxp, + u32 blockseed); /* misc */ void scriptapi_on_newplayer(lua_State *L, ServerActiveObject *player); diff --git a/src/server.cpp b/src/server.cpp index 6756e4a08..d3c1218e7 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -283,7 +283,7 @@ void * EmergeThread::Thread() v3s16 minp = block->getPos()*MAP_BLOCKSIZE; v3s16 maxp = minp + v3s16(1,1,1)*(MAP_BLOCKSIZE-1); scriptapi_environment_on_generated(m_server->m_lua, - minp, maxp); + minp, maxp, mapgen::get_blockseed(data.seed, minp)); if(enable_mapgen_debug_info) infostream<<"EmergeThread: ended up with: " |