]> git.lizzy.rs Git - minetest.git/blobdiff - src/script/common/c_content.cpp
Dual wielding
[minetest.git] / src / script / common / c_content.cpp
index 52baeae9d5c5758f0a0cd698e045b3c66ff923f8..8b03f091044e8bb0a0d5fa1559dee9cbca98ffcf 100644 (file)
@@ -42,7 +42,7 @@ struct EnumString es_TileAnimationType[] =
        {TAT_NONE, "none"},
        {TAT_VERTICAL_FRAMES, "vertical_frames"},
        {TAT_SHEET_2D, "sheet_2d"},
-       {0, NULL},
+       {0, nullptr},
 };
 
 /******************************************************************************/
@@ -81,6 +81,16 @@ void read_item_definition(lua_State* L, int index,
        def.usable = lua_isfunction(L, -1);
        lua_pop(L, 1);
 
+       lua_pushstring(L, "on_place");
+       lua_rawget(L, index);
+       def.has_on_place = lua_isfunction(L, -1);
+       lua_pop(L, 1);
+
+       lua_pushstring(L, "on_secondary_use");
+       lua_rawget(L, index);
+       def.has_on_secondary_use = lua_isfunction(L, -1);
+       lua_pop(L, 1);
+
        getboolfield(L, index, "liquids_pointable", def.liquids_pointable);
 
        lua_getfield(L, index, "tool_capabilities");
@@ -112,6 +122,19 @@ void read_item_definition(lua_State* L, int index,
        }
        lua_pop(L, 1);
 
+       // No, this is not a mistake. Item sounds are in "sound", node sounds in "sounds".
+       lua_getfield(L, index, "sound");
+       if (!lua_isnil(L, -1)) {
+               luaL_checktype(L, -1, LUA_TTABLE);
+               lua_getfield(L, -1, "punch_use");
+               read_soundspec(L, -1, def.sound_use);
+               lua_pop(L, 1);
+               lua_getfield(L, -1, "punch_use_air");
+               read_soundspec(L, -1, def.sound_use_air);
+               lua_pop(L, 1);
+       }
+       lua_pop(L, 1);
+
        def.range = getfloatfield_default(L, index, "range", def.range);
 
        // Client shall immediately place this node when player places the item.
@@ -196,12 +219,13 @@ void read_object_properties(lua_State *L, int index,
        int hp_max = 0;
        if (getintfield(L, -1, "hp_max", hp_max)) {
                prop->hp_max = (u16)rangelim(hp_max, 0, U16_MAX);
+               // hp_max = 0 is sometimes used as a hack to keep players dead, only validate for entities
+               if (prop->hp_max == 0 && sao->getType() != ACTIVEOBJECT_TYPE_PLAYER)
+                       throw LuaError("The hp_max property may not be 0 for entities!");
 
                if (prop->hp_max < sao->getHP()) {
-                       PlayerHPChangeReason reason(PlayerHPChangeReason::SET_HP);
+                       PlayerHPChangeReason reason(PlayerHPChangeReason::SET_HP_MAX);
                        sao->setHP(prop->hp_max, reason);
-                       if (sao->getType() == ACTIVEOBJECT_TYPE_PLAYER)
-                               sao->getEnv()->getGameDef()->SendPlayerHPOrDie((PlayerSAO *)sao, reason);
                }
        }
 
@@ -222,10 +246,12 @@ void read_object_properties(lua_State *L, int index,
        lua_pop(L, 1);
 
        lua_getfield(L, -1, "selectionbox");
-       if (lua_istable(L, -1))
+       if (lua_istable(L, -1)) {
+               getboolfield(L, -1, "rotate", prop->rotate_selectionbox);
                prop->selectionbox = read_aabb3f(L, -1, 1.0);
-       else if (collisionbox_defined)
+       } else if (collisionbox_defined) {
                prop->selectionbox = prop->collisionbox;
+       }
        lua_pop(L, 1);
 
        getboolfield(L, -1, "pointable", prop->pointable);
@@ -363,6 +389,8 @@ void push_object_properties(lua_State *L, ObjectProperties *prop)
        push_aabb3f(L, prop->collisionbox);
        lua_setfield(L, -2, "collisionbox");
        push_aabb3f(L, prop->selectionbox);
+       lua_pushboolean(L, prop->rotate_selectionbox);
+       lua_setfield(L, -2, "rotate");
        lua_setfield(L, -2, "selectionbox");
        lua_pushboolean(L, prop->pointable);
        lua_setfield(L, -2, "pointable");
@@ -444,7 +472,7 @@ void push_object_properties(lua_State *L, ObjectProperties *prop)
 }
 
 /******************************************************************************/
-TileDef read_tiledef(lua_State *L, int index, u8 drawtype)
+TileDef read_tiledef(lua_State *L, int index, u8 drawtype, bool special)
 {
        if(index < 0)
                index = lua_gettop(L) + 1 + index;
@@ -455,7 +483,6 @@ TileDef read_tiledef(lua_State *L, int index, u8 drawtype)
        bool default_culling = true;
        switch (drawtype) {
                case NDT_PLANTLIKE:
-               case NDT_PLANTLIKE_ROOTED:
                case NDT_FIRELIKE:
                        default_tiling = false;
                        // "break" is omitted here intentionaly, as PLANTLIKE
@@ -465,6 +492,10 @@ TileDef read_tiledef(lua_State *L, int index, u8 drawtype)
                case NDT_LIQUID:
                        default_culling = false;
                        break;
+               case NDT_PLANTLIKE_ROOTED:
+                       default_tiling = !special;
+                       default_culling = !special;
+                       break;
                default:
                        break;
        }
@@ -480,7 +511,7 @@ TileDef read_tiledef(lua_State *L, int index, u8 drawtype)
        else if(lua_istable(L, index))
        {
                // name="default_lava.png"
-               tiledef.name = "";
+               tiledef.name.clear();
                getstringfield(L, index, "name", tiledef.name);
                getstringfield(L, index, "image", tiledef.name); // MaterialSpec compat.
                tiledef.backface_culling = getboolfield_default(
@@ -552,20 +583,13 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index)
 
        // tiles = {}
        lua_getfield(L, index, "tiles");
-       // If nil, try the deprecated name "tile_images" instead
-       if(lua_isnil(L, -1)){
-               lua_pop(L, 1);
-               warn_if_field_exists(L, index, "tile_images",
-                               "Deprecated; new name is \"tiles\".");
-               lua_getfield(L, index, "tile_images");
-       }
        if(lua_istable(L, -1)){
                int table = lua_gettop(L);
                lua_pushnil(L);
                int i = 0;
                while(lua_next(L, table) != 0){
                        // Read tiledef from value
-                       f.tiledef[i] = read_tiledef(L, -1, f.drawtype);
+                       f.tiledef[i] = read_tiledef(L, -1, f.drawtype, false);
                        // removes value, keeps key for next iteration
                        lua_pop(L, 1);
                        i++;
@@ -593,7 +617,7 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index)
                int i = 0;
                while (lua_next(L, table) != 0) {
                        // Read tiledef from value
-                       f.tiledef_overlay[i] = read_tiledef(L, -1, f.drawtype);
+                       f.tiledef_overlay[i] = read_tiledef(L, -1, f.drawtype, false);
                        // removes value, keeps key for next iteration
                        lua_pop(L, 1);
                        i++;
@@ -615,20 +639,13 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index)
 
        // special_tiles = {}
        lua_getfield(L, index, "special_tiles");
-       // If nil, try the deprecated name "special_materials" instead
-       if(lua_isnil(L, -1)){
-               lua_pop(L, 1);
-               warn_if_field_exists(L, index, "special_materials",
-                               "Deprecated; new name is \"special_tiles\".");
-               lua_getfield(L, index, "special_materials");
-       }
        if(lua_istable(L, -1)){
                int table = lua_gettop(L);
                lua_pushnil(L);
                int i = 0;
                while(lua_next(L, table) != 0){
                        // Read tiledef from value
-                       f.tiledef_special[i] = read_tiledef(L, -1, f.drawtype);
+                       f.tiledef_special[i] = read_tiledef(L, -1, f.drawtype, true);
                        // removes value, keeps key for next iteration
                        lua_pop(L, 1);
                        i++;
@@ -686,7 +703,8 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index)
                        !(f.param_type_2 == CPT2_COLOR ||
                        f.param_type_2 == CPT2_COLORED_FACEDIR ||
                        f.param_type_2 == CPT2_COLORED_WALLMOUNTED ||
-                       f.param_type_2 == CPT2_COLORED_DEGROTATE))
+                       f.param_type_2 == CPT2_COLORED_DEGROTATE ||
+                       f.param_type_2 == CPT2_COLORED_4DIR))
                warningstream << "Node " << f.name.c_str()
                        << " has a palette, but not a suitable paramtype2." << std::endl;
 
@@ -721,6 +739,9 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index)
        // the slowest possible
        f.liquid_viscosity = getintfield_default(L, index,
                        "liquid_viscosity", f.liquid_viscosity);
+       // If move_resistance is not set explicitly,
+       // move_resistance is equal to liquid_viscosity
+       f.move_resistance = f.liquid_viscosity;
        f.liquid_range = getintfield_default(L, index,
                        "liquid_range", f.liquid_range);
        f.leveled = getintfield_default(L, index, "leveled", f.leveled);
@@ -824,6 +845,21 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index)
        getstringfield(L, index, "node_dig_prediction",
                f.node_dig_prediction);
 
+       // How much the node slows down players, ranging from 1 to 7,
+       // the higher, the slower.
+       f.move_resistance = getintfield_default(L, index,
+                       "move_resistance", f.move_resistance);
+
+       // Whether e.g. players in this node will have liquid movement physics
+       lua_getfield(L, index, "liquid_move_physics");
+       if(lua_isboolean(L, -1)) {
+               f.liquid_move_physics = lua_toboolean(L, -1);
+       } else if(lua_isnil(L, -1)) {
+               f.liquid_move_physics = f.liquid_type != LIQUID_NONE;
+       } else {
+               errorstream << "Field \"liquid_move_physics\": Invalid type!" << std::endl;
+       }
+       lua_pop(L, 1);
 }
 
 void push_content_features(lua_State *L, const ContentFeatures &c)
