diff options
author | kwolekr <kwolekr@minetest.net> | 2013-06-22 00:29:44 -0400 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2013-06-22 01:11:52 -0400 |
commit | c1b829077a3518f3a129eee11887b2358a53f20b (patch) | |
tree | 966230881a6fba1ce81d5b356f03c273bb6584dd /src/script/common | |
parent | b1a74df26d73aab2463ad0f18e04d1970bf83d96 (diff) | |
download | minetest-c1b829077a3518f3a129eee11887b2358a53f20b.tar.gz minetest-c1b829077a3518f3a129eee11887b2358a53f20b.tar.bz2 minetest-c1b829077a3518f3a129eee11887b2358a53f20b.zip |
Decoration: Add Schematic decoration type
Diffstat (limited to 'src/script/common')
-rw-r--r-- | src/script/common/c_content.cpp | 49 | ||||
-rw-r--r-- | src/script/common/c_content.h | 5 |
2 files changed, 54 insertions, 0 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 64c76ef7c..4ea296523 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "log.h" #include "tool.h" #include "server.h" +#include "mapgen.h" struct EnumString es_TileAnimationType[] = { @@ -922,3 +923,51 @@ NoiseParams *read_noiseparams(lua_State *L, int index) return np; } + +/******************************************************************************/ +bool read_schematic(lua_State *L, int index, DecoSchematic *dschem, Server *server) { + if (index < 0) + index = lua_gettop(L) + 1 + index; + + INodeDefManager *ndef = server->getNodeDefManager(); + + if (lua_istable(L, index)) { + lua_getfield(L, index, "size"); + v3s16 size = read_v3s16(L, -1); + lua_pop(L, 1); + + int numnodes = size.X * size.Y * size.Z; + MapNode *schemdata = new MapNode[numnodes]; + int i = 0; + + lua_getfield(L, index, "data"); + luaL_checktype(L, -1, LUA_TTABLE); + + lua_pushnil(L); + while (lua_next(L, -2)) { + if (i < numnodes) + schemdata[i] = readnode(L, -1, ndef); + + i++; + lua_pop(L, 1); + } + + dschem->size = size; + dschem->schematic = schemdata; + + if (i != numnodes) { + errorstream << "read_schematic: incorrect number of " + "nodes provided in raw schematic data (got " << i << + ", expected " << numnodes << ")." << std::endl; + return false; + } + } else if (lua_isstring(L, index)) { + dschem->filename = std::string(lua_tostring(L, index)); + } else { + errorstream << "read_schematic: missing schematic " + "filename or raw schematic data" << std::endl; + return false; + } + + return true; +} diff --git a/src/script/common/c_content.h b/src/script/common/c_content.h index 58be7118c..fc00ce089 100644 --- a/src/script/common/c_content.h +++ b/src/script/common/c_content.h @@ -57,6 +57,7 @@ struct DigParams; struct HitParams; struct EnumString; struct NoiseParams; +class DecoSchematic; ContentFeatures read_content_features (lua_State *L, int index); @@ -139,6 +140,10 @@ bool string_to_enum (const EnumString *spec, NoiseParams* read_noiseparams (lua_State *L, int index); +bool read_schematic (lua_State *L, int index, + DecoSchematic *dschem, + Server *server); + void luaentity_get (lua_State *L,u16 id); extern struct EnumString es_TileAnimationType[]; |