From 769cc9879f306055e683bf720b0877a364e82ba5 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 26 Nov 2011 15:19:03 +0200 Subject: [PATCH] Add on_generated hook --- data/mods/default/init.lua | 7 +++++++ src/mapgen.h | 2 +- src/scriptapi.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/scriptapi.h | 2 ++ src/server.cpp | 5 +++++ 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/data/mods/default/init.lua b/data/mods/default/init.lua index 88f457e2..6ea15b4e 100644 --- a/data/mods/default/init.lua +++ b/data/mods/default/init.lua @@ -15,6 +15,7 @@ -- 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_newplayer(func(ObjectRef)) -- minetest.register_on_respawnplayer(func(ObjectRef)) -- ^ return true in func to disable regular player placement @@ -1329,6 +1330,12 @@ minetest.register_on_respawnplayer(function(player) -- return true end) +minetest.register_on_generated(function(minp, maxp) + --print("on_generated: minp="..dump(minp).." maxp="..dump(maxp)) + --cp = {x=(minp.x+maxp.x)/2, y=(minp.y+maxp.y)/2, z=(minp.z+maxp.z)/2} + --minetest.env:add_node(cp, {name="sand"}) +end) + -- Example setting get print("setting max_users = " .. dump(minetest.setting_get("max_users"))) print("setting asdf = " .. dump(minetest.setting_get("asdf"))) diff --git a/src/mapgen.h b/src/mapgen.h index 55aede09..207dfdaf 100644 --- a/src/mapgen.h +++ b/src/mapgen.h @@ -60,7 +60,7 @@ namespace mapgen u64 seed; v3s16 blockpos; UniqueQueue transforming_liquid; - INodeDefManager *nodedef; // Destructor deletes + INodeDefManager *nodedef; BlockMakeData(); ~BlockMakeData(); diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index badf3818..976b482c 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -843,6 +843,13 @@ static int l_register_on_punchnode(lua_State *L) return register_lua_callback(L, "registered_on_punchnodes"); } +// register_on_generated(function) +static int l_register_on_generated(lua_State *L) +{ + infostream<<"register_on_generated"<getPos()*MAP_BLOCKSIZE; + v3s16 maxp = minp + v3s16(1,1,1)*(MAP_BLOCKSIZE-1); + scriptapi_environment_on_generated(m_server->m_lua, + minp, maxp); } } -- 2.30.2