Botcraft 1.21.4
Loading...
Searching...
No Matches
Item.cpp
Go to the documentation of this file.
4
5namespace Botcraft
6{
8 {
9 id = props.id;
10 name = props.name;
11 stack_size = props.stack_size;
12 durability = props.durability;
14 }
15
17 {
18 return id;
19 }
20
21 const std::string& Item::GetName() const
22 {
23 return name;
24 }
25
26 unsigned char Item::GetStackSize() const
27 {
28 return stack_size;
29 }
30
32 {
33 return tool_type;
34 }
35
37 {
38 return tool_material;
39 }
40
42 {
43 return durability;
44 }
45
47 {
48 if (!Utilities::StartsWith(name, "minecraft:"))
49 {
50 if (name != "default")
51 {
52 LOG_WARNING("Unexpected item name format: " << name);
53 }
56 return;
57 }
58
59 const std::string without_minecraft = name.substr(10);
60 const std::vector<std::string> sub_parts = Utilities::SplitString(without_minecraft, '_');
61
62 if (sub_parts.size() == 1 && sub_parts[0] == "shears")
63 {
66 return;
67 }
68
69 if (sub_parts.size() == 1 || sub_parts.size() > 2)
70 {
73 return;
74 }
75
76 if (sub_parts[1] == "axe")
77 {
79 }
80 else if (sub_parts[1] == "hoe")
81 {
83 }
84 else if (sub_parts[1] == "pickaxe")
85 {
87 }
88 else if (sub_parts[1] == "shovel")
89 {
91 }
92 else if (sub_parts[1] == "sword")
93 {
95 }
96 // Not a tool
97 else
98 {
101 return;
102 }
103
104 // If we're here, it's a tool, so extract the material
105 if (sub_parts[0] == "wooden")
106 {
108 }
109 else if (sub_parts[0] == "golden")
110 {
112 }
113 else if (sub_parts[0] == "stone")
114 {
116 }
117 else if (sub_parts[0] == "iron")
118 {
120 }
121 else if (sub_parts[0] == "diamond")
122 {
124 }
125#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
126 else if (sub_parts[0] == "netherite")
127 {
129 }
130#endif
131 else
132 {
134 LOG_WARNING("Unknown material for tool: " << name);
135 }
136 }
137
138} //Botcraft
#define LOG_WARNING(osstream)
Definition Logger.hpp:44
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
Item(const ItemProperties &props)
Definition Item.cpp:7
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
bool StartsWith(const std::string &mainStr, const std::string &toMatch)
std::vector< std::string > SplitString(const std::string &s, const char delimiter)
int ItemId
Definition Item.hpp:15
unsigned char stack_size
Definition Item.hpp:22