]> git.lizzy.rs Git - minetest.git/blobdiff - src/script/common/c_content.cpp
Add particle animation, glow
[minetest.git] / src / script / common / c_content.cpp
index 1c78f139ff7e517e48cd3d438536aaea4f23d4c6..84af4583b9de7d2962d1b2d18eccfc88f18a6302 100644 (file)
@@ -33,12 +33,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "porting.h"
 #include "mg_schematic.h"
 #include "noise.h"
-#include "json/json.h"
+#include <json/json.h>
 
 struct EnumString es_TileAnimationType[] =
 {
        {TAT_NONE, "none"},
        {TAT_VERTICAL_FRAMES, "vertical_frames"},
+       {TAT_SHEET_2D, "sheet_2d"},
        {0, NULL},
 };
 
@@ -65,9 +66,8 @@ ItemDefinition read_item_definition(lua_State* L,int index,
        }
        lua_pop(L, 1);
 
-       def.stack_max = getintfield_default(L, index, "stack_max", def.stack_max);
-       if(def.stack_max == 0)
-               def.stack_max = 1;
+       int stack_max = getintfield_default(L, index, "stack_max", def.stack_max);
+       def.stack_max = rangelim(stack_max, 1, U16_MAX);
 
        lua_getfield(L, index, "on_use");
        def.usable = lua_isfunction(L, -1);
