Add blockseed to on_generated

master
Perttu Ahola 2012-03-28 20:46:05 +03:00
parent 81b9cfdfa4
commit 9a1df7bf38
6 changed files with 25 additions and 7 deletions

View File

@ -444,7 +444,7 @@ minetest.register_globalstep(func(dtime))
minetest.register_on_placenode(func(pos, newnode, placer)) minetest.register_on_placenode(func(pos, newnode, placer))
minetest.register_on_dignode(func(pos, oldnode, digger)) minetest.register_on_dignode(func(pos, oldnode, digger))
minetest.register_on_punchnode(func(pos, node, puncher)) minetest.register_on_punchnode(func(pos, node, puncher))
minetest.register_on_generated(func(minp, maxp)) minetest.register_on_generated(func(minp, maxp, blockseed))
minetest.register_on_newplayer(func(ObjectRef)) minetest.register_on_newplayer(func(ObjectRef))
minetest.register_on_dieplayer(func(ObjectRef)) minetest.register_on_dieplayer(func(ObjectRef))
minetest.register_on_respawnplayer(func(ObjectRef)) minetest.register_on_respawnplayer(func(ObjectRef))

View File

@ -193,6 +193,7 @@ void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0,
} }
} }
#if 0
static void make_jungletree(VoxelManipulator &vmanip, v3s16 p0, static void make_jungletree(VoxelManipulator &vmanip, v3s16 p0,
INodeDefManager *ndef) 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) INodeDefManager *ndef)
{ {
MapNode papyrusnode(ndef->getId("mapgen_papyrus")); 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) INodeDefManager *ndef)
{ {
MapNode cactusnode(ndef->getId("mapgen_cactus")); MapNode cactusnode(ndef->getId("mapgen_cactus"));
@ -309,7 +310,9 @@ void make_cactus(VoxelManipulator &vmanip, v3s16 p0,
p1.Y++; p1.Y++;
} }
} }
#endif
#if 0
/* /*
Dungeon making routines 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, static void make_nc(VoxelManipulator &vmanip, PseudoRandom &random,
INodeDefManager *ndef) 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")); 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. 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); 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 #define VMANIP_FLAG_CAVE VOXELFLAG_CHECKED1
void make_block(BlockMakeData *data) void make_block(BlockMakeData *data)

View File

@ -36,6 +36,9 @@ namespace mapgen
// Find out if block is completely underground // Find out if block is completely underground
bool block_is_underground(u64 seed, v3s16 blockpos); 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 // Main map generation routine
void make_block(BlockMakeData *data); void make_block(BlockMakeData *data);

View File

@ -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); realitycheck(L);
assert(lua_checkstack(L, 20)); assert(lua_checkstack(L, 20));
@ -4423,7 +4424,8 @@ void scriptapi_environment_on_generated(lua_State *L, v3s16 minp, v3s16 maxp)
// Call function // Call function
push_v3s16(L, minp); push_v3s16(L, minp);
push_v3s16(L, maxp); 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)); script_error(L, "error: %s", lua_tostring(L, -1));
// value removed, keep key for next iteration // value removed, keep key for next iteration
} }

View File

@ -51,7 +51,8 @@ bool scriptapi_on_chat_message(lua_State *L, const std::string &name,
// On environment step // On environment step
void scriptapi_environment_step(lua_State *L, float dtime); void scriptapi_environment_step(lua_State *L, float dtime);
// After generating a piece of map // 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 */ /* misc */
void scriptapi_on_newplayer(lua_State *L, ServerActiveObject *player); void scriptapi_on_newplayer(lua_State *L, ServerActiveObject *player);

View File

@ -283,7 +283,7 @@ void * EmergeThread::Thread()
v3s16 minp = block->getPos()*MAP_BLOCKSIZE; v3s16 minp = block->getPos()*MAP_BLOCKSIZE;
v3s16 maxp = minp + v3s16(1,1,1)*(MAP_BLOCKSIZE-1); v3s16 maxp = minp + v3s16(1,1,1)*(MAP_BLOCKSIZE-1);
scriptapi_environment_on_generated(m_server->m_lua, scriptapi_environment_on_generated(m_server->m_lua,
minp, maxp); minp, maxp, mapgen::get_blockseed(data.seed, minp));
if(enable_mapgen_debug_info) if(enable_mapgen_debug_info)
infostream<<"EmergeThread: ended up with: " infostream<<"EmergeThread: ended up with: "