]> git.lizzy.rs Git - minetest.git/blob - src/itemdef.h
Fix -Wterminate warning on GCC 6
[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 #include "sound.h"
30 class IGameDef;
31 struct ToolCapabilities;
32
33 /*
34         Base item definition
35 */
36
37 enum ItemType
38 {
39         ITEM_NONE,
40         ITEM_NODE,
41         ITEM_CRAFT,
42         ITEM_TOOL,
43 };
44
45 struct ItemDefinition
46 {
47         /*
48                 Basic item properties
49         */
50         ItemType type;
51         std::string name; // "" = hand
52         std::string description; // Shown in tooltip.
53
54         /*
55                 Visual properties
56         */
57         std::string inventory_image; // Optional for nodes, mandatory for tools/craftitems
58         std::string wield_image; // If empty, inventory_image or mesh (only nodes) is used
59         v3f wield_scale;
60
61         /*
62                 Item stack and interaction properties
63         */
64         s16 stack_max;
65         bool usable;
66         bool liquids_pointable;
67         // May be NULL. If non-NULL, deleted by destructor
68         ToolCapabilities *tool_capabilities;
69         ItemGroupList groups;
70         SimpleSoundSpec sound_place;
71         SimpleSoundSpec sound_place_failed;
72         f32 range;
73
74         // Client shall immediately place this node when player places the item.
75         // Server will update the precise end result a moment later.
76         // "" = no prediction
77         std::string node_placement_prediction;
78
79         /*
80                 Some helpful methods
81         */
82         ItemDefinition();
83         ItemDefinition(const ItemDefinition &def);
84         ItemDefinition& operator=(const ItemDefinition &def);
85         ~ItemDefinition();
86         void reset();
87         void serialize(std::ostream &os, u16 protocol_version) const;
88         void deSerialize(std::istream &is);
89 private:
90         void resetInitial();
91 };
92
93 class IItemDefManager
94 {
95 public:
96         IItemDefManager(){}
97         virtual ~IItemDefManager(){}
98
99         // Get item definition
100         virtual const ItemDefinition& get(const std::string &name) const=0;
101         // Get alias definition
102         virtual std::string getAlias(const std::string &name) const=0;
103         // Get set of all defined item names and aliases
104         virtual std::set<std::string> getAll() const=0;
105         // Check if item is known
106         virtual bool isKnown(const std::string &name) const=0;
107 #ifndef SERVER
108         // Get item inventory texture
109         virtual video::ITexture* getInventoryTexture(const std::string &name,
110                         IGameDef *gamedef) const=0;
111         // Get item wield mesh
112         virtual scene::IMesh* getWieldMesh(const std::string &name,
113                 IGameDef *gamedef) const=0;
114 #endif
115
116         virtual void serialize(std::ostream &os, u16 protocol_version)=0;
117 };
118
119 class IWritableItemDefManager : public IItemDefManager
120 {
121 public:
122         IWritableItemDefManager(){}
123         virtual ~IWritableItemDefManager(){}
124
125         // Get item definition
126         virtual const ItemDefinition& get(const std::string &name) const=0;
127         // Get alias definition
128         virtual std::string getAlias(const std::string &name) const=0;
129         // Get set of all defined item names and aliases
130         virtual std::set<std::string> getAll() const=0;
131         // Check if item is known
132         virtual bool isKnown(const std::string &name) const=0;
133 #ifndef SERVER
134         // Get item inventory texture
135         virtual video::ITexture* getInventoryTexture(const std::string &name,
136                         IGameDef *gamedef) const=0;
137         // Get item wield mesh
138         virtual scene::IMesh* getWieldMesh(const std::string &name,
139                 IGameDef *gamedef) const=0;
140 #endif
141
142         // Remove all registered item and node definitions and aliases
143         // Then re-add the builtin item definitions
144         virtual void clear()=0;
145         // Register item definition
146         virtual void registerItem(const ItemDefinition &def)=0;
147         // Set an alias so that items named <name> will load as <convert_to>.
148         // Alias is not set if <name> has already been defined.
149         // Alias will be removed if <name> is defined at a later point of time.
150         virtual void registerAlias(const std::string &name,
151                         const std::string &convert_to)=0;
152
153         virtual void serialize(std::ostream &os, u16 protocol_version)=0;
154         virtual void deSerialize(std::istream &is)=0;
155
156         // Do stuff asked by threads that can only be done in the main thread
157         virtual void processQueue(IGameDef *gamedef)=0;
158 };
159
160 IWritableItemDefManager* createItemDefManager();
161
162 #endif