aboutsummaryrefslogtreecommitdiff
path: root/src/shared/item/item.hh
diff options
context:
space:
mode:
authorNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-12 21:57:46 +1100
committerNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-12 21:57:46 +1100
commite4483eca01b48b943cd0461e24a74ae1a3139ed4 (patch)
treeed58c3c246e3af1af337697695d780aa31f6ad9a /src/shared/item/item.hh
parent1cc08c51eb4b0f95c30c0a98ad1fc5ad3459b2df (diff)
Update to most recent version (old initial commit)
Diffstat (limited to 'src/shared/item/item.hh')
-rw-r--r--src/shared/item/item.hh49
1 files changed, 49 insertions, 0 deletions
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 <cstdint>
+
+#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