Botcraft 1.21.4
Loading...
Searching...
No Matches
Item.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#if PROTOCOL_VERSION < 347 /* < 1.13 */
5#include <utility>
6#endif
7
9
10namespace Botcraft
11{
12#if PROTOCOL_VERSION < 347 /* < 1.13 */
13 using ItemId = std::pair<int, unsigned char>;
14#else
15 using ItemId = int;
16#endif
17
19 {
21 std::string name;
22 unsigned char stack_size;
24 };
25
26 class Item
27 {
28 public:
29 Item(const ItemProperties& props);
30
31 ItemId GetId() const;
32 const std::string& GetName() const;
33 unsigned char GetStackSize() const;
34 ToolType GetToolType() const;
36
37 /// @brief Get the max durability of this item
38 /// @return -1 if undefined, max durability otherwise
39 int GetMaxDurability() const;
40
41 private:
43
44 private:
46 std::string name;
47 unsigned char stack_size;
51 };
52} // Botcraft
53
54#if PROTOCOL_VERSION < 347 /* < 1.13 */
55namespace std
56{
57 template<>
58 struct hash<std::pair<int, unsigned char>>
59 {
60 size_t operator()(const std::pair<int, unsigned char>& p) const
61 {
62 const size_t hash1 = std::hash<int>{}(p.first);
63 const size_t hash2 = std::hash<unsigned char>{}(p.second);
64
65 return hash1 ^ (hash2 + 0x9e3779b9 + (hash1 << 6) + (hash1 >> 2));
66 }
67 };
68}
69#endif
std::string name
Definition Item.hpp:46
void LoadTypeAndMaterialFromName()
Definition Item.cpp:46
ItemId id
Definition Item.hpp:45
unsigned char GetStackSize() const
Definition Item.cpp:26
int durability
Definition Item.hpp:48
ToolMaterial GetToolMaterial() const
Definition Item.cpp:36
ItemId GetId() const
Definition Item.cpp:16
ToolType GetToolType() const
Definition Item.cpp:31
ToolType tool_type
Definition Item.hpp:49
unsigned char stack_size
Definition Item.hpp:47
int GetMaxDurability() const
Get the max durability of this item.
Definition Item.cpp:41
ToolMaterial tool_material
Definition Item.hpp:50
const std::string & GetName() const
Definition Item.cpp:21
int ItemId
Definition Item.hpp:15
STL namespace.
unsigned char stack_size
Definition Item.hpp:22