@@ -951,6 +987,10 @@ void push_content_features(lua_State *L, const ContentFeatures &c)
        lua_setfield(L, -2, "legacy_wallmounted");
        lua_pushstring(L, c.node_dig_prediction.c_str());
        lua_setfield(L, -2, "node_dig_prediction");
+       lua_pushnumber(L, c.move_resistance);
+       lua_setfield(L, -2, "move_resistance");
+       lua_pushboolean(L, c.liquid_move_physics);
+       lua_setfield(L, -2, "liquid_move_physics");
 }
 
 /******************************************************************************/
@@ -980,22 +1020,25 @@ void push_nodebox(lua_State *L, const NodeBox &box)
                        push_aabb3f(L, box.wall_side);
                        lua_setfield(L, -2, "wall_side");
                        break;
-               case NODEBOX_CONNECTED:
+               case NODEBOX_CONNECTED: {
                        lua_pushstring(L, "connected");
                        lua_setfield(L, -2, "type");
-                       push_box(L, box.connect_top);
+                       const auto &c = box.getConnected();
+                       push_box(L, c.connect_top);
                        lua_setfield(L, -2, "connect_top");
-                       push_box(L, box.connect_bottom);
+                       push_box(L, c.connect_bottom);
                        lua_setfield(L, -2, "connect_bottom");
-                       push_box(L, box.connect_front);
+                       push_box(L, c.connect_front);
                        lua_setfield(L, -2, "connect_front");
-                       push_box(L, box.connect_back);
+                       push_box(L, c.connect_back);
                        lua_setfield(L, -2, "connect_back");
-                       push_box(L, box.connect_left);
+                       push_box(L, c.connect_left);
                        lua_setfield(L, -2, "connect_left");
-                       push_box(L, box.connect_right);
+                       push_box(L, c.connect_right);
                        lua_setfield(L, -2, "connect_right");
+                       // half the boxes are missing here?
                        break;
+               }
                default:
                        FATAL_ERROR("Invalid box.type");
                        break;
@@ -1028,37 +1071,40 @@ void push_palette(lua_State *L, const std::vector<video::SColor> *palette)
 
 /******************************************************************************/
 void read_server_sound_params(lua_State *L, int index,
-               ServerSoundParams &params)
+               ServerPlayingSound &params)
 {
        if(index < 0)
                index = lua_gettop(L) + 1 + index;
-       // Clear
-       params = ServerSoundParams();
+
        if(lua_istable(L, index)){
+               // Functional overlap: this may modify SimpleSoundSpec contents
+               getfloatfield(L, index, "fade", params.spec.fade);
+               getfloatfield(L, index, "pitch", params.spec.pitch);
+               getboolfield(L, index, "loop", params.spec.loop);
+
                getfloatfield(L, index, "gain", params.gain);
+
+               // Handle positional information
                getstringfield(L, index, "to_player", params.to_player);
-               getfloatfield(L, index, "fade", params.fade);
-               getfloatfield(L, index, "pitch", params.pitch);
                lua_getfield(L, index, "pos");
                if(!lua_isnil(L, -1)){
                        v3f p = read_v3f(L, -1)*BS;
                        params.pos = p;
-                       params.type = ServerSoundParams::SSP_POSITIONAL;
+                       params.type = SoundLocation::Position;
                }
                lua_pop(L, 1);
                lua_getfield(L, index, "object");
                if(!lua_isnil(L, -1)){
-                       ObjectRef *ref = ObjectRef::checkobject(L, -1);
+                       ObjectRef *ref = ModApiBase::checkObject<ObjectRef>(L, -1);
                        ServerActiveObject *sao = ObjectRef::getobject(ref);
                        if(sao){
                                params.object = sao->getId();
-                               params.type = ServerSoundParams::SSP_OBJECT;
+                               params.type = SoundLocation::Object;
                        }
                }
                lua_pop(L, 1);
                params.max_hear_distance = BS*getfloatfield_default(L, index,
                                "max_hear_distance", params.max_hear_distance/BS);
-               getboolfield(L, index, "loop", params.loop);
                getstringfield(L, index, "exclude_player", params.exclude_player);
        }
 }
@@ -1123,62 +1169,50 @@ NodeBox read_nodebox(lua_State *L, int index)
        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");
-       NODEBOXREADVEC(nodebox.disconnected_top, "disconnected_top");
-       NODEBOXREADVEC(nodebox.disconnected_bottom, "disconnected_bottom");
-       NODEBOXREADVEC(nodebox.disconnected_front, "disconnected_front");
-       NODEBOXREADVEC(nodebox.disconnected_left, "disconnected_left");
-       NODEBOXREADVEC(nodebox.disconnected_back, "disconnected_back");
-       NODEBOXREADVEC(nodebox.disconnected_right, "disconnected_right");
-       NODEBOXREADVEC(nodebox.disconnected, "disconnected");
-       NODEBOXREADVEC(nodebox.disconnected_sides, "disconnected_sides");
+
+       if (nodebox.type == NODEBOX_CONNECTED) {
+               auto &c = nodebox.getConnected();
+               NODEBOXREADVEC(c.connect_top, "connect_top");
+               NODEBOXREADVEC(c.connect_bottom, "connect_bottom");
+               NODEBOXREADVEC(c.connect_front, "connect_front");
+               NODEBOXREADVEC(c.connect_left, "connect_left");
+               NODEBOXREADVEC(c.connect_back, "connect_back");
+               NODEBOXREADVEC(c.connect_right, "connect_right");
+               NODEBOXREADVEC(c.disconnected_top, "disconnected_top");
+               NODEBOXREADVEC(c.disconnected_bottom, "disconnected_bottom");
+               NODEBOXREADVEC(c.disconnected_front, "disconnected_front");
+               NODEBOXREADVEC(c.disconnected_left, "disconnected_left");
+               NODEBOXREADVEC(c.disconnected_back, "disconnected_back");
+               NODEBOXREADVEC(c.disconnected_right, "disconnected_right");
+               NODEBOXREADVEC(c.disconnected, "disconnected");
+               NODEBOXREADVEC(c.disconnected_sides, "disconnected_sides");
+       }
 
        return nodebox;
 }
 
 /******************************************************************************/
-MapNode readnode(lua_State *L, int index, const NodeDefManager *ndef)
+MapNode readnode(lua_State *L, int index)
 {
-       lua_getfield(L, index, "name");
-       if (!lua_isstring(L, -1))
-               throw LuaError("Node name is not set or is not a string!");
-       std::string name = lua_tostring(L, -1);
-       lua_pop(L, 1);
-
-       u8 param1 = 0;
-       lua_getfield(L, index, "param1");
-       if (!lua_isnil(L, -1))
-               param1 = lua_tonumber(L, -1);
-       lua_pop(L, 1);
-
-       u8 param2 = 0;
-       lua_getfield(L, index, "param2");
-       if (!lua_isnil(L, -1))
-               param2 = lua_tonumber(L, -1);
-       lua_pop(L, 1);
-
-       content_t id = CONTENT_IGNORE;
-       if (!ndef->getId(name, id))
-               throw LuaError("\"" + name + "\" is not a registered node!");
-
-       return {id, param1, param2};
+       lua_pushvalue(L, index);
+       lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_READ_NODE);
+       lua_insert(L, -2);
+       lua_call(L, 1, 3);
+       content_t content = lua_tointeger(L, -3);
+       u8 param1 = lua_tointeger(L, -2);
+       u8 param2 = lua_tointeger(L, -1);
+       lua_pop(L, 3);
+       return MapNode(content, param1, param2);
 }
 
 /******************************************************************************/
-void pushnode(lua_State *L, const MapNode &n, const NodeDefManager *ndef)
+void pushnode(lua_State *L, const MapNode &n)
 {
-       lua_createtable(L, 0, 3);
-       lua_pushstring(L, ndef->get(n).name.c_str());
-       lua_setfield(L, -2, "name");
+       lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_PUSH_NODE);
+       lua_pushinteger(L, n.getContent());
        lua_pushinteger(L, n.getParam1());
-       lua_setfield(L, -2, "param1");
        lua_pushinteger(L, n.getParam2());
-       lua_setfield(L, -2, "param2");
+       lua_call(L, 3, 1);
 }
 
 /******************************************************************************/
@@ -1231,7 +1265,7 @@ ItemStack read_item(lua_State* L, int index, IItemDefManager *idef)
 
        if (lua_isuserdata(L, index)) {
                // Convert from LuaItemStack
-               LuaItemStack *o = LuaItemStack::checkobject(L, index);
+               LuaItemStack *o = ModApiBase::checkObject<LuaItemStack>(L, index);
                return o->getItem();
        }
 
@@ -1331,45 +1365,52 @@ void push_tool_capabilities(lua_State *L,
 }
 
 /******************************************************************************/
-void push_inventory_list(lua_State *L, Inventory *inv, const char *name)
+void push_inventory_list(lua_State *L, const InventoryList &invlist)
 {
-       InventoryList *invlist = inv->getList(name);
-       if(invlist == NULL){
-               lua_pushnil(L);
-               return;
+       push_items(L, invlist.getItems());
+}
+
+/******************************************************************************/
+void push_inventory_lists(lua_State *L, const Inventory &inv)
+{
+       const auto &lists = inv.getLists();
+       lua_createtable(L, 0, lists.size());
+       for(const InventoryList *list : lists) {
+               const std::string &name = list->getName();
+               lua_pushlstring(L, name.c_str(), name.size());
+               push_inventory_list(L, *list);
+               lua_rawset(L, -3);
        }
-       std::vector<ItemStack> items;
-       for(u32 i=0; i<invlist->getSize(); i++)
-               items.push_back(invlist->getItem(i));
-       push_items(L, items);
 }
 
 /******************************************************************************/
 void read_inventory_list(lua_State *L, int tableindex,
-               Inventory *inv, const char *name, Server* srv, int forcesize)
+               Inventory *inv, const char *name, IGameDef *gdef, int forcesize)
 {
        if(tableindex < 0)
                tableindex = lua_gettop(L) + 1 + tableindex;
+
        // If nil, delete list
        if(lua_isnil(L, tableindex)){
                inv->deleteList(name);
                return;
        }
-       // Otherwise set list
-       std::vector<ItemStack> items = read_items(L, tableindex,srv);
-       int listsize = (forcesize != -1) ? forcesize : items.size();
+
+       // Get Lua-specified items to insert into the list
+       std::vector<ItemStack> items = read_items(L, tableindex, gdef);
+       size_t listsize = (forcesize >= 0) ? forcesize : items.size();
+
+       // Create or resize/clear list
        InventoryList *invlist = inv->addList(name, listsize);
-       int index = 0;
-       for(std::vector<ItemStack>::const_iterator
-                       i = items.begin(); i != items.end(); ++i){
-               if(forcesize != -1 && index == forcesize)
-                       break;
-               invlist->changeItem(index, *i);
-               index++;
+       if (!invlist) {
+               luaL_error(L, "inventory list: cannot create list named '%s'", name);
+               return;
        }
-       while(forcesize != -1 && index < forcesize){
-               invlist->deleteItem(index);
-               index++;
+
+       for (size_t i = 0; i < items.size(); ++i) {
+               if (i == listsize)
+                       break; // Truncate provided list of items
+               invlist->changeItem(i, items[i]);
        }
 }
 
@@ -1608,7 +1649,7 @@ void push_items(lua_State *L, const std::vector<ItemStack> &items)
 }
 
 /******************************************************************************/
-std::vector<ItemStack> read_items(lua_State *L, int index, Server *srv)
+std::vector<ItemStack> read_items(lua_State *L, int index, IGameDef *gdef)
 {
        if(index < 0)
                index = lua_gettop(L) + 1 + index;
@@ -1624,7 +1665,7 @@ std::vector<ItemStack> read_items(lua_State *L, int index, Server *srv)
                if (items.size() < (u32) key) {
                        items.resize(key);
                }
-               items[key - 1] = read_item(L, -1, srv->idef());
+               items[key - 1] = read_item(L, -1, gdef->idef());
                lua_pop(L, 1);
        }
        return items;
@@ -1675,24 +1716,19 @@ bool read_noiseparams(lua_State *L, int index, NoiseParams *np)
 void push_noiseparams(lua_State *L, NoiseParams *np)
 {
        lua_newtable(L);
-       push_float_string(L, np->offset);
-       lua_setfield(L, -2, "offset");
-       push_float_string(L, np->scale);
-       lua_setfield(L, -2, "scale");
-       push_float_string(L, np->persist);
-       lua_setfield(L, -2, "persistence");
-       push_float_string(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");
+       setfloatfield(L, -1, "offset",      np->offset);
+       setfloatfield(L, -1, "scale",       np->scale);
+       setfloatfield(L, -1, "persist",     np->persist);
+       setfloatfield(L, -1, "persistence", np->persist);
+       setfloatfield(L, -1, "lacunarity",  np->lacunarity);
+       setintfield(  L, -1, "seed",        np->seed);
+       setintfield(  L, -1, "octaves",     np->octaves);
 
        push_flags_string(L, flagdesc_noiseparams, np->flags,
                np->flags);
        lua_setfield(L, -2, "flags");
 
-       push_v3_float_string(L, np->spread);
+       push_v3f(L, np->spread);
        lua_setfield(L, -2, "spread");
 }
 
@@ -1861,7 +1897,7 @@ void push_pointed_thing(lua_State *L, const PointedThing &pointed, bool csm,
        if (hitpoint && (pointed.type != POINTEDTHING_NOTHING)) {
                push_v3f(L, pointed.intersection_point / BS); // convert to node coords
                lua_setfield(L, -2, "intersection_point");
-               push_v3s16(L, pointed.intersection_normal);
+               push_v3f(L, pointed.intersection_normal);
                lua_setfield(L, -2, "intersection_normal");
                lua_pushinteger(L, pointed.box_id + 1); // change to Lua array index
                lua_setfield(L, -2, "box_id");
@@ -1926,6 +1962,8 @@ void read_hud_element(lua_State *L, HudElement *elem)
        elem->world_pos = lua_istable(L, -1) ? read_v3f(L, -1) : v3f();
        lua_pop(L, 1);
 
+       elem->style = getintfield_default(L, 2, "style", 0);
+
        /* check for known deprecated element usage */
        if ((elem->type  == HUD_ELEM_STATBAR) && (elem->size == v2s32()))
                log_deprecated(L,"Deprecated usage of statbar without size!");
@@ -1953,6 +1991,12 @@ void push_hud_element(lua_State *L, HudElement *elem)
        lua_pushnumber(L, elem->number);
        lua_setfield(L, -2, "number");
 
+       if (elem->type == HUD_ELEM_WAYPOINT) {
+               // waypoints reuse the item field to store precision, precision = item - 1
+               lua_pushnumber(L, elem->item - 1);
+               lua_setfield(L, -2, "precision");
+       }
+       // push the item field for waypoints as well for backwards compatibility
        lua_pushnumber(L, elem->item);
        lua_setfield(L, -2, "item");
 
@@ -1980,17 +2024,22 @@ void push_hud_element(lua_State *L, HudElement *elem)
 
        lua_pushstring(L, elem->text2.c_str());
        lua_setfield(L, -2, "text2");
+
+       lua_pushinteger(L, elem->style);
+       lua_setfield(L, -2, "style");
 }
 
-HudElementStat read_hud_change(lua_State *L, HudElement *elem, void **value)
+bool read_hud_change(lua_State *L, HudElementStat &stat, HudElement *elem, void **value)
 {
-       HudElementStat stat = HUD_STAT_NUMBER;
-       std::string statstr;
-       if (lua_isstring(L, 3)) {
+       std::string statstr = lua_tostring(L, 3);
+       {
                int statint;
-               statstr = lua_tostring(L, 3);
-               stat = string_to_enum(es_HudElementStat, statint, statstr) ?
-                               (HudElementStat)statint : stat;
+               if (!string_to_enum(es_HudElementStat, statint, statstr)) {
+                       script_log_unique(L, "Unknown HUD stat type: " + statstr, warningstream);
+                       return false;
+               }
+
+               stat = (HudElementStat)statint;
        }
 
        switch (stat) {
@@ -2048,8 +2097,13 @@ HudElementStat read_hud_change(lua_State *L, HudElement *elem, void **value)
                        elem->text2 = luaL_checkstring(L, 4);
                        *value = &elem->text2;
                        break;
+               case HUD_STAT_STYLE:
+                       elem->style = luaL_checknumber(L, 4);
+                       *value = &elem->style;
+                       break;
        }
-       return stat;
+
+       return true;
 }
 
 /******************************************************************************/
@@ -2107,3 +2161,35 @@ void push_collision_move_result(lua_State *L, const collisionMoveResult &res)
        lua_setfield(L, -2, "collisions");
        /**/
 }
+
+
+void push_mod_spec(lua_State *L, const ModSpec &spec, bool include_unsatisfied)
+{
+       lua_newtable(L);
+
+       lua_pushstring(L, spec.name.c_str());
+       lua_setfield(L, -2, "name");
+
+       lua_pushstring(L, spec.author.c_str());
+       lua_setfield(L, -2, "author");
+
+       lua_pushinteger(L, spec.release);
+       lua_setfield(L, -2, "release");
+
+       lua_pushstring(L, spec.desc.c_str());
+       lua_setfield(L, -2, "description");
+
+       lua_pushstring(L, spec.path.c_str());
+       lua_setfield(L, -2, "path");
+
+       lua_pushstring(L, spec.virtual_path.c_str());
+       lua_setfield(L, -2, "virtual_path");
+
+       lua_newtable(L);
+       int i = 1;
+       for (const auto &dep : spec.unsatisfied_depends) {
+               lua_pushstring(L, dep.c_str());
+               lua_rawseti(L, -2, i++);
+       }
+       lua_setfield(L, -2, "unsatisfied_depends");
+}