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.
21 #ifndef ITEMDEF_HEADER
22 #define ITEMDEF_HEADER
24 #include "irrlichttypes_extrabloated.h"
28 #include "itemgroup.h"
32 struct ToolCapabilities;
52 std::string name; // "" = hand
53 std::string description; // Shown in tooltip.
58 std::string inventory_image; // Optional for nodes, mandatory for tools/craftitems
59 std::string wield_image; // If empty, inventory_image or mesh (only nodes) is used
63 Item stack and interaction properties
67 bool liquids_pointable;
68 // May be NULL. If non-NULL, deleted by destructor
69 ToolCapabilities *tool_capabilities;
71 SimpleSoundSpec sound_place;
72 SimpleSoundSpec sound_place_failed;
75 // Client shall immediately place this node when player places the item.
76 // Server will update the precise end result a moment later.
78 std::string node_placement_prediction;
84 ItemDefinition(const ItemDefinition &def);
85 ItemDefinition& operator=(const ItemDefinition &def);
88 void serialize(std::ostream &os, u16 protocol_version) const;
89 void deSerialize(std::istream &is);
98 virtual ~IItemDefManager(){}
100 // Get item definition
101 virtual const ItemDefinition& get(const std::string &name) const=0;
102 // Get alias definition
103 virtual std::string getAlias(const std::string &name) const=0;
104 // Get set of all defined item names and aliases
105 virtual std::set<std::string> getAll() const=0;
106 // Check if item is known
107 virtual bool isKnown(const std::string &name) const=0;
109 // Get item inventory texture
110 virtual video::ITexture* getInventoryTexture(const std::string &name,
111 Client *client) const=0;
112 // Get item wield mesh
113 virtual scene::IMesh* getWieldMesh(const std::string &name,
114 Client *client) const=0;
117 virtual void serialize(std::ostream &os, u16 protocol_version)=0;
120 class IWritableItemDefManager : public IItemDefManager
123 IWritableItemDefManager(){}
124 virtual ~IWritableItemDefManager(){}
126 // Get item definition
127 virtual const ItemDefinition& get(const std::string &name) const=0;
128 // Get alias definition
129 virtual std::string getAlias(const std::string &name) const=0;
130 // Get set of all defined item names and aliases
131 virtual std::set<std::string> getAll() const=0;
132 // Check if item is known
133 virtual bool isKnown(const std::string &name) const=0;
135 // Get item inventory texture
136 virtual video::ITexture* getInventoryTexture(const std::string &name,
137 Client *client) const=0;
138 // Get item wield mesh
139 virtual scene::IMesh* getWieldMesh(const std::string &name,
140 Client *client) const=0;
143 // Remove all registered item and node definitions and aliases
144 // Then re-add the builtin item definitions
145 virtual void clear()=0;
146 // Register item definition
147 virtual void registerItem(const ItemDefinition &def)=0;
148 virtual void unregisterItem(const std::string &name)=0;
149 // Set an alias so that items named <name> will load as <convert_to>.
150 // Alias is not set if <name> has already been defined.
151 // Alias will be removed if <name> is defined at a later point of time.
152 virtual void registerAlias(const std::string &name,
153 const std::string &convert_to)=0;
155 virtual void serialize(std::ostream &os, u16 protocol_version)=0;
156 virtual void deSerialize(std::istream &is)=0;
158 // Do stuff asked by threads that can only be done in the main thread
159 virtual void processQueue(IGameDef *gamedef)=0;
162 IWritableItemDefManager* createItemDefManager();