]> git.lizzy.rs Git - minetest.git/blob - src/itemdef.h
Dual wielding
[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 #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 #include "texture_override.h" // TextureOverride
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         std::string short_description;
60
61         /*
62                 Visual properties
63         */
64         std::string inventory_image; // Optional for nodes, mandatory for tools/craftitems
65         std::string inventory_overlay; // Overlay of inventory_image.
66         std::string wield_image; // If empty, inventory_image or mesh (only nodes) is used
67         std::string wield_overlay; // Overlay of wield_image.
68         std::string palette_image; // If specified, the item will be colorized based on this
69         video::SColor color; // The fallback color of the node.
70         v3f wield_scale;
71
72         /*
73                 Item stack and interaction properties
74         */
75         u16 stack_max;
76         bool usable;
77         bool liquids_pointable;
78         // May be NULL. If non-NULL, deleted by destructor
79         ToolCapabilities *tool_capabilities;
80         ItemGroupList groups;
81         SimpleSoundSpec sound_place;
82         SimpleSoundSpec sound_place_failed;
83         SimpleSoundSpec sound_use, sound_use_air;
84         f32 range;
85
86         // Client shall immediately place this node when player places the item.
87         // Server will update the precise end result a moment later.
88         // "" = no prediction
89         std::string node_placement_prediction;
90         u8 place_param2;
91         bool has_on_place;
92         bool has_on_secondary_use;
93
94         /*
95                 Some helpful methods
96         */
97         ItemDefinition();
98         ItemDefinition(const ItemDefinition &def);
99         ItemDefinition& operator=(const ItemDefinition &def);
100         ~ItemDefinition();
101         void reset();
102         void serialize(std::ostream &os, u16 protocol_version) const;
103         void deSerialize(std::istream &is, u16 protocol_version);
104 private:
105         void resetInitial();
106 };
107
108 class IItemDefManager
109 {
110 public:
111         IItemDefManager() = default;
112
113         virtual ~IItemDefManager() = default;
114
115         // Get item definition
116         virtual const ItemDefinition& get(const std::string &name) const=0;
117         // Get alias definition
118         virtual const std::string &getAlias(const std::string &name) const=0;
119         // Get set of all defined item names and aliases
120         virtual void getAll(std::set<std::string> &result) const=0;
121         // Check if item is known
122         virtual bool isKnown(const std::string &name) const=0;
123 #ifndef SERVER
124         // Get item inventory texture
125         virtual video::ITexture* getInventoryTexture(const std::string &name,
126                         Client *client) const=0;
127         // Get item wield mesh
128         virtual ItemMesh* getWieldMesh(const std::string &name,
129                 Client *client) const=0;
130         // Get item palette
131         virtual Palette* getPalette(const std::string &name,
132                 Client *client) const = 0;
133         // Returns the base color of an item stack: the color of all
134         // tiles that do not define their own color.
135         virtual video::SColor getItemstackColor(const ItemStack &stack,
136                 Client *client) const = 0;
137 #endif
138
139         virtual void serialize(std::ostream &os, u16 protocol_version)=0;
140 };
141
142 class IWritableItemDefManager : public IItemDefManager
143 {
144 public:
145         IWritableItemDefManager() = default;
146
147         virtual ~IWritableItemDefManager() = default;
148
149         // Get item definition
150         virtual const ItemDefinition& get(const std::string &name) const=0;
151         // Get alias definition
152         virtual const std::string &getAlias(const std::string &name) const=0;
153         // Get set of all defined item names and aliases
154         virtual void getAll(std::set<std::string> &result) const=0;
155         // Check if item is known
156         virtual bool isKnown(const std::string &name) const=0;
157 #ifndef SERVER
158         // Get item inventory texture
159         virtual video::ITexture* getInventoryTexture(const std::string &name,
160                         Client *client) const=0;
161         // Get item wield mesh
162         virtual ItemMesh* getWieldMesh(const std::string &name,
163                 Client *client) const=0;
164 #endif
165
166         // Replace the textures of registered nodes with the ones specified in
167         // the texture pack's override.txt files
168         virtual void applyTextureOverrides(const std::vector<TextureOverride> &overrides)=0;
169
170         // Remove all registered item and node definitions and aliases
171         // Then re-add the builtin item definitions
172         virtual void clear()=0;
173         // Register item definition
174         virtual void registerItem(const ItemDefinition &def)=0;
175         virtual void unregisterItem(const std::string &name)=0;
176         // Set an alias so that items named <name> will load as <convert_to>.
177         // Alias is not set if <name> has already been defined.
178         // Alias will be removed if <name> is defined at a later point of time.
179         virtual void registerAlias(const std::string &name,
180                         const std::string &convert_to)=0;
181
182         virtual void serialize(std::ostream &os, u16 protocol_version)=0;
183         virtual void deSerialize(std::istream &is, u16 protocol_version)=0;
184
185         // Do stuff asked by threads that can only be done in the main thread
186         virtual void processQueue(IGameDef *gamedef)=0;
187 };
188
189 IWritableItemDefManager* createItemDefManager();