#include <string>
#include <iostream>
#include <set>
-#include <map>
#include "itemgroup.h"
#include "sound.h"
-#include "util/container.h"
-#include "util/thread.h"
-
+class IGameDef;
+class Client;
+struct ToolCapabilities;
#ifndef SERVER
#include "client/tile.h"
+struct ItemMesh;
+struct ItemStack;
#endif
-class IGameDef;
-class INodeDefManager;
-struct ToolCapabilities;
-
/*
Base item definition
*/
ITEM_NONE,
ITEM_NODE,
ITEM_CRAFT,
- ITEM_TOOL
+ ITEM_TOOL,
};
struct ItemDefinition
*/
std::string inventory_image; // Optional for nodes, mandatory for tools/craftitems
std::string wield_image; // If empty, inventory_image or mesh (only nodes) is used
+ std::string palette_image; // If specified, the item will be colorized based on this
+ video::SColor color; // The fallback color of the node.
v3f wield_scale;
/*
Item stack and interaction properties
*/
- s16 stack_max;
+ u16 stack_max;
bool usable;
bool liquids_pointable;
// May be NULL. If non-NULL, deleted by destructor
// Get item definition
virtual const ItemDefinition& get(const std::string &name) const=0;
// Get alias definition
- virtual std::string getAlias(const std::string &name) const=0;
+ virtual const std::string &getAlias(const std::string &name) const=0;
// Get set of all defined item names and aliases
- virtual std::set<std::string> getAll() const=0;
+ virtual void getAll(std::set<std::string> &result) const=0;
// Check if item is known
virtual bool isKnown(const std::string &name) const=0;
#ifndef SERVER
// Get item inventory texture
virtual video::ITexture* getInventoryTexture(const std::string &name,
- IGameDef *gamedef) const=0;
+ Client *client) const=0;
// Get item wield mesh
- virtual scene::IMesh* getWieldMesh(const std::string &name,
- IGameDef *gamedef) const=0;
+ virtual ItemMesh* getWieldMesh(const std::string &name,
+ Client *client) const=0;
+ // Get item palette
+ virtual Palette* getPalette(const std::string &name,
+ Client *client) const = 0;
+ // Returns the base color of an item stack: the color of all
+ // tiles that do not define their own color.
+ virtual video::SColor getItemstackColor(const ItemStack &stack,
+ Client *client) const = 0;
#endif
virtual void serialize(std::ostream &os, u16 protocol_version)=0;
// Get item definition
virtual const ItemDefinition& get(const std::string &name) const=0;
// Get alias definition
- virtual std::string getAlias(const std::string &name) const=0;
+ virtual const std::string &getAlias(const std::string &name) const=0;
// Get set of all defined item names and aliases
- virtual std::set<std::string> getAll() const=0;
+ virtual void getAll(std::set<std::string> &result) const=0;
// Check if item is known
virtual bool isKnown(const std::string &name) const=0;
#ifndef SERVER
// Get item inventory texture
virtual video::ITexture* getInventoryTexture(const std::string &name,
- IGameDef *gamedef) const=0;
+ Client *client) const=0;
// Get item wield mesh
- virtual scene::IMesh* getWieldMesh(const std::string &name,
- IGameDef *gamedef) const=0;
+ virtual ItemMesh* getWieldMesh(const std::string &name,
+ Client *client) const=0;
#endif
// Remove all registered item and node definitions and aliases
virtual void clear()=0;
// Register item definition
virtual void registerItem(const ItemDefinition &def)=0;
+ virtual void unregisterItem(const std::string &name)=0;
// Set an alias so that items named <name> will load as <convert_to>.
// Alias is not set if <name> has already been defined.
// Alias will be removed if <name> is defined at a later point of time.
virtual void processQueue(IGameDef *gamedef)=0;
};
-
-class CItemDefManager: public IWritableItemDefManager
-{
-public:
- CItemDefManager();
- virtual ~CItemDefManager();
- virtual const ItemDefinition& get(const std::string &name_) const;
- virtual std::string getAlias(const std::string &name) const;
- virtual std::set<std::string> getAll() const;
- virtual bool isKnown(const std::string &name_) const;
-
-#ifndef SERVER
- // Get item inventory texture
- virtual video::ITexture* getInventoryTexture(const std::string &name,
- IGameDef *gamedef) const;
-
- // Get item wield mesh
- virtual scene::IMesh* getWieldMesh(const std::string &name,
- IGameDef *gamedef) const;
-#endif
- void clear();
-
- virtual void registerItem(const ItemDefinition &def);
- virtual void registerAlias(const std::string &name,
- const std::string &convert_to);
- void serialize(std::ostream &os, u16 protocol_version);
- void deSerialize(std::istream &is);
-
- void processQueue(IGameDef *gamedef);
-
-private:
-
-#ifndef SERVER
- struct ClientCached
- {
- video::ITexture *inventory_texture;
- scene::IMesh *wield_mesh;
-
- ClientCached();
- };
-
- void createNodeItemTexture(const std::string& name,
- const ItemDefinition& def, INodeDefManager* nodedef,
- ClientCached* cc, IGameDef* gamedef, ITextureSource* tsrc) const;
-
- ClientCached* createClientCachedDirect(const std::string &name,
- IGameDef *gamedef) const;
-
- ClientCached* getClientCached(const std::string &name,
- IGameDef *gamedef) const;
-
- // The id of the thread that is allowed to use irrlicht directly
- threadid_t m_main_thread;
-
- // A reference to this can be returned when nothing is found, to avoid NULLs
- mutable ClientCached m_dummy_clientcached;
-
- // Cached textures and meshes
- mutable MutexedMap<std::string, ClientCached*> m_clientcached;
-
- // Queued clientcached fetches (to be processed by the main thread)
- mutable RequestQueue<std::string, ClientCached*, u8, u8> m_get_clientcached_queue;
-#endif
-
- // Key is name
- std::map<std::string, ItemDefinition*> m_item_definitions;
-
- // Aliases
- std::map<std::string, std::string> m_aliases;
-};
-
IWritableItemDefManager* createItemDefManager();
#endif