Add blockseed to on_generated

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

@ -444,7 +444,7 @@ minetest.register_globalstep(func(dtime))
minetest.register_on_placenode(func(pos, newnode, placer))
minetest.register_on_dignode(func(pos, oldnode, digger))
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_dieplayer(func(ObjectRef))
minetest.register_on_respawnplayer(func(ObjectRef))

@ -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)

@ -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);

@ -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
}

@ -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);

@ -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: "