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"
31 struct ToolCapabilities;
33 #include "client/tile.h"
56 std::string name; // "" = hand
57 std::string description; // Shown in tooltip.
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.
69 Item stack and interaction properties
73 bool liquids_pointable;
74 // May be NULL. If non-NULL, deleted by destructor
75 ToolCapabilities *tool_capabilities;
77 SimpleSoundSpec sound_place;
78 SimpleSoundSpec sound_place_failed;
81 // Client shall immediately place this node when player places the item.
82 // Server will update the precise end result a moment later.
84 std::string node_placement_prediction;
90 ItemDefinition(const ItemDefinition &def);
91 ItemDefinition& operator=(const ItemDefinition &def);
94 void serialize(std::ostream &os, u16 protocol_version) const;
95 void deSerialize(std::istream &is);
100 class IItemDefManager
103 IItemDefManager() = default;
105 virtual ~IItemDefManager() = default;
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;
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;
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;
131 virtual void serialize(std::ostream &os, u16 protocol_version)=0;
134 class IWritableItemDefManager : public IItemDefManager
137 IWritableItemDefManager() = default;
139 virtual ~IWritableItemDefManager() = default;
141 // Get item definition
142 virtual const ItemDefinition& get(const std::string &name) const=0;
143 // Get alias definition
144 virtual const std::string &getAlias(const std::string &name) const=0;
145 // Get set of all defined item names and aliases
146 virtual void getAll(std::set<std::string> &result) const=0;
147 // Check if item is known
148 virtual bool isKnown(const std::string &name) const=0;
150 // Get item inventory texture
151 virtual video::ITexture* getInventoryTexture(const std::string &name,
152 Client *client) const=0;
153 // Get item wield mesh
154 virtual ItemMesh* getWieldMesh(const std::string &name,
155 Client *client) const=0;
158 // Remove all registered item and node definitions and aliases
159 // Then re-add the builtin item definitions
160 virtual void clear()=0;
161 // Register item definition
162 virtual void registerItem(const ItemDefinition &def)=0;
163 virtual void unregisterItem(const std::string &name)=0;
164 // Set an alias so that items named <name> will load as <convert_to>.
165 // Alias is not set if <name> has already been defined.
166 // Alias will be removed if <name> is defined at a later point of time.
167 virtual void registerAlias(const std::string &name,
168 const std::string &convert_to)=0;
170 virtual void serialize(std::ostream &os, u16 protocol_version)=0;
171 virtual void deSerialize(std::istream &is)=0;
173 // Do stuff asked by threads that can only be done in the main thread
174 virtual void processQueue(IGameDef *gamedef)=0;
177 IWritableItemDefManager* createItemDefManager();