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"
31 - Item that is being burned
33 - Item stack that is being heated
45 typedef NodeMetadata* (*Factory)(std::istream&);
48 virtual ~NodeMetadata();
50 static NodeMetadata* deSerialize(std::istream &is);
51 void serialize(std::ostream &os);
53 // This usually is the CONTENT_ value
54 virtual u16 typeId() const = 0;
55 virtual NodeMetadata* clone() = 0;
56 virtual void serializeBody(std::ostream &os) = 0;
57 virtual std::string infoText() {return "<todo: remove this text>";}
58 virtual Inventory* getInventory() {return NULL;}
59 // This is called always after the inventory is modified, before
60 // the changes are copied elsewhere
61 virtual void inventoryModified(){}
62 // A step in time. Returns true if metadata changed.
63 virtual bool step(float dtime) {return false;}
66 static void registerType(u16 id, Factory f);
68 static core::map<u16, Factory> m_types;
71 class SignNodeMetadata : public NodeMetadata
74 SignNodeMetadata(std::string text);
75 //~SignNodeMetadata();
77 virtual u16 typeId() const;
78 static NodeMetadata* create(std::istream &is);
79 virtual NodeMetadata* clone();
80 virtual void serializeBody(std::ostream &os);
81 virtual std::string infoText();
83 std::string getText(){ return m_text; }
84 void setText(std::string t){ m_text = t; }
90 class ChestNodeMetadata : public NodeMetadata
96 virtual u16 typeId() const;
97 static NodeMetadata* create(std::istream &is);
98 virtual NodeMetadata* clone();
99 virtual void serializeBody(std::ostream &os);
100 virtual std::string infoText();
101 virtual Inventory* getInventory() {return m_inventory;}
104 Inventory *m_inventory;
107 class FurnaceNodeMetadata : public NodeMetadata
110 FurnaceNodeMetadata();
111 ~FurnaceNodeMetadata();
113 virtual u16 typeId() const;
114 virtual NodeMetadata* clone();
115 static NodeMetadata* create(std::istream &is);
116 virtual void serializeBody(std::ostream &os);
117 virtual std::string infoText();
118 virtual Inventory* getInventory() {return m_inventory;}
119 virtual void inventoryModified();
120 virtual bool step(float dtime);
123 Inventory *m_inventory;
124 float m_step_accumulator;
125 float m_fuel_totaltime;
127 float m_src_totaltime;
132 List of metadata of all the nodes of a block
135 class InventoryManager;
137 class NodeMetadataList
142 void serialize(std::ostream &os);
143 void deSerialize(std::istream &is);
145 // Get pointer to data
146 NodeMetadata* get(v3s16 p);
148 void remove(v3s16 p);
149 // Deletes old data and sets a new one
150 void set(v3s16 p, NodeMetadata *d);
152 // A step in time. Returns true if something changed.
153 bool step(float dtime);
156 core::map<v3s16, NodeMetadata*> m_data;