3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2013 Kahrl <kahrl@gmx.net>
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.
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.
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.
23 #include "irrlichttypes_extrabloated.h"
27 #include "itemgroup.h"
29 #include "texture_override.h" // TextureOverride
32 struct ToolCapabilities;
34 #include "client/tile.h"
57 std::string name; // "" = hand
58 std::string description; // Shown in tooltip.
59 std::string short_description;
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.
73 Item stack and interaction properties
77 bool liquids_pointable;
78 // May be NULL. If non-NULL, deleted by destructor
79 ToolCapabilities *tool_capabilities;
81 SimpleSoundSpec sound_place;
82 SimpleSoundSpec sound_place_failed;
83 SimpleSoundSpec sound_use, sound_use_air;
86 // Client shall immediately place this node when player places the item.
87 // Server will update the precise end result a moment later.
89 std::string node_placement_prediction;
96 ItemDefinition(const ItemDefinition &def);
97 ItemDefinition& operator=(const ItemDefinition &def);
100 void serialize(std::ostream &os, u16 protocol_version) const;
101 void deSerialize(std::istream &is, u16 protocol_version);
106 class IItemDefManager
109 IItemDefManager() = default;
111 virtual ~IItemDefManager() = default;
113 // Get item definition
114 virtual const ItemDefinition& get(const std::string &name) const=0;
115 // Get alias definition
116 virtual const std::string &getAlias(const std::string &name) const=0;
117 // Get set of all defined item names and aliases
118 virtual void getAll(std::set<std::string> &result) const=0;
119 // Check if item is known
120 virtual bool isKnown(const std::string &name) const=0;
122 // Get item inventory texture
123 virtual video::ITexture* getInventoryTexture(const std::string &name,
124 Client *client) const=0;
125 // Get item wield mesh
126 virtual ItemMesh* getWieldMesh(const std::string &name,
127 Client *client) const=0;
129 virtual Palette* getPalette(const std::string &name,
130 Client *client) const = 0;
131 // Returns the base color of an item stack: the color of all
132 // tiles that do not define their own color.
133 virtual video::SColor getItemstackColor(const ItemStack &stack,
134 Client *client) const = 0;
137 virtual void serialize(std::ostream &os, u16 protocol_version)=0;
140 class IWritableItemDefManager : public IItemDefManager
143 IWritableItemDefManager() = default;
145 virtual ~IWritableItemDefManager() = default;
147 // Get item definition
148 virtual const ItemDefinition& get(const std::string &name) const=0;
149 // Get alias definition
150 virtual const std::string &getAlias(const std::string &name) const=0;
151 // Get set of all defined item names and aliases
152 virtual void getAll(std::set<std::string> &result) const=0;
153 // Check if item is known
154 virtual bool isKnown(const std::string &name) const=0;
156 // Get item inventory texture
157 virtual video::ITexture* getInventoryTexture(const std::string &name,
158 Client *client) const=0;
159 // Get item wield mesh
160 virtual ItemMesh* getWieldMesh(const std::string &name,
161 Client *client) const=0;
164 // Replace the textures of registered nodes with the ones specified in
165 // the texture pack's override.txt files
166 virtual void applyTextureOverrides(const std::vector<TextureOverride> &overrides)=0;
168 // Remove all registered item and node definitions and aliases
169 // Then re-add the builtin item definitions
170 virtual void clear()=0;
171 // Register item definition
172 virtual void registerItem(const ItemDefinition &def)=0;
173 virtual void unregisterItem(const std::string &name)=0;
174 // Set an alias so that items named <name> will load as <convert_to>.
175 // Alias is not set if <name> has already been defined.
176 // Alias will be removed if <name> is defined at a later point of time.
177 virtual void registerAlias(const std::string &name,
178 const std::string &convert_to)=0;
180 virtual void serialize(std::ostream &os, u16 protocol_version)=0;
181 virtual void deSerialize(std::istream &is, u16 protocol_version)=0;
183 // Do stuff asked by threads that can only be done in the main thread
184 virtual void processQueue(IGameDef *gamedef)=0;
187 IWritableItemDefManager* createItemDefManager();