@@ -76,7 +76,7 @@ ItemDefinition read_item_definition(lua_State* L,int index,
        getboolfield(L, index, "liquids_pointable", def.liquids_pointable);
 
        warn_if_field_exists(L, index, "tool_digging_properties",
-                       "deprecated: use tool_capabilities");
+                       "Deprecated; use tool_capabilities");
 
        lua_getfield(L, index, "tool_capabilities");
        if(lua_istable(L, -1)){
@@ -100,6 +100,9 @@ ItemDefinition read_item_definition(lua_State* L,int index,
                lua_getfield(L, -1, "place");
                read_soundspec(L, -1, def.sound_place);
                lua_pop(L, 1);
+               lua_getfield(L, -1, "place_failed");
+               read_soundspec(L, -1, def.sound_place_failed);
+               lua_pop(L, 1);
        }
        lua_pop(L, 1);
 
@@ -162,18 +165,13 @@ void read_object_properties(lua_State *L, int index,
        lua_pop(L, 1);
 
        lua_getfield(L, -1, "colors");
-       if(lua_istable(L, -1)){
-               prop->colors.clear();
+       if (lua_istable(L, -1)) {
                int table = lua_gettop(L);
-               lua_pushnil(L);
-               while(lua_next(L, table) != 0){
-                       // key at index -2 and value at index -1
-                       if(lua_isstring(L, -1))
-                               prop->colors.push_back(readARGB8(L, -1));
-                       else
-                               prop->colors.push_back(video::SColor(255, 255, 255, 255));
-                       // removes value, keeps key for next iteration
-                       lua_pop(L, 1);
+               prop->colors.clear();
+               for (lua_pushnil(L); lua_next(L, table); lua_pop(L, 1)) {
+                       video::SColor color(255, 255, 255, 255);
+                       read_color(L, -1, &color);
+                       prop->colors.push_back(color);
                }
        }
        lua_pop(L, 1);
@@ -202,43 +200,141 @@ void read_object_properties(lua_State *L, int index,
                prop->automatic_face_movement_dir_offset = 0.0;
        }
        lua_pop(L, 1);
+       getboolfield(L, -1, "backface_culling", prop->backface_culling);
+
+       getstringfield(L, -1, "nametag", prop->nametag);
+       lua_getfield(L, -1, "nametag_color");
+       if (!lua_isnil(L, -1)) {
+               video::SColor color = prop->nametag_color;
+               if (read_color(L, -1, &color))
+                       prop->nametag_color = color;
+       }
+       lua_pop(L, 1);
+
+       lua_getfield(L, -1, "automatic_face_movement_max_rotation_per_sec");
+       if (lua_isnumber(L, -1)) {
+               prop->automatic_face_movement_max_rotation_per_sec = luaL_checknumber(L, -1);
+       }
+       lua_pop(L, 1);
+       getstringfield(L, -1, "infotext", prop->infotext);
 }
 
 /******************************************************************************/
-TileDef read_tiledef(lua_State *L, int index)
+void push_object_properties(lua_State *L, ObjectProperties *prop)
+{
+       lua_newtable(L);
+       lua_pushnumber(L, prop->hp_max);
+       lua_setfield(L, -2, "hp_max");
+       lua_pushboolean(L, prop->physical);
+       lua_setfield(L, -2, "physical");
+       lua_pushboolean(L, prop->collideWithObjects);
+       lua_setfield(L, -2, "collide_with_objects");
+       lua_pushnumber(L, prop->weight);
+       lua_setfield(L, -2, "weight");
+       push_aabb3f(L, prop->collisionbox);
+       lua_setfield(L, -2, "collisionbox");
+       lua_pushlstring(L, prop->visual.c_str(), prop->visual.size());
+       lua_setfield(L, -2, "visual");
+       lua_pushlstring(L, prop->mesh.c_str(), prop->mesh.size());
+       lua_setfield(L, -2, "mesh");
+       push_v2f(L, prop->visual_size);
+       lua_setfield(L, -2, "visual_size");
+
+       lua_newtable(L);
+       u16 i = 1;
+       for (std::vector<std::string>::iterator it = prop->textures.begin();
+                       it != prop->textures.end(); ++it) {
+               lua_pushlstring(L, it->c_str(), it->size());
+               lua_rawseti(L, -2, i);
+       }
+       lua_setfield(L, -2, "textures");
+
+       lua_newtable(L);
+       i = 1;
+       for (std::vector<video::SColor>::iterator it = prop->colors.begin();
+                       it != prop->colors.end(); ++it) {
+               push_ARGB8(L, *it);
+               lua_rawseti(L, -2, i);
+       }
+       lua_setfield(L, -2, "colors");
+
+       push_v2s16(L, prop->spritediv);
+       lua_setfield(L, -2, "spritediv");
+       push_v2s16(L, prop->initial_sprite_basepos);
+       lua_setfield(L, -2, "initial_sprite_basepos");
+       lua_pushboolean(L, prop->is_visible);
+       lua_setfield(L, -2, "is_visible");
+       lua_pushboolean(L, prop->makes_footstep_sound);
+       lua_setfield(L, -2, "makes_footstep_sound");
+       lua_pushnumber(L, prop->automatic_rotate);
+       lua_setfield(L, -2, "automatic_rotate");
+       lua_pushnumber(L, prop->stepheight / BS);
+       lua_setfield(L, -2, "stepheight");
+       if (prop->automatic_face_movement_dir)
+               lua_pushnumber(L, prop->automatic_face_movement_dir_offset);
+       else
+               lua_pushboolean(L, false);
+       lua_setfield(L, -2, "automatic_face_movement_dir");
+       lua_pushboolean(L, prop->backface_culling);
+       lua_setfield(L, -2, "backface_culling");
+       lua_pushlstring(L, prop->nametag.c_str(), prop->nametag.size());
+       lua_setfield(L, -2, "nametag");
+       push_ARGB8(L, prop->nametag_color);
+       lua_setfield(L, -2, "nametag_color");
+       lua_pushnumber(L, prop->automatic_face_movement_max_rotation_per_sec);
+       lua_setfield(L, -2, "automatic_face_movement_max_rotation_per_sec");
+       lua_pushlstring(L, prop->infotext.c_str(), prop->infotext.size());
+       lua_setfield(L, -2, "infotext");
+}
+
+/******************************************************************************/
+TileDef read_tiledef(lua_State *L, int index, u8 drawtype)
 {
        if(index < 0)
                index = lua_gettop(L) + 1 + index;
 
        TileDef tiledef;
 
+       bool default_tiling = true;
+       bool default_culling = true;
+       switch (drawtype) {
+               case NDT_PLANTLIKE:
+               case NDT_FIRELIKE:
+                       default_tiling = false;
+                       // "break" is omitted here intentionaly, as PLANTLIKE
+                       // FIRELIKE drawtype both should default to having
+                       // backface_culling to false.
+               case NDT_MESH:
+               case NDT_LIQUID:
+                       default_culling = false;
+                       break;
+               default:
+                       break;
+       }
+
        // key at index -2 and value at index
        if(lua_isstring(L, index)){
                // "default_lava.png"
                tiledef.name = lua_tostring(L, index);
+               tiledef.tileable_vertical = default_tiling;
+               tiledef.tileable_horizontal = default_tiling;
+               tiledef.backface_culling = default_culling;
        }
        else if(lua_istable(L, index))
        {
-               // {name="default_lava.png", animation={}}
+               // name="default_lava.png"
                tiledef.name = "";
                getstringfield(L, index, "name", tiledef.name);
                getstringfield(L, index, "image", tiledef.name); // MaterialSpec compat.
                tiledef.backface_culling = getboolfield_default(
-                                       L, index, "backface_culling", true);
+                       L, index, "backface_culling", default_culling);
+               tiledef.tileable_horizontal = getboolfield_default(
+                       L, index, "tileable_horizontal", default_tiling);
+               tiledef.tileable_vertical = getboolfield_default(
+                       L, index, "tileable_vertical", default_tiling);
                // animation = {}
                lua_getfield(L, index, "animation");
-               if(lua_istable(L, -1)){
-                       // {type="vertical_frames", aspect_w=16, aspect_h=16, length=2.0}
-                       tiledef.animation.type = (TileAnimationType)
-                                       getenumfield(L, -1, "type", es_TileAnimationType,
-                                       TAT_NONE);
-                       tiledef.animation.aspect_w =
-                                       getintfield_default(L, -1, "aspect_w", 16);
-                       tiledef.animation.aspect_h =
-                                       getintfield_default(L, -1, "aspect_h", 16);
-                       tiledef.animation.length =
-                                       getfloatfield_default(L, -1, "length", 1.0);
-               }
+               tiledef.animation = read_animation_definition(L, -1);
                lua_pop(L, 1);
        }
 
@@ -300,7 +396,7 @@ ContentFeatures read_content_features(lua_State *L, int index)
                int i = 0;
                while(lua_next(L, table) != 0){
                        // Read tiledef from value
-                       f.tiledef[i] = read_tiledef(L, -1);
+                       f.tiledef[i] = read_tiledef(L, -1, f.drawtype);
                        // removes value, keeps key for next iteration
                        lua_pop(L, 1);
                        i++;
@@ -335,7 +431,7 @@ ContentFeatures read_content_features(lua_State *L, int index)
                int i = 0;
                while(lua_next(L, table) != 0){
                        // Read tiledef from value
-                       f.tiledef_special[i] = read_tiledef(L, -1);
+                       f.tiledef_special[i] = read_tiledef(L, -1, f.drawtype);
                        // removes value, keeps key for next iteration
                        lua_pop(L, 1);
                        i++;
@@ -357,8 +453,7 @@ ContentFeatures read_content_features(lua_State *L, int index)
        /* Other stuff */
 
        lua_getfield(L, index, "post_effect_color");
-       if(!lua_isnil(L, -1))
-               f.post_effect_color = readARGB8(L, -1);
+       read_color(L, -1, &f.post_effect_color);
        lua_pop(L, 1);
 
        f.param_type = (ContentParamType)getenumfield(L, index, "paramtype",
@@ -368,17 +463,17 @@ ContentFeatures read_content_features(lua_State *L, int index)
 
        // Warn about some deprecated fields
        warn_if_field_exists(L, index, "wall_mounted",
-                       "deprecated: use paramtype2 = 'wallmounted'");
+                       "Deprecated; use paramtype2 = 'wallmounted'");
        warn_if_field_exists(L, index, "light_propagates",
-                       "deprecated: determined from paramtype");
+                       "Deprecated; determined from paramtype");
        warn_if_field_exists(L, index, "dug_item",
-                       "deprecated: use 'drop' field");
+                       "Deprecated; use 'drop' field");
        warn_if_field_exists(L, index, "extra_dug_item",
-                       "deprecated: use 'drop' field");
+                       "Deprecated; use 'drop' field");
        warn_if_field_exists(L, index, "extra_dug_item_rarity",
-                       "deprecated: use 'drop' field");
+                       "Deprecated; use 'drop' field");
        warn_if_field_exists(L, index, "metadata_name",
-                       "deprecated: use on_add and metadata callbacks");
+                       "Deprecated; use on_add and metadata callbacks");
 
        // True for all ground-like things like stone and mud, false for eg. trees
        getboolfield(L, index, "is_ground_content", f.is_ground_content);
