From e4483eca01b48b943cd0461e24a74ae1a3139ed4 Mon Sep 17 00:00:00 2001 From: Nicolas James Date: Wed, 12 Feb 2025 21:57:46 +1100 Subject: Update to most recent version (old initial commit) --- src/shared/item/item.hh | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/shared/item/item.hh (limited to 'src/shared/item/item.hh') diff --git a/src/shared/item/item.hh b/src/shared/item/item.hh new file mode 100644 index 0000000..3774189 --- /dev/null +++ b/src/shared/item/item.hh @@ -0,0 +1,49 @@ +#ifndef SHARED_ITEM_ITEM_HH_ +#define SHARED_ITEM_ITEM_HH_ + +#include + +#include "shared/net/proto.hh" +#include "shared/world/block.hh" +#include "shared/world/chunk.hh" + +namespace shared { +namespace item { + +// ABC for items that exist in a player's inventory. (TODO abc lol) +class item { +public: + using type_t = std::uint32_t; + +public: + type_t type; + std::uint32_t quantity; + +public: + item(const type_t& type, const std::uint32_t& quantity) noexcept + : type(type), quantity(quantity) {} + item(const proto::item& item) noexcept + : type(item.type()), quantity(item.quantity()) {} + virtual ~item() noexcept {} + +public: + static std::uint32_t get_max_stack(const type_t& type) noexcept; + +public: + virtual type_t get_type() const noexcept { + return this->type; + } + +public: // protobuf stuff + void pack(proto::item* const proto, + const std::uint32_t inventory_index) const noexcept { + proto->set_type(this->type); + proto->set_quantity(this->quantity); + proto->set_index(inventory_index); + } +}; + +} // namespace item +} // namespace shared + +#endif -- cgit v1.2.3