Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
nodemetadata.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include <unordered_set>
8#include <map>
9#include "metadata.h"
10
11/*
12 NodeMetadata stores arbitary amounts of data for special blocks.
13 Used for furnaces, chests and signs.
14
15 There are two interaction methods: inventory menu and text input.
16 Only one can be used for a single metadata, thus only inventory OR
17 text input should exist in a metadata.
18*/
19
20class Inventory;
21class IItemDefManager;
22
24{
25public:
26 NodeMetadata(IItemDefManager *item_def_mgr);
28
29 void serialize(std::ostream &os, u8 version, bool disk=true) const;
30 void deSerialize(std::istream &is, u8 version);
31
32 void clear();
33 bool empty() const;
34
35 // The inventory
37 {
38 return m_inventory;
39 }
40
41 inline bool isPrivate(const std::string &name) const
42 {
43 return m_privatevars.count(name) != 0;
44 }
45
48 bool markPrivate(const std::string &name, bool set);
49
50private:
51 int countNonPrivate() const;
52
54 std::unordered_set<std::string> m_privatevars;
55};
56
57
58/*
59 List of metadata of all the nodes of a block
60*/
61
62typedef std::map<v3s16, NodeMetadata *> NodeMetadataMap;
63
65{
66public:
67 NodeMetadataList(bool is_metadata_owner = true) :
68 m_is_metadata_owner(is_metadata_owner)
69 {}
70
72
73 void serialize(std::ostream &os, u8 blockver, bool disk = true,
74 bool absolute_pos = false, bool include_empty = false) const;
75 void deSerialize(std::istream &is, IItemDefManager *item_def_mgr,
76 bool absolute_pos = false);
77
78 // Add all keys in this list to the vector keys
79 std::vector<v3s16> getAllKeys();
80 // Get pointer to data
82 // Deletes data
83 void remove(v3s16 p);
84 // Deletes old data and sets a new one
85 void set(v3s16 p, NodeMetadata *d);
86 // Deletes all
87 void clear();
88
89 size_t size() const { return m_data.size(); }
90
91 NodeMetadataMap::const_iterator begin()
92 {
93 return m_data.begin();
94 }
95
96 NodeMetadataMap::const_iterator end()
97 {
98 return m_data.end();
99 }
100
101private:
102 int countNonEmpty() const;
103
106};
Definition itemdef.h:129
Definition inventory.h:314
Definition nodemetadata.h:65
std::vector< v3s16 > getAllKeys()
Definition nodemetadata.cpp:194
void set(v3s16 p, NodeMetadata *d)
Definition nodemetadata.cpp:227
void deSerialize(std::istream &is, IItemDefManager *item_def_mgr, bool absolute_pos=false)
Definition nodemetadata.cpp:141
NodeMetadataMap::const_iterator begin()
Definition nodemetadata.h:91
bool m_is_metadata_owner
Definition nodemetadata.h:104
NodeMetadataList(bool is_metadata_owner=true)
Definition nodemetadata.h:67
NodeMetadataMap m_data
Definition nodemetadata.h:105
NodeMetadata * get(v3s16 p)
Definition nodemetadata.cpp:204
size_t size() const
Definition nodemetadata.h:89
~NodeMetadataList()
Definition nodemetadata.cpp:189
void clear()
Definition nodemetadata.cpp:233
int countNonEmpty() const
Definition nodemetadata.cpp:242
NodeMetadataMap::const_iterator end()
Definition nodemetadata.h:96
void remove(v3s16 p)
Definition nodemetadata.cpp:212
void serialize(std::ostream &os, u8 blockver, bool disk=true, bool absolute_pos=false, bool include_empty=false) const
Definition nodemetadata.cpp:101
Definition nodemetadata.h:24
bool empty() const
Definition nodemetadata.cpp:71
int countNonPrivate() const
Definition nodemetadata.cpp:85
void clear()
Definition nodemetadata.cpp:64
Inventory * getInventory()
Definition nodemetadata.h:36
bool isPrivate(const std::string &name) const
Definition nodemetadata.h:41
Inventory * m_inventory
Definition nodemetadata.h:53
std::unordered_set< std::string > m_privatevars
Definition nodemetadata.h:54
void deSerialize(std::istream &is, u8 version)
Definition nodemetadata.cpp:47
NodeMetadata(IItemDefManager *item_def_mgr)
Definition nodemetadata.cpp:20
void serialize(std::ostream &os, u8 version, bool disk=true) const
Definition nodemetadata.cpp:29
bool markPrivate(const std::string &name, bool set)
Marks a key as private.
Definition nodemetadata.cpp:77
~NodeMetadata()
Definition nodemetadata.cpp:24
Definition metadata.h:63
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
std::map< v3s16, NodeMetadata * > NodeMetadataMap
Definition nodemetadata.h:62
static std::string p(std::string path)
Definition test_filesys.cpp:53