@@ -395,6 +490,8 @@ ContentFeatures read_content_features(lua_State *L, int index)
        getboolfield(L, index, "climbable", f.climbable);
        // Player can build on these
        getboolfield(L, index, "buildable_to", f.buildable_to);
+       // Liquids flow into and replace node
+       getboolfield(L, index, "floodable", f.floodable);
        // Whether the node is non-liquid, source liquid or flowing liquid
        f.liquid_type = (LiquidType)getenumfield(L, index, "liquidtype",
                        ScriptApiNode::es_LiquidType, LIQUID_NONE);
@@ -414,12 +511,17 @@ ContentFeatures read_content_features(lua_State *L, int index)
        f.leveled = getintfield_default(L, index, "leveled", f.leveled);
 
        getboolfield(L, index, "liquid_renewable", f.liquid_renewable);
-       getstringfield(L, index, "freezemelt", f.freezemelt);
        f.drowning = getintfield_default(L, index,
                        "drowning", f.drowning);
        // Amount of light the node emits
        f.light_source = getintfield_default(L, index,
                        "light_source", f.light_source);
+       if (f.light_source > LIGHT_MAX) {
+               warningstream << "Node " << f.name.c_str()
+                       << " had greater light_source than " << LIGHT_MAX
+                       << ", it was reduced." << std::endl;
+               f.light_source = LIGHT_MAX;
+       }
        f.damage_per_second = getintfield_default(L, index,
                        "damage_per_second", f.damage_per_second);
 
