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