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