@@ -428,6 +530,46 @@ ContentFeatures read_content_features(lua_State *L, int index)
                f.node_box = read_nodebox(L, -1);
        lua_pop(L, 1);
 
+       lua_getfield(L, index, "connects_to");
+       if (lua_istable(L, -1)) {
+               int table = lua_gettop(L);
+               lua_pushnil(L);
+               while (lua_next(L, table) != 0) {
+                       // Value at -1
+                       f.connects_to.push_back(lua_tostring(L, -1));
+                       lua_pop(L, 1);
+               }
+       }
+       lua_pop(L, 1);
+
+       lua_getfield(L, index, "connect_sides");
+       if (lua_istable(L, -1)) {
+               int table = lua_gettop(L);
+               lua_pushnil(L);
+               while (lua_next(L, table) != 0) {
+                       // Value at -1
+                       std::string side(lua_tostring(L, -1));
+                       // Note faces are flipped to make checking easier
+                       if (side == "top")
+                               f.connect_sides |= 2;
+                       else if (side == "bottom")
+                               f.connect_sides |= 1;
+                       else if (side == "front")
+                               f.connect_sides |= 16;
+                       else if (side == "left")
+                               f.connect_sides |= 32;
+                       else if (side == "back")
+                               f.connect_sides |= 4;
+                       else if (side == "right")
+                               f.connect_sides |= 8;
+                       else
+                               warningstream << "Unknown value for \"connect_sides\": "
+                                       << side << std::endl;
+                       lua_pop(L, 1);
+               }
+       }
+       lua_pop(L, 1);
+
        lua_getfield(L, index, "selection_box");
        if(lua_istable(L, -1))
                f.selection_box = read_nodebox(L, -1);
@@ -520,25 +662,31 @@ NodeBox read_nodebox(lua_State *L, int index)
                nodebox.type = (NodeBoxType)getenumfield(L, index, "type",
                                ScriptApiNode::es_NodeBoxType, NODEBOX_REGULAR);
 
-               lua_getfield(L, index, "fixed");
-               if(lua_istable(L, -1))
-                       nodebox.fixed = read_aabb3f_vector(L, -1, BS);
-               lua_pop(L, 1);
-
-               lua_getfield(L, index, "wall_top");
-               if(lua_istable(L, -1))
-                       nodebox.wall_top = read_aabb3f(L, -1, BS);
-               lua_pop(L, 1);
-
-               lua_getfield(L, index, "wall_bottom");
-               if(lua_istable(L, -1))
-                       nodebox.wall_bottom = read_aabb3f(L, -1, BS);
-               lua_pop(L, 1);
-
-               lua_getfield(L, index, "wall_side");
-               if(lua_istable(L, -1))
-                       nodebox.wall_side = read_aabb3f(L, -1, BS);
-               lua_pop(L, 1);
+#define NODEBOXREAD(n, s) \
+       do { \
+               lua_getfield(L, index, (s)); \
+               if (lua_istable(L, -1)) \
+                       (n) = read_aabb3f(L, -1, BS); \
+               lua_pop(L, 1); \
+       } while (0)
+
+#define NODEBOXREADVEC(n, s) \
+       do { \
+               lua_getfield(L, index, (s)); \
+               if (lua_istable(L, -1)) \
+                       (n) = read_aabb3f_vector(L, -1, BS); \
+               lua_pop(L, 1); \
+       } while (0)
+               NODEBOXREADVEC(nodebox.fixed, "fixed");
+               NODEBOXREAD(nodebox.wall_top, "wall_top");
+               NODEBOXREAD(nodebox.wall_bottom, "wall_bottom");
+               NODEBOXREAD(nodebox.wall_side, "wall_side");
+               NODEBOXREADVEC(nodebox.connect_top, "connect_top");
+               NODEBOXREADVEC(nodebox.connect_bottom, "connect_bottom");
+               NODEBOXREADVEC(nodebox.connect_front, "connect_front");
+               NODEBOXREADVEC(nodebox.connect_left, "connect_left");
+               NODEBOXREADVEC(nodebox.connect_back, "connect_back");
+               NODEBOXREADVEC(nodebox.connect_right, "connect_right");
        }
        return nodebox;
 }
