]> git.lizzy.rs Git - minetest.git/blob - src/nodemetadata.h
Derive NodeMetadata from Metadata
[minetest.git] / src / nodemetadata.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser 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.
18 */
19
20 #ifndef NODEMETADATA_HEADER
21 #define NODEMETADATA_HEADER
22
23 #include "metadata.h"
24
25 /*
26         NodeMetadata stores arbitary amounts of data for special blocks.
27         Used for furnaces, chests and signs.
28
29         There are two interaction methods: inventory menu and text input.
30         Only one can be used for a single metadata, thus only inventory OR
31         text input should exist in a metadata.
32 */
33
34 class Inventory;
35 class IItemDefManager;
36
37 class NodeMetadata : public Metadata
38 {
39 public:
40         NodeMetadata(IItemDefManager *item_def_mgr);
41         ~NodeMetadata();
42
43         void serialize(std::ostream &os) const;
44         void deSerialize(std::istream &is);
45
46         void clear();
47         bool empty() const;
48
49         // The inventory
50         Inventory *getInventory()
51         {
52                 return m_inventory;
53         }
54
55 private:
56         Inventory *m_inventory;
57 };
58
59
60 /*
61         List of metadata of all the nodes of a block
62 */
63
64 class NodeMetadataList
65 {
66 public:
67         ~NodeMetadataList();
68
69         void serialize(std::ostream &os) const;
70         void deSerialize(std::istream &is, IItemDefManager *item_def_mgr);
71
72         // Add all keys in this list to the vector keys
73         std::vector<v3s16> getAllKeys();
74         // Get pointer to data
75         NodeMetadata *get(v3s16 p);
76         // Deletes data
77         void remove(v3s16 p);
78         // Deletes old data and sets a new one
79         void set(v3s16 p, NodeMetadata *d);
80         // Deletes all
81         void clear();
82
83 private:
84         int countNonEmpty() const;
85
86         std::map<v3s16, NodeMetadata *> m_data;
87 };
88
89 #endif