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