itemstackmetadata.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. Minetest
  3. Copyright (C) 2017-8 rubenwardy <rw@rubenwardy.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #pragma once
  17. #include "metadata.h"
  18. #include "tool.h"
  19. class Inventory;
  20. class IItemDefManager;
  21. class ItemStackMetadata : public SimpleMetadata
  22. {
  23. public:
  24. ItemStackMetadata() : toolcaps_overridden(false) {}
  25. // Overrides
  26. void clear() override;
  27. bool setString(const std::string &name, const std::string &var) override;
  28. void serialize(std::ostream &os) const;
  29. void deSerialize(std::istream &is);
  30. const ToolCapabilities &getToolCapabilities(
  31. const ToolCapabilities &default_caps) const
  32. {
  33. return toolcaps_overridden ? toolcaps_override : default_caps;
  34. }
  35. void setToolCapabilities(const ToolCapabilities &caps);
  36. void clearToolCapabilities();
  37. private:
  38. void updateToolCapabilities();
  39. bool toolcaps_overridden;
  40. ToolCapabilities toolcaps_override;
  41. };