3 Copyright (C) 2010-2013 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 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.
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.
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.
22 #include <unordered_set>
26 NodeMetadata stores arbitary amounts of data for special blocks.
27 Used for furnaces, chests and signs.
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.
35 class IItemDefManager
;
37 class NodeMetadata
: public Metadata
40 NodeMetadata(IItemDefManager
*item_def_mgr
);
43 void serialize(std::ostream
&os
, u8 version
, bool disk
=true) const;
44 void deSerialize(std::istream
&is
, u8 version
);
50 Inventory
*getInventory()
55 inline bool isPrivate(const std::string
&name
) const
57 return m_privatevars
.count(name
) != 0;
59 void markPrivate(const std::string
&name
, bool set
);
62 int countNonPrivate() const;
64 Inventory
*m_inventory
;
65 std::unordered_set
<std::string
> m_privatevars
;
70 List of metadata of all the nodes of a block
73 typedef std::map
<v3s16
, NodeMetadata
*> NodeMetadataMap
;
75 class NodeMetadataList
78 NodeMetadataList(bool is_metadata_owner
= true) :
79 m_is_metadata_owner(is_metadata_owner
)
84 void serialize(std::ostream
&os
, u8 blockver
, bool disk
= true,
85 bool absolute_pos
= false) const;
86 void deSerialize(std::istream
&is
, IItemDefManager
*item_def_mgr
,
87 bool absolute_pos
= false);
89 // Add all keys in this list to the vector keys
90 std::vector
<v3s16
> getAllKeys();
91 // Get pointer to data
92 NodeMetadata
*get(v3s16 p
);
95 // Deletes old data and sets a new one
96 void set(v3s16 p
, NodeMetadata
*d
);
100 size_t size() const { return m_data
.size(); }
102 NodeMetadataMap::const_iterator
begin()
104 return m_data
.begin();
107 NodeMetadataMap::const_iterator
end()
113 int countNonEmpty() const;
115 bool m_is_metadata_owner
;
116 NodeMetadataMap m_data
;