]> git.lizzy.rs Git - minetest.git/blob - src/itemdef.h
New damage system, add damageGroups to ToolCapabilities, bump protocol version
[minetest.git] / src / itemdef.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2013 Kahrl <kahrl@gmx.net>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #ifndef ITEMDEF_HEADER
22 #define ITEMDEF_HEADER
23
24 #include "irrlichttypes_extrabloated.h"
25 #include <string>
26 #include <iostream>
27 #include <set>
28 #include "itemgroup.h"
29 class IGameDef;
30 struct ToolCapabilities;
31
32 /*
33         Base item definition
34 */
35
36 enum ItemType
37 {
38         ITEM_NONE,
39         ITEM_NODE,
40         ITEM_CRAFT,
41         ITEM_TOOL,
42 };
43
44 struct ItemDefinition
45 {
46         /*
47                 Basic item properties
48         */
49         ItemType type;
50         std::string name; // "" = hand
51         std::string description; // Shown in tooltip.
52
53         /*
54                 Visual properties
55         */
56         std::string inventory_image; // Optional for nodes, mandatory for tools/craftitems
57         std::string wield_image; // If empty, inventory_image or mesh (only nodes) is used
58         v3f wield_scale;
59
60         /*
61                 Item stack and interaction properties
62         */
63         s16 stack_max;
64         bool usable;
65         bool liquids_pointable;
66         // May be NULL. If non-NULL, deleted by destructor
67         ToolCapabilities *tool_capabilities;
68         ItemGroupList groups;
69
70         // Client shall immediately place this node when player places the item.
71         // Server will update the precise end result a moment later.
72         // "" = no prediction
73         std::string node_placement_prediction;
74
75         /*
76                 Some helpful methods
77         */
78         ItemDefinition();
79         ItemDefinition(const ItemDefinition &def);
80         ItemDefinition& operator=(const ItemDefinition &def);
81         ~ItemDefinition();
82         void reset();
83         void serialize(std::ostream &os, u16 protocol_version) const;
84         void deSerialize(std::istream &is);
85 private:
86         void resetInitial();
87 };
88
89 class IItemDefManager
90 {
91 public:
92         IItemDefManager(){}
93         virtual ~IItemDefManager(){}
94
95         // Get item definition
96         virtual const ItemDefinition& get(const std::string &name) const=0;
97         // Get alias definition
98         virtual std::string getAlias(const std::string &name) const=0;
99         // Get set of all defined item names and aliases
100         virtual std::set<std::string> getAll() const=0;
101         // Check if item is known
102         virtual bool isKnown(const std::string &name) const=0;
103 #ifndef SERVER
104         // Get item inventory texture
105         virtual video::ITexture* getInventoryTexture(const std::string &name,
106                         IGameDef *gamedef) const=0;
107         // Get item wield mesh
108         virtual scene::IMesh* getWieldMesh(const std::string &name,
109                 IGameDef *gamedef) const=0;
110 #endif
111
112         virtual void serialize(std::ostream &os, u16 protocol_version)=0;
113 };
114
115 class IWritableItemDefManager : public IItemDefManager
116 {
117 public:
118         IWritableItemDefManager(){}
119         virtual ~IWritableItemDefManager(){}
120
121         // Get item definition
122         virtual const ItemDefinition& get(const std::string &name) const=0;
123         // Get alias definition
124         virtual std::string getAlias(const std::string &name) const=0;
125         // Get set of all defined item names and aliases
126         virtual std::set<std::string> getAll() const=0;
127         // Check if item is known
128         virtual bool isKnown(const std::string &name) const=0;
129 #ifndef SERVER
130         // Get item inventory texture
131         virtual video::ITexture* getInventoryTexture(const std::string &name,
132                         IGameDef *gamedef) const=0;
133         // Get item wield mesh
134         virtual scene::IMesh* getWieldMesh(const std::string &name,
135                 IGameDef *gamedef) const=0;
136 #endif
137
138         // Remove all registered item and node definitions and aliases
139         // Then re-add the builtin item definitions
140         virtual void clear()=0;
141         // Register item definition
142         virtual void registerItem(const ItemDefinition &def)=0;
143         // Set an alias so that items named <name> will load as <convert_to>.
144         // Alias is not set if <name> has already been defined.
145         // Alias will be removed if <name> is defined at a later point of time.
146         virtual void registerAlias(const std::string &name,
147                         const std::string &convert_to)=0;
148
149         virtual void serialize(std::ostream &os, u16 protocol_version)=0;
150         virtual void deSerialize(std::istream &is)=0;
151
152         // Do stuff asked by threads that can only be done in the main thread
153         virtual void processQueue(IGameDef *gamedef)=0;
154 };
155
156 IWritableItemDefManager* createItemDefManager();
157
158 #endif