itemstackmetadata.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #include <optional>
  20. class Inventory;
  21. class IItemDefManager;
  22. class ItemStackMetadata : public SimpleMetadata
  23. {
  24. public:
  25. ItemStackMetadata():
  26. toolcaps_overridden(false)
  27. {}
  28. // Overrides
  29. void clear() override;
  30. bool setString(const std::string &name, std::string_view var) override;
  31. void serialize(std::ostream &os) const;
  32. void deSerialize(std::istream &is);
  33. const ToolCapabilities &getToolCapabilities(
  34. const ToolCapabilities &default_caps) const
  35. {
  36. return toolcaps_overridden ? toolcaps_override : default_caps;
  37. }
  38. void setToolCapabilities(const ToolCapabilities &caps);
  39. void clearToolCapabilities();
  40. const std::optional<WearBarParams> &getWearBarParamOverride() const
  41. {
  42. return wear_bar_override;
  43. }
  44. void setWearBarParams(const WearBarParams &params);
  45. void clearWearBarParams();
  46. private:
  47. void updateToolCapabilities();
  48. void updateWearBarParams();
  49. bool toolcaps_overridden;
  50. ToolCapabilities toolcaps_override;
  51. std::optional<WearBarParams> wear_bar_override;
  52. };