3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2011 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"
30 struct ToolCapabilities;
50 std::string name; // "" = hand
51 std::string description; // Shown in tooltip.
56 std::string inventory_image; // Optional for nodes, mandatory for tools/craftitems
57 std::string wield_image; // If empty, inventory_image or mesh (only nodes) is used
61 Item stack and interaction properties
65 // If true, don't use node placement prediction
67 bool liquids_pointable;
68 // May be NULL. If non-NULL, deleted by destructor
69 ToolCapabilities *tool_capabilities;
72 // Client shall immediately place this node when player places the item.
73 // Server will update the precise end result a moment later.
75 std::string node_placement_prediction;
81 ItemDefinition(const ItemDefinition &def);
82 ItemDefinition& operator=(const ItemDefinition &def);
85 void serialize(std::ostream &os) const;
86 void deSerialize(std::istream &is);
95 virtual ~IItemDefManager(){}
97 // Get item definition
98 virtual const ItemDefinition& get(const std::string &name) const=0;
99 // Get alias definition
100 virtual std::string getAlias(const std::string &name) const=0;
101 // Get set of all defined item names and aliases
102 virtual std::set<std::string> getAll() const=0;
103 // Check if item is known
104 virtual bool isKnown(const std::string &name) const=0;
106 // Get item inventory texture
107 virtual video::ITexture* getInventoryTexture(const std::string &name,
108 IGameDef *gamedef) const=0;
109 // Get item wield mesh
110 virtual scene::IMesh* getWieldMesh(const std::string &name,
111 IGameDef *gamedef) const=0;
114 virtual void serialize(std::ostream &os)=0;
117 class IWritableItemDefManager : public IItemDefManager
120 IWritableItemDefManager(){}
121 virtual ~IWritableItemDefManager(){}
123 // Get item definition
124 virtual const ItemDefinition& get(const std::string &name) const=0;
125 // Get alias definition
126 virtual std::string getAlias(const std::string &name) const=0;
127 // Get set of all defined item names and aliases
128 virtual std::set<std::string> getAll() const=0;
129 // Check if item is known
130 virtual bool isKnown(const std::string &name) const=0;
132 // Get item inventory texture
133 virtual video::ITexture* getInventoryTexture(const std::string &name,
134 IGameDef *gamedef) const=0;
135 // Get item wield mesh
136 virtual scene::IMesh* getWieldMesh(const std::string &name,
137 IGameDef *gamedef) const=0;
140 // Remove all registered item and node definitions and aliases
141 // Then re-add the builtin item definitions
142 virtual void clear()=0;
143 // Register item definition
144 virtual void registerItem(const ItemDefinition &def)=0;
145 // Set an alias so that items named <name> will load as <convert_to>.
146 // Alias is not set if <name> has already been defined.
147 // Alias will be removed if <name> is defined at a later point of time.
148 virtual void registerAlias(const std::string &name,
149 const std::string &convert_to)=0;
151 virtual void serialize(std::ostream &os)=0;
152 virtual void deSerialize(std::istream &is)=0;
154 // Do stuff asked by threads that can only be done in the main thread
155 virtual void processQueue(IGameDef *gamedef)=0;
158 IWritableItemDefManager* createItemDefManager();