3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef NODEMETADATA_HEADER
21 #define NODEMETADATA_HEADER
23 #include "common_irrlicht.h"
28 NodeMetadata stores arbitary amounts of data for special blocks.
29 Used for furnaces, chests and signs.
31 There are two interaction methods: inventory menu and text input.
32 Only one can be used for a single metadata, thus only inventory OR
33 text input should exist in a metadata.
42 typedef NodeMetadata* (*Factory)(std::istream&, IGameDef *gamedef);
44 NodeMetadata(IGameDef *gamedef);
45 virtual ~NodeMetadata();
47 static NodeMetadata* deSerialize(std::istream &is, IGameDef *gamedef);
48 void serialize(std::ostream &os);
50 // This usually is the CONTENT_ value
51 virtual u16 typeId() const = 0;
52 virtual NodeMetadata* clone(IGameDef *gamedef) = 0;
53 virtual void serializeBody(std::ostream &os) = 0;
54 virtual std::string infoText() {return "";}
55 virtual Inventory* getInventory() {return NULL;}
56 // This is called always after the inventory is modified, before
57 // the changes are copied elsewhere
58 virtual void inventoryModified(){}
59 // A step in time. Returns true if metadata changed.
60 virtual bool step(float dtime) {return false;}
61 virtual bool nodeRemovalDisabled(){return false;}
62 // Used to make custom inventory menus.
63 // See format in guiInventoryMenu.cpp.
64 virtual std::string getInventoryDrawSpecString(){return "";}
65 // primarily used for locking chests, but others can play too
66 virtual std::string getOwner(){ return std::string(""); }
67 virtual void setOwner(std::string t){}
68 virtual bool allowsTextInput(){ return false; }
69 virtual std::string getText(){ return ""; }
70 virtual void setText(const std::string &t){}
72 static void registerType(u16 id, Factory f);
75 static core::map<u16, Factory> m_types;
79 List of metadata of all the nodes of a block
82 class NodeMetadataList
87 void serialize(std::ostream &os);
88 void deSerialize(std::istream &is, IGameDef *gamedef);
90 // Get pointer to data
91 NodeMetadata* get(v3s16 p);
94 // Deletes old data and sets a new one
95 void set(v3s16 p, NodeMetadata *d);
97 // A step in time. Returns true if something changed.
98 bool step(float dtime);
101 core::map<v3s16, NodeMetadata*> m_data;