@@ -547,22 +695,23 @@ NodeBox read_nodebox(lua_State *L, int index)
 MapNode readnode(lua_State *L, int index, INodeDefManager *ndef)
 {
        lua_getfield(L, index, "name");
-       const char *name = luaL_checkstring(L, -1);
+       if (!lua_isstring(L, -1))
+               throw LuaError("Node name is not set or is not a string!");
+       const char *name = lua_tostring(L, -1);
        lua_pop(L, 1);
-       u8 param1;
+
+       u8 param1 = 0;
        lua_getfield(L, index, "param1");
-       if(lua_isnil(L, -1))
-               param1 = 0;
-       else
+       if (!lua_isnil(L, -1))
                param1 = lua_tonumber(L, -1);
        lua_pop(L, 1);
-       u8 param2;
+
+       u8 param2 = 0;
        lua_getfield(L, index, "param2");
-       if(lua_isnil(L, -1))
-               param2 = 0;
-       else
+       if (!lua_isnil(L, -1))
                param2 = lua_tonumber(L, -1);
        lua_pop(L, 1);
+
        return MapNode(ndef, name, param1, param2);
 }
 
@@ -580,14 +729,13 @@ void pushnode(lua_State *L, const MapNode &n, INodeDefManager *ndef)
 
 /******************************************************************************/
 void warn_if_field_exists(lua_State *L, int table,
-               const char *fieldname, const std::string &message)
+               const char *name, const std::string &message)
 {
-       lua_getfield(L, table, fieldname);
-       if(!lua_isnil(L, -1)){
-//TODO find way to access backtrace fct from here
-               //              infostream<<script_get_backtrace(L)<<std::endl;
-               infostream<<"WARNING: field \""<<fieldname<<"\": "
-                               <<message<<std::endl;
+       lua_getfield(L, table, name);
+       if (!lua_isnil(L, -1)) {
+               warningstream << "Field \"" << name << "\": "
+                               << message << std::endl;
+               infostream << script_get_backtrace(L) << std::endl;
        }
        lua_pop(L, 1);
 }
@@ -646,7 +794,7 @@ ItemStack read_item(lua_State* L, int index,Server* srv)
                }
                catch(SerializationError &e)
                {
-                       infostream<<"WARNING: unable to create item from itemstring"
+                       warningstream<<"unable to create item from itemstring"
                                        <<": "<<itemstring<<std::endl;
                        return ItemStack();
                }
