]> git.lizzy.rs Git - dragonfireclient.git/blob - src/script/lua_api/l_itemstackmeta.h
Consistent HP and damage types (#8167)
[dragonfireclient.git] / src / script / lua_api / l_itemstackmeta.h
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2017-8 rubenwardy <rw@rubenwardy.com>
5 Copyright (C) 2017 raymoo
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22 #pragma once
23
24 #include "lua_api/l_base.h"
25 #include "lua_api/l_metadata.h"
26 #include "irrlichttypes_bloated.h"
27 #include "inventory.h"
28
29 class ItemStackMetaRef : public MetaDataRef
30 {
31 private:
32         ItemStack *istack = nullptr;
33
34         static const char className[];
35         static const luaL_Reg methods[];
36
37         static ItemStackMetaRef *checkobject(lua_State *L, int narg);
38
39         virtual Metadata* getmeta(bool auto_create);
40
41         virtual void clearMeta();
42
43         virtual void reportMetadataChange(const std::string *name = nullptr);
44
45         void setToolCapabilities(const ToolCapabilities &caps)
46         {
47                 istack->metadata.setToolCapabilities(caps);
48         }
49
50         void clearToolCapabilities()
51         {
52                 istack->metadata.clearToolCapabilities();
53         }
54
55         // Exported functions
56         static int l_set_tool_capabilities(lua_State *L);
57
58         // garbage collector
59         static int gc_object(lua_State *L);
60 public:
61         ItemStackMetaRef(ItemStack *istack): istack(istack) {}
62         ~ItemStackMetaRef() = default;
63
64         // Creates an ItemStackMetaRef and leaves it on top of stack
65         // Not callable from Lua; all references are created on the C side.
66         static void create(lua_State *L, ItemStack *istack);
67
68         static void Register(lua_State *L);
69 };