diff options
Diffstat (limited to 'src/itemstackmetadata.cpp')
-rw-r--r-- | src/itemstackmetadata.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/itemstackmetadata.cpp b/src/itemstackmetadata.cpp index f63671425..53c8bad83 100644 --- a/src/itemstackmetadata.cpp +++ b/src/itemstackmetadata.cpp @@ -9,6 +9,22 @@ #define DESERIALIZE_KV_DELIM_STR "\x02" #define DESERIALIZE_PAIR_DELIM_STR "\x03" +#define TOOLCAP_KEY "tool_capabilities" + +void ItemStackMetadata::clear() +{ + Metadata::clear(); + updateToolCapabilities(); +} + +bool ItemStackMetadata::setString(const std::string &name, const std::string &var) +{ + bool result = Metadata::setString(name, var); + if (name == TOOLCAP_KEY) + updateToolCapabilities(); + return result; +} + void ItemStackMetadata::serialize(std::ostream &os) const { std::ostringstream os2; @@ -41,4 +57,29 @@ void ItemStackMetadata::deSerialize(std::istream &is) m_stringvars[""] = in; } } + updateToolCapabilities(); +} + +void ItemStackMetadata::updateToolCapabilities() +{ + if (contains(TOOLCAP_KEY)) { + toolcaps_overridden = true; + toolcaps_override = ToolCapabilities(); + std::istringstream is(getString(TOOLCAP_KEY)); + toolcaps_override.deserializeJson(is); + } else { + toolcaps_overridden = false; + } +} + +void ItemStackMetadata::setToolCapabilities(const ToolCapabilities &caps) +{ + std::ostringstream os; + caps.serializeJson(os); + setString(TOOLCAP_KEY, os.str()); +} + +void ItemStackMetadata::clearToolCapabilities() +{ + setString(TOOLCAP_KEY, ""); } |