@@ -677,20 +825,18 @@ void push_tool_capabilities(lua_State *L,
                // Create groupcaps table
                lua_newtable(L);
                // For each groupcap
-               for(std::map<std::string, ToolGroupCap>::const_iterator
-                               i = toolcap.groupcaps.begin(); i != toolcap.groupcaps.end(); i++){
+               for (ToolGCMap::const_iterator i = toolcap.groupcaps.begin();
+                       i != toolcap.groupcaps.end(); i++) {
                        // Create groupcap table
                        lua_newtable(L);
                        const std::string &name = i->first;
                        const ToolGroupCap &groupcap = i->second;
                        // Create subtable "times"
                        lua_newtable(L);
-                       for(std::map<int, float>::const_iterator
-                                       i = groupcap.times.begin(); i != groupcap.times.end(); i++){
-                               int rating = i->first;
-                               float time = i->second;
-                               lua_pushinteger(L, rating);
-                               lua_pushnumber(L, time);
+                       for (UNORDERED_MAP<int, float>::const_iterator
+                                       i = groupcap.times.begin(); i != groupcap.times.end(); i++) {
+                               lua_pushinteger(L, i->first);
+                               lua_pushnumber(L, i->second);
                                lua_settable(L, -3);
                        }
                        // Set subtable "times"
@@ -706,8 +852,8 @@ void push_tool_capabilities(lua_State *L,
                //Create damage_groups table
                lua_newtable(L);
                // For each damage group
-               for(std::map<std::string, s16>::const_iterator
-                               i = toolcap.damageGroups.begin(); i != toolcap.damageGroups.end(); i++){
+               for (DamageGroup::const_iterator i = toolcap.damageGroups.begin();
+                       i != toolcap.damageGroups.end(); i++) {
                        // Create damage group table
                        lua_pushinteger(L, i->second);
                        lua_setfield(L, -2, i->first.c_str());
@@ -758,6 +904,41 @@ void read_inventory_list(lua_State *L, int tableindex,
        }
 }
 
+/******************************************************************************/
+struct TileAnimationParams read_animation_definition(lua_State *L, int index)
+{
+       if(index < 0)
+               index = lua_gettop(L) + 1 + index;
+
+       struct TileAnimationParams anim;
+       anim.type = TAT_NONE;
+       if (!lua_istable(L, index))
+               return anim;
+
+       anim.type = (TileAnimationType)
+               getenumfield(L, index, "type", es_TileAnimationType,
+               TAT_NONE);
+       if (anim.type == TAT_VERTICAL_FRAMES) {
+               // {type="vertical_frames", aspect_w=16, aspect_h=16, length=2.0}
+               anim.vertical_frames.aspect_w =
+                       getintfield_default(L, index, "aspect_w", 16);
+               anim.vertical_frames.aspect_h =
+                       getintfield_default(L, index, "aspect_h", 16);
+               anim.vertical_frames.length =
+                       getfloatfield_default(L, index, "length", 1.0);
+       } else if (anim.type == TAT_SHEET_2D) {
+               // {type="sheet_2d", frames_w=5, frames_h=3, frame_length=0.5}
+               getintfield(L, index, "frames_w",
+                       anim.sheet_2d.frames_w);
+               getintfield(L, index, "frames_h",
+                       anim.sheet_2d.frames_h);
+               getfloatfield(L, index, "frame_length",
+                       anim.sheet_2d.frame_length);
+       }
+
+       return anim;
+}
+
 /******************************************************************************/
 ToolCapabilities read_tool_capabilities(
                lua_State *L, int table)
@@ -781,14 +962,14 @@ ToolCapabilities read_tool_capabilities(
                                getintfield(L, table_groupcap, "uses", groupcap.uses);
                                // DEPRECATED: maxwear
                                float maxwear = 0;
-                               if(getfloatfield(L, table_groupcap, "maxwear", maxwear)){
-                                       if(maxwear != 0)
+                               if (getfloatfield(L, table_groupcap, "maxwear", maxwear)){
+                                       if (maxwear != 0)
                                                groupcap.uses = 1.0/maxwear;
                                        else
                                                groupcap.uses = 0;
-                                       infostream<<script_get_backtrace(L)<<std::endl;
-                                       infostream<<"WARNING: field \"maxwear\" is deprecated; "
-                                                       <<"should replace with uses=1/maxwear"<<std::endl;
+                                       warningstream << "Field \"maxwear\" is deprecated; "
+                                                       << "replace with uses=1/maxwear" << std::endl;
+                                       infostream << script_get_backtrace(L) << std::endl;
                                }
                                // Read "times" table
                                lua_getfield(L, table_groupcap, "times");
@@ -902,13 +1083,18 @@ u32 read_flags_table(lua_State *L, int table, FlagDesc *flagdesc, u32 *flagmask)
        return flags;
 }
 
+void push_flags_string(lua_State *L, FlagDesc *flagdesc, u32 flags, u32 flagmask)
+{
+       std::string flagstring = writeFlagString(flags, flagdesc, flagmask);
+       lua_pushlstring(L, flagstring.c_str(), flagstring.size());
+}
+
 /******************************************************************************/
 /* Lua Stored data!                                                           */
 /******************************************************************************/
 
 /******************************************************************************/
-void read_groups(lua_State *L, int index,
-               std::map<std::string, int> &result)
+void read_groups(lua_State *L, int index, ItemGroupList &result)
 {
        if (!lua_istable(L,index))
                return;
@@ -926,15 +1112,23 @@ void read_groups(lua_State *L, int index,
        }
 }
 
+/******************************************************************************/
+void push_groups(lua_State *L, const ItemGroupList &groups)
+{
+       lua_newtable(L);
+       for (ItemGroupList::const_iterator it = groups.begin(); it != groups.end(); ++it) {
+               lua_pushnumber(L, it->second);
+               lua_setfield(L, -2, it->first.c_str());
+       }
+}
+
 /******************************************************************************/
 void push_items(lua_State *L, const std::vector<ItemStack> &items)
 {
-       // Create and fill table
        lua_createtable(L, items.size(), 0);
-       std::vector<ItemStack>::const_iterator iter = items.begin();
-       for (u32 i = 0; iter != items.end(); iter++) {
-               LuaItemStack::create(L, *iter);
-               lua_rawseti(L, -2, ++i);
+       for (u32 i = 0; i != items.size(); i++) {
+               LuaItemStack::create(L, items[i]);
+               lua_rawseti(L, -2, i + 1);
        }
 }
 
@@ -975,18 +1169,6 @@ void luaentity_get(lua_State *L, u16 id)
 }
 
 /******************************************************************************/
-NoiseParams *get_noiseparams(lua_State *L, int index)
-{
-       NoiseParams *np = new NoiseParams;
-
-       if (!read_noiseparams(L, index, np)) {
-               delete np;
-               np = NULL;
-       }
-
-       return np;
-}
-
 bool read_noiseparams(lua_State *L, int index, NoiseParams *np)
 {
        if (index < 0)
@@ -995,14 +1177,16 @@ bool read_noiseparams(lua_State *L, int index, NoiseParams *np)
        if (!lua_istable(L, index))
                return false;
 
-       np->offset     = getfloatfield_default(L, index, "offset",     0.0);
-       np->scale      = getfloatfield_default(L, index, "scale",      0.0);
-       np->persist    = getfloatfield_default(L, index, "persist",    0.0);
-       np->lacunarity = getfloatfield_default(L, index, "lacunarity", 2.0);
-       np->seed       = getintfield_default(L,   index, "seed",       0);
-       np->octaves    = getintfield_default(L,   index, "octaves",    0);
+       getfloatfield(L, index, "offset",      np->offset);
+       getfloatfield(L, index, "scale",       np->scale);
+       getfloatfield(L, index, "persist",     np->persist);
+       getfloatfield(L, index, "persistence", np->persist);
+       getfloatfield(L, index, "lacunarity",  np->lacunarity);
+       getintfield(L,   index, "seed",        np->seed);
+       getintfield(L,   index, "octaves",     np->octaves);
 
-       u32 flags = 0, flagmask = 0;
+       u32 flags    = 0;
+       u32 flagmask = 0;
        np->flags = getflagsfield(L, index, "flags", flagdesc_noiseparams,
                &flags, &flagmask) ? flags : NOISE_FLAG_DEFAULTS;
 
@@ -1013,103 +1197,28 @@ bool read_noiseparams(lua_State *L, int index, NoiseParams *np)
        return true;
 }
 
-/******************************************************************************/
-
-bool get_schematic(lua_State *L, int index, Schematic *schem,
-       INodeDefManager *ndef, std::map<std::string, std::string> &replace_names)
-{
-       if (index < 0)
-               index = lua_gettop(L) + 1 + index;
-
-       if (lua_istable(L, index)) {
-               return read_schematic(L, index, schem, ndef, replace_names);
-       } else if (lua_isstring(L, index)) {
-               NodeResolver *resolver = ndef->getResolver();
-               const char *filename = lua_tostring(L, index);
-               return schem->loadSchematicFromFile(filename, resolver, replace_names);
-       } else {
-               return false;
-       }
-}
-
-bool read_schematic(lua_State *L, int index, Schematic *schem,
-       INodeDefManager *ndef, std::map<std::string, std::string> &replace_names)
+void push_noiseparams(lua_State *L, NoiseParams *np)
 {
-       //// Get schematic size
-       lua_getfield(L, index, "size");
-       v3s16 size = read_v3s16(L, -1);
-       lua_pop(L, 1);
-
-       //// Get schematic data
-       lua_getfield(L, index, "data");
-       luaL_checktype(L, -1, LUA_TTABLE);
-
-       int numnodes = size.X * size.Y * size.Z;
-       MapNode *schemdata = new MapNode[numnodes];
-       int i = 0;
-
-       lua_pushnil(L);
-       while (lua_next(L, -2)) {
-               if (i < numnodes) {
-                       // same as readnode, except param1 default is MTSCHEM_PROB_CONST
-                       lua_getfield(L, -1, "name");
-                       std::string name = luaL_checkstring(L, -1);
-                       lua_pop(L, 1);
-
-                       u8 param1;
-                       lua_getfield(L, -1, "param1");
-                       param1 = !lua_isnil(L, -1) ? lua_tonumber(L, -1) : MTSCHEM_PROB_ALWAYS;
-                       lua_pop(L, 1);
-
-                       u8 param2;
-                       lua_getfield(L, -1, "param2");
-                       param2 = !lua_isnil(L, -1) ? lua_tonumber(L, -1) : 0;
-                       lua_pop(L, 1);
-
-                       std::map<std::string, std::string>::iterator it;
-                       it = replace_names.find(name);
-                       if (it != replace_names.end())
-                               name = it->second;
-
-                       schemdata[i] = MapNode(ndef, name, param1, param2);
-               }
-
-               i++;
-               lua_pop(L, 1);
-       }
-
-       if (i != numnodes) {
-               errorstream << "read_schematic: incorrect number of "
-                       "nodes provided in raw schematic data (got " << i <<
-                       ", expected " << numnodes << ")." << std::endl;
-               return false;
-       }
-
-       //// Get Y-slice probability values (if present)
-       u8 *slice_probs = new u8[size.Y];
-       for (i = 0; i != size.Y; i++)
-               slice_probs[i] = MTSCHEM_PROB_ALWAYS;
-
-       lua_getfield(L, index, "yslice_prob");
-       if (lua_istable(L, -1)) {
-               lua_pushnil(L);
-               while (lua_next(L, -2)) {
-                       if (getintfield(L, -1, "ypos", i) && i >= 0 && i < size.Y) {
-                               slice_probs[i] = getintfield_default(L, -1,
-                                       "prob", MTSCHEM_PROB_ALWAYS);
-                       }
-                       lua_pop(L, 1);
-               }
-       }
-
-       // Here, we read the nodes directly from the INodeDefManager - there is no
-       // need for pending node resolutions so we'll mark this schematic as updated
-       schem->flags       = SCHEM_CIDS_UPDATED;
-
-       schem->size        = size;
-       schem->schemdata   = schemdata;
-       schem->slice_probs = slice_probs;
-       return true;
+       lua_newtable(L);
+       lua_pushnumber(L, np->offset);
+       lua_setfield(L, -2, "offset");
+       lua_pushnumber(L, np->scale);
+       lua_setfield(L, -2, "scale");
+       lua_pushnumber(L, np->persist);
+       lua_setfield(L, -2, "persistence");
+       lua_pushnumber(L, np->lacunarity);
+       lua_setfield(L, -2, "lacunarity");
+       lua_pushnumber(L, np->seed);
+       lua_setfield(L, -2, "seed");
+       lua_pushnumber(L, np->octaves);
+       lua_setfield(L, -2, "octaves");
+
+       push_flags_string(L, flagdesc_noiseparams, np->flags,
+               np->flags);
+       lua_setfield(L, -2, "flags");
+
+       push_v3f(L, np->spread);
+       lua_setfield(L, -2, "spread");
 }
 
 /******************************************************************************/
@@ -1167,8 +1276,13 @@ static bool push_json_value_helper(lua_State *L, const Json::Value &value,
                        lua_newtable(L);
                        for (Json::Value::const_iterator it = value.begin();
                                        it != value.end(); ++it) {
+#ifndef JSONCPP_STRING
                                const char *str = it.memberName();
                                lua_pushstring(L, str ? str : "");
+#else
+                               std::string str = it.name();
+                               lua_pushstring(L, str.c_str());
+#endif
                                push_json_value_helper(L, *it, nullindex);
                                lua_rawset(L, -3);
                        }
@@ -1243,4 +1357,3 @@ void read_json_value(lua_State *L, Json::Value &root, int index, u8 recursion)
        }
        lua_pop(L, 1); // Pop value
 }
-