]> git.lizzy.rs Git - dragonfireclient.git/blob - src/script/lua_api/l_item.h
Omnicleanup: header cleanup, add ModApiUtil shared between game and mainmenu
[dragonfireclient.git] / src / script / lua_api / l_item.h
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef L_ITEM_H_
21 #define L_ITEM_H_
22
23 #include "lua_api/l_base.h"
24 #include "inventory.h"  // ItemStack
25
26 class LuaItemStack : public ModApiBase {
27 private:
28         ItemStack m_stack;
29
30         static const char className[];
31         static const luaL_reg methods[];
32
33         // Exported functions
34
35         // garbage collector
36         static int gc_object(lua_State *L);
37
38         // is_empty(self) -> true/false
39         static int l_is_empty(lua_State *L);
40
41         // get_name(self) -> string
42         static int l_get_name(lua_State *L);
43
44         // get_count(self) -> number
45         static int l_get_count(lua_State *L);
46
47         // get_wear(self) -> number
48         static int l_get_wear(lua_State *L);
49
50         // get_metadata(self) -> string
51         static int l_get_metadata(lua_State *L);
52
53         // clear(self) -> true
54         static int l_clear(lua_State *L);
55
56         // replace(self, itemstack or itemstring or table or nil) -> true
57         static int l_replace(lua_State *L);
58
59         // to_string(self) -> string
60         static int l_to_string(lua_State *L);
61
62         // to_table(self) -> table or nil
63         static int l_to_table(lua_State *L);
64
65         // get_stack_max(self) -> number
66         static int l_get_stack_max(lua_State *L);
67
68         // get_free_space(self) -> number
69         static int l_get_free_space(lua_State *L);
70
71         // is_known(self) -> true/false
72         // Checks if the item is defined.
73         static int l_is_known(lua_State *L);
74
75         // get_definition(self) -> table
76         // Returns the item definition table from minetest.registered_items,
77         // or a fallback one (name="unknown")
78         static int l_get_definition(lua_State *L);
79
80         // get_tool_capabilities(self) -> table
81         // Returns the effective tool digging properties.
82         // Returns those of the hand ("") if this item has none associated.
83         static int l_get_tool_capabilities(lua_State *L);
84
85         // add_wear(self, amount) -> true/false
86         // The range for "amount" is [0,65535]. Wear is only added if the item
87         // is a tool. Adding wear might destroy the item.
88         // Returns true if the item is (or was) a tool.
89         static int l_add_wear(lua_State *L);
90
91         // add_item(self, itemstack or itemstring or table or nil) -> itemstack
92         // Returns leftover item stack
93         static int l_add_item(lua_State *L);
94
95         // item_fits(self, itemstack or itemstring or table or nil) -> true/false, itemstack
96         // First return value is true iff the new item fits fully into the stack
97         // Second return value is the would-be-left-over item stack
98         static int l_item_fits(lua_State *L);
99
100         // take_item(self, takecount=1) -> itemstack
101         static int l_take_item(lua_State *L);
102
103         // peek_item(self, peekcount=1) -> itemstack
104         static int l_peek_item(lua_State *L);
105
106 public:
107         LuaItemStack(const ItemStack &item);
108         ~LuaItemStack();
109
110         const ItemStack& getItem() const;
111         ItemStack& getItem();
112
113         // LuaItemStack(itemstack or itemstring or table or nil)
114         // Creates an LuaItemStack and leaves it on top of stack
115         static int create_object(lua_State *L);
116         // Not callable from Lua
117         static int create(lua_State *L, const ItemStack &item);
118         static LuaItemStack* checkobject(lua_State *L, int narg);
119         static void Register(lua_State *L);
120
121 };
122
123 class ModApiItemMod : public ModApiBase {
124 private:
125         static int l_register_item_raw(lua_State *L);
126         static int l_register_alias_raw(lua_State *L);
127         static int l_get_content_id(lua_State *L);
128         static int l_get_name_from_content_id(lua_State *L);
129 public:
130         static void Initialize(lua_State *L, int top);
131 };
132
133
134
135 #endif /* L_ITEM_H_ */