]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/script/common/c_content.cpp
Merge branch 'master' of https://github.com/minetest/minetest
[dragonfireclient.git] / src / script / common / c_content.cpp
index dac828316552825eaffa32052e8e1e0947a4e77b..72361bdb528b98f45c154e3e4d8d5f31caef01b3 100644 (file)
@@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "object_properties.h"
 #include "collision.h"
 #include "cpp_api/s_node.h"
+#include "lua_api/l_clientobject.h"
 #include "lua_api/l_object.h"
 #include "lua_api/l_item.h"
 #include "common/c_internal.h"
@@ -56,6 +57,7 @@ void read_item_definition(lua_State* L, int index,
                        es_ItemType, ITEM_NONE);
        getstringfield(L, index, "name", def.name);
        getstringfield(L, index, "description", def.description);
+       getstringfield(L, index, "short_description", def.short_description);
        getstringfield(L, index, "inventory_image", def.inventory_image);
        getstringfield(L, index, "inventory_overlay", def.inventory_overlay);
        getstringfield(L, index, "wield_image", def.wield_image);
@@ -142,6 +144,8 @@ void push_item_definition_full(lua_State *L, const ItemDefinition &i)
        lua_setfield(L, -2, "name");
        lua_pushstring(L, i.description.c_str());
        lua_setfield(L, -2, "description");
+       lua_pushstring(L, i.short_description.c_str());
+       lua_setfield(L, -2, "short_description");
        lua_pushstring(L, type.c_str());
        lua_setfield(L, -2, "type");
        lua_pushstring(L, i.inventory_image.c_str());
@@ -164,16 +168,18 @@ void push_item_definition_full(lua_State *L, const ItemDefinition &i)
        lua_setfield(L, -2, "usable");
        lua_pushboolean(L, i.liquids_pointable);
        lua_setfield(L, -2, "liquids_pointable");
-       if (i.type == ITEM_TOOL) {
+       if (i.tool_capabilities) {
                push_tool_capabilities(L, *i.tool_capabilities);
                lua_setfield(L, -2, "tool_capabilities");
        }
        push_groups(L, i.groups);
        lua_setfield(L, -2, "groups");
+       lua_newtable(L);
        push_soundspec(L, i.sound_place);
-       lua_setfield(L, -2, "sound_place");
+       lua_setfield(L, -2, "place");
        push_soundspec(L, i.sound_place_failed);
-       lua_setfield(L, -2, "sound_place_failed");
+       lua_setfield(L, -2, "place_failed");
+       lua_setfield(L, -2, "sounds");
        lua_pushstring(L, i.node_placement_prediction.c_str());
        lua_setfield(L, -2, "node_placement_prediction");
 }
@@ -327,6 +333,10 @@ void read_object_properties(lua_State *L, int index,
 
        getfloatfield(L, -1, "zoom_fov", prop->zoom_fov);
        getboolfield(L, -1, "use_texture_alpha", prop->use_texture_alpha);
+       getboolfield(L, -1, "shaded", prop->shaded);
+       getboolfield(L, -1, "show_on_minimap", prop->show_on_minimap);
+
+       getstringfield(L, -1, "damage_texture_modifier", prop->damage_texture_modifier);
 }
 
 /******************************************************************************/
@@ -409,6 +419,12 @@ void push_object_properties(lua_State *L, ObjectProperties *prop)
        lua_setfield(L, -2, "zoom_fov");
        lua_pushboolean(L, prop->use_texture_alpha);
        lua_setfield(L, -2, "use_texture_alpha");
+       lua_pushboolean(L, prop->shaded);
+       lua_setfield(L, -2, "shaded");
+       lua_pushlstring(L, prop->damage_texture_modifier.c_str(), prop->damage_texture_modifier.size());
+       lua_setfield(L, -2, "damage_texture_modifier");
+       lua_pushboolean(L, prop->show_on_minimap);
+       lua_setfield(L, -2, "show_on_minimap");
 }
 
 /******************************************************************************/
@@ -481,13 +497,11 @@ TileDef read_tiledef(lua_State *L, int index, u8 drawtype)
 }
 
 /******************************************************************************/
-ContentFeatures read_content_features(lua_State *L, int index)
+void read_content_features(lua_State *L, ContentFeatures &f, int index)
 {
        if(index < 0)
                index = lua_gettop(L) + 1 + index;
 
-       ContentFeatures f;
-
        /* Cache existence of some callbacks */
        lua_getfield(L, index, "on_construct");
        if(!lua_isnil(L, -1)) f.has_on_construct = true;
@@ -690,6 +704,8 @@ ContentFeatures read_content_features(lua_State *L, int index)
        f.liquid_range = getintfield_default(L, index,
                        "liquid_range", f.liquid_range);
        f.leveled = getintfield_default(L, index, "leveled", f.leveled);
+       f.leveled_max = getintfield_default(L, index,
+                       "leveled_max", f.leveled_max);
 
        getboolfield(L, index, "liquid_renewable", f.liquid_renewable);
        f.drowning = getintfield_default(L, index,
@@ -788,7 +804,6 @@ ContentFeatures read_content_features(lua_State *L, int index)
        getstringfield(L, index, "node_dig_prediction",
                f.node_dig_prediction);
 
-       return f;
 }
 
 void push_content_features(lua_State *L, const ContentFeatures &c)
@@ -856,6 +871,8 @@ void push_content_features(lua_State *L, const ContentFeatures &c)
        lua_setfield(L, -2, "post_effect_color");
        lua_pushnumber(L, c.leveled);
        lua_setfield(L, -2, "leveled");
+       lua_pushnumber(L, c.leveled_max);
+       lua_setfield(L, -2, "leveled_max");
        lua_pushboolean(L, c.sunlight_propagates);
        lua_setfield(L, -2, "sunlight_propagates");
        lua_pushnumber(L, c.light_source);
@@ -902,11 +919,11 @@ void push_content_features(lua_State *L, const ContentFeatures &c)
        lua_setfield(L, -2, "collision_box");
        lua_newtable(L);
        push_soundspec(L, c.sound_footstep);
-       lua_setfield(L, -2, "sound_footstep");
+       lua_setfield(L, -2, "footstep");
        push_soundspec(L, c.sound_dig);
-       lua_setfield(L, -2, "sound_dig");
+       lua_setfield(L, -2, "dig");
        push_soundspec(L, c.sound_dug);
-       lua_setfield(L, -2, "sound_dug");
+       lua_setfield(L, -2, "dug");
        lua_setfield(L, -2, "sounds");
        lua_pushboolean(L, c.legacy_facedir_simple);
        lua_setfield(L, -2, "legacy_facedir_simple");
@@ -1294,17 +1311,17 @@ void push_tool_capabilities(lua_State *L,
 }
 
 /******************************************************************************/
-void push_inventory_list(lua_State *L, Inventory *inv, const char *name)
+void push_inventory(lua_State *L, Inventory *inventory)
 {
-       InventoryList *invlist = inv->getList(name);
-       if(invlist == NULL){
-               lua_pushnil(L);
-               return;
+       std::vector<const InventoryList*> lists = inventory->getLists();
+       std::vector<const InventoryList*>::iterator iter = lists.begin();
+       lua_createtable(L, 0, lists.size());
+       for (; iter != lists.end(); iter++) {
+               const char* name = (*iter)->getName().c_str();
+               lua_pushstring(L, name);
+               push_inventory_list(L, inventory, name);
+               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);
 }
 
 /******************************************************************************/
@@ -1336,6 +1353,19 @@ void read_inventory_list(lua_State *L, int tableindex,
        }
 }
 
+void push_inventory_list(lua_State *L, Inventory *inv, const char *name)
+{
+       InventoryList *invlist = inv->getList(name);
+       if(invlist == NULL){
+               lua_pushnil(L);
+               return;
+       }
+       std::vector<ItemStack> items;
+       for(u32 i=0; i<invlist->getSize(); i++)
+               items.push_back(invlist->getItem(i));
+       push_items(L, items);
+}
+
 /******************************************************************************/
 struct TileAnimationParams read_animation_definition(lua_State *L, int index)
 {
@@ -1371,6 +1401,29 @@ struct TileAnimationParams read_animation_definition(lua_State *L, int index)
        return anim;
 }
 
+void push_animation_definition(lua_State *L, struct TileAnimationParams anim)
+{
+       switch (anim.type) {
+       case TAT_NONE:
+               lua_pushnil(L);
+               break;
+       case TAT_VERTICAL_FRAMES:
+               lua_newtable(L);
+               setstringfield(L, -1, "type", "vertical_frames");
+               setfloatfield(L, -1, "aspect_w", anim.vertical_frames.aspect_w);
+               setfloatfield(L, -1, "aspect_h", anim.vertical_frames.aspect_h);
+               setfloatfield(L, -1, "length", anim.vertical_frames.length);
+               break;
+       case TAT_SHEET_2D:
+               lua_newtable(L);
+               setstringfield(L, -1, "type", "sheet_2d");
+               setintfield(L, -1, "frames_w", anim.sheet_2d.frames_w);
+               setintfield(L, -1, "frames_h", anim.sheet_2d.frames_h);
+               setintfield(L, -1, "frame_length", anim.sheet_2d.frame_length);
+               break;
+       }
+}
+
 /******************************************************************************/
 ToolCapabilities read_tool_capabilities(
                lua_State *L, int table)
@@ -1809,14 +1862,15 @@ void push_pointed_thing(lua_State *L, const PointedThing &pointed, bool csm,
        } else if (pointed.type == POINTEDTHING_OBJECT) {
                lua_pushstring(L, "object");
                lua_setfield(L, -2, "type");
-
                if (csm) {
-                       lua_pushinteger(L, pointed.object_id);
-                       lua_setfield(L, -2, "id");
+#ifndef SERVER
+                       ClientObjectRef::create(L, pointed.object_id);
+#endif
                } else {
                        push_objectRef(L, pointed.object_id);
-                       lua_setfield(L, -2, "ref");
                }
+               
+               lua_setfield(L, -2, "ref");
        } else {
                lua_pushstring(L, "nothing");
                lua_setfield(L, -2, "type");
@@ -1871,6 +1925,7 @@ void read_hud_element(lua_State *L, HudElement *elem)
        elem->dir     = getintfield_default(L, 2, "direction", 0);
        elem->z_index = MYMAX(S16_MIN, MYMIN(S16_MAX,
                        getintfield_default(L, 2, "z_index", 0)));
+       elem->text2   = getstringfield_default(L, 2, "text2", "");
 
        // Deprecated, only for compatibility's sake
        if (elem->dir == 0)
@@ -1939,14 +1994,18 @@ void push_hud_element(lua_State *L, HudElement *elem)
 
        lua_pushnumber(L, elem->z_index);
        lua_setfield(L, -2, "z_index");
+
+       lua_pushstring(L, elem->text2.c_str());
+       lua_setfield(L, -2, "text2");
 }
 
 HudElementStat read_hud_change(lua_State *L, HudElement *elem, void **value)
 {
        HudElementStat stat = HUD_STAT_NUMBER;
+       std::string statstr;
        if (lua_isstring(L, 3)) {
                int statint;
-               std::string statstr = lua_tostring(L, 3);
+               statstr = lua_tostring(L, 3);
                stat = string_to_enum(es_HudElementStat, statint, statstr) ?
                                (HudElementStat)statint : stat;
        }
@@ -1974,6 +2033,8 @@ HudElementStat read_hud_change(lua_State *L, HudElement *elem, void **value)
                        break;
                case HUD_STAT_ITEM:
                        elem->item = luaL_checknumber(L, 4);
+                       if (elem->type == HUD_ELEM_WAYPOINT && statstr == "precision")
+                               elem->item++;
                        *value = &elem->item;
                        break;
                case HUD_STAT_DIR:
@@ -2000,6 +2061,10 @@ HudElementStat read_hud_change(lua_State *L, HudElement *elem, void **value)
                        elem->z_index = MYMAX(S16_MIN, MYMIN(S16_MAX, luaL_checknumber(L, 4)));
                        *value = &elem->z_index;
                        break;
+               case HUD_STAT_TEXT2:
+                       elem->text2 = luaL_checkstring(L, 4);
+                       *value = &elem->text2;
+                       break;
        }
        return stat;
 }
@@ -2059,3 +2124,27 @@ void push_collision_move_result(lua_State *L, const collisionMoveResult &res)
        lua_setfield(L, -2, "collisions");
        /**/
 }
+
+/******************************************************************************/
+void push_physics_override(lua_State *L, float speed, float jump, float gravity, bool sneak, bool sneak_glitch, bool new_move)
+{
+       lua_createtable(L, 0, 6);
+       
+       lua_pushnumber(L, speed);
+       lua_setfield(L, -2, "speed");
+
+       lua_pushnumber(L, jump);
+       lua_setfield(L, -2, "jump");
+
+       lua_pushnumber(L, gravity);
+       lua_setfield(L, -2, "gravity");
+
+       lua_pushboolean(L, sneak);
+       lua_setfield(L, -2, "sneak");
+
+       lua_pushboolean(L, sneak_glitch);
+       lua_setfield(L, -2, "sneak_glitch");
+
+       lua_pushboolean(L, new_move);
+       lua_setfield(L, -2, "new_move");
+}