From a637107a4e81be88938d68df4deae50e68cf2cd8 Mon Sep 17 00:00:00 2001 From: raymoo Date: Tue, 18 Apr 2017 16:30:27 -0700 Subject: Allow overriding tool capabilities through itemstack metadata This makes it possible to modify the tool capabilities of individual itemstacks by calling a method on itemstack metadata references. --- src/itemstackmetadata.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/itemstackmetadata.h') diff --git a/src/itemstackmetadata.h b/src/itemstackmetadata.h index 843ef4832..0e1977c8c 100644 --- a/src/itemstackmetadata.h +++ b/src/itemstackmetadata.h @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include "metadata.h" +#include "tool.h" class Inventory; class IItemDefManager; @@ -27,6 +28,27 @@ class IItemDefManager; class ItemStackMetadata : public Metadata { public: + ItemStackMetadata() : toolcaps_overridden(false) {} + + // Overrides + void clear() override; + bool setString(const std::string &name, const std::string &var) override; + void serialize(std::ostream &os) const; void deSerialize(std::istream &is); + + const ToolCapabilities &getToolCapabilities( + const ToolCapabilities &default_caps) const + { + return toolcaps_overridden ? toolcaps_override : default_caps; + } + + void setToolCapabilities(const ToolCapabilities &caps); + void clearToolCapabilities(); + +private: + void updateToolCapabilities(); + + bool toolcaps_overridden; + ToolCapabilities toolcaps_override; }; -- cgit v1.2.3