]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/script/lua_api/l_object.cpp
Omnicleanup: header cleanup, add ModApiUtil shared between game and mainmenu
[dragonfireclient.git] / src / script / lua_api / l_object.cpp
index 6dec3db852566c3dc8473f2308b9bfd79e6be929..c0da79c2991accef2bfd7f84fefce57f3cc6b7fd 100644 (file)
@@ -17,13 +17,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
-#include "cpp_api/scriptapi.h"
-#include "common/c_converter.h"
-#include "common/c_content.h"
 #include "lua_api/l_object.h"
-#include "common/c_internal.h"
+#include "lua_api/l_internal.h"
 #include "lua_api/l_inventory.h"
 #include "lua_api/l_item.h"
+#include "common/c_converter.h"
+#include "common/c_content.h"
 #include "log.h"
 #include "tool.h"
 #include "serverobject.h"
@@ -62,6 +61,7 @@ struct EnumString es_HudBuiltinElement[] =
        {HUD_FLAG_HEALTHBAR_VISIBLE, "healthbar"},
        {HUD_FLAG_CROSSHAIR_VISIBLE, "crosshair"},
        {HUD_FLAG_WIELDITEM_VISIBLE, "wielditem"},
+       {HUD_FLAG_BREATHBAR_VISIBLE, "breathbar"},
        {0, NULL},
 };
 
@@ -274,7 +274,7 @@ int ObjectRef::l_get_inventory(lua_State *L)
        if(co == NULL) return 0;
        // Do it
        InventoryLocation loc = co->getInventoryLocation();
-       if(STACK_TO_SERVER(L)->getInventory(loc) != NULL)
+       if(getServer(L)->getInventory(loc) != NULL)
                InvRef::create(L, loc);
        else
                lua_pushnil(L); // An object may have no inventory (nil)
@@ -329,7 +329,7 @@ int ObjectRef::l_set_wielded_item(lua_State *L)
        ServerActiveObject *co = getobject(ref);
        if(co == NULL) return 0;
        // Do it
-       ItemStack item = read_item(L, 2,STACK_TO_SERVER(L));
+       ItemStack item = read_item(L, 2, getServer(L));
        bool success = co->setWieldedItem(item);
        lua_pushboolean(L, success);
        return 1;
@@ -701,6 +701,33 @@ int ObjectRef::l_set_look_yaw(lua_State *L)
        return 1;
 }
 
+// set_breath(self, breath)
+int ObjectRef::l_set_breath(lua_State *L)
+{
+       NO_MAP_LOCK_REQUIRED;
+       ObjectRef *ref = checkobject(L, 1);
+       PlayerSAO* co = getplayersao(ref);
+       if(co == NULL) return 0;
+       u16 breath = luaL_checknumber(L, 2);
+       // Do it
+       co->setBreath(breath);
+       co->m_breath_not_sent = true;
+       return 0;
+}
+
+// get_breath(self)
+int ObjectRef::l_get_breath(lua_State *L)
+{
+       NO_MAP_LOCK_REQUIRED;
+       ObjectRef *ref = checkobject(L, 1);
+       PlayerSAO* co = getplayersao(ref);
+       if(co == NULL) return 0;
+       // Do it
+       u16 breath = co->getBreath();
+       lua_pushinteger (L, breath);
+       return 1;
+}
+
 // set_inventory_formspec(self, formspec)
 int ObjectRef::l_set_inventory_formspec(lua_State *L)
 {
@@ -711,7 +738,7 @@ int ObjectRef::l_set_inventory_formspec(lua_State *L)
        std::string formspec = luaL_checkstring(L, 2);
 
        player->inventory_formspec = formspec;
-       STACK_TO_SERVER(L)->reportInventoryFormspecModified(player->getName());
+       getServer(L)->reportInventoryFormspecModified(player->getName());
        lua_pushboolean(L, true);
        return 1;
 }
@@ -813,7 +840,7 @@ int ObjectRef::l_hud_add(lua_State *L)
        elem->offset = lua_istable(L, -1) ? read_v2f(L, -1) : v2f();
        lua_pop(L, 1);
 
-       u32 id = STACK_TO_SERVER(L)->hudAdd(player, elem);
+       u32 id = getServer(L)->hudAdd(player, elem);
        if (id == (u32)-1) {
                delete elem;
                return 0;
@@ -835,7 +862,7 @@ int ObjectRef::l_hud_remove(lua_State *L)
        if (!lua_isnil(L, 2))
                id = lua_tonumber(L, 2);
 
-       if (!STACK_TO_SERVER(L)->hudRemove(player, id))
+       if (!getServer(L)->hudRemove(player, id))
                return 0;
 
        lua_pushboolean(L, true);
@@ -901,7 +928,7 @@ int ObjectRef::l_hud_change(lua_State *L)
                        value = &e->offset;
        }
 
-       STACK_TO_SERVER(L)->hudChange(player, id, stat, value);
+       getServer(L)->hudChange(player, id, stat, value);
 
        lua_pushboolean(L, true);
        return 1;
@@ -971,7 +998,24 @@ int ObjectRef::l_hud_set_flags(lua_State *L)
                        mask  |= esp[i].num;
                }
        }
-       if (!STACK_TO_SERVER(L)->hudSetFlags(player, flags, mask))
+       if (!getServer(L)->hudSetFlags(player, flags, mask))
+               return 0;
+
+       lua_pushboolean(L, true);
+       return 1;
+}
+
+// hud_set_hotbar_itemcount(self, hotbar_itemcount)
+int ObjectRef::l_hud_set_hotbar_itemcount(lua_State *L)
+{
+       ObjectRef *ref = checkobject(L, 1);
+       Player *player = getplayer(ref);
+       if (player == NULL)
+               return 0;
+
+       s32 hotbar_itemcount = lua_tonumber(L, 2);
+
+       if (!getServer(L)->hudSetHotbarItemcount(player, hotbar_itemcount))
                return 0;
 
        lua_pushboolean(L, true);
@@ -1080,6 +1124,8 @@ const luaL_reg ObjectRef::methods[] = {
        luamethod(ObjectRef, get_look_yaw),
        luamethod(ObjectRef, set_look_yaw),
        luamethod(ObjectRef, set_look_pitch),
+       luamethod(ObjectRef, get_breath),
+       luamethod(ObjectRef, set_breath),
        luamethod(ObjectRef, set_inventory_formspec),
        luamethod(ObjectRef, get_inventory_formspec),
        luamethod(ObjectRef, get_player_control),
@@ -1089,7 +1135,6 @@ const luaL_reg ObjectRef::methods[] = {
        luamethod(ObjectRef, hud_change),
        luamethod(ObjectRef, hud_get),
        luamethod(ObjectRef, hud_set_flags),
+       luamethod(ObjectRef, hud_set_hotbar_itemcount),
        {0,0}
 };
-
-REGISTER_LUA_REF(ObjectRef)