Cuberite
A lightweight, fast and extensible game server for Minecraft
Item.cpp
Go to the documentation of this file.
1 
2 #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
3 
4 #include "Item.h"
5 #include "BlockType.h"
6 #include "ItemGrid.h"
7 #include "json/json.h"
8 #include "Items/ItemHandler.h"
9 
10 #include "FastRandom.h"
11 
12 
13 
14 
15 
17  m_ItemType(E_ITEM_EMPTY),
18  m_ItemCount(0),
19  m_ItemDamage(0),
20  m_CustomName(),
21  m_RepairCost(0),
22  m_FireworkItem(),
23  m_ItemColor()
24 {
25 }
26 
27 
28 
29 
30 
32  short a_ItemType,
33  char a_ItemCount,
34  short a_ItemDamage,
35  const AString & a_Enchantments,
36  const AString & a_CustomName,
37  const AStringVector & a_LoreTable
38 ):
39  m_ItemType (a_ItemType),
40  m_ItemCount (a_ItemCount),
41  m_ItemDamage (a_ItemDamage),
42  m_Enchantments(a_Enchantments),
43  m_CustomName (a_CustomName),
44  m_LoreTable (a_LoreTable),
45  m_RepairCost (0),
46  m_FireworkItem(),
47  m_ItemColor()
48 {
49  if (!IsValidItem(m_ItemType))
50  {
52  {
53  LOGWARNING("%s: creating an invalid item type (%d), resetting to empty.", __FUNCTION__, a_ItemType);
54  }
55  Empty();
56  }
57 }
58 
59 
60 
61 
62 
64 {
66  m_ItemCount = 0;
67  m_ItemDamage = 0;
69  m_CustomName = "";
70  m_LoreTable.clear();
71  m_RepairCost = 0;
74 }
75 
76 
77 
78 
79 
81 {
83  m_ItemCount = 0;
84  m_ItemDamage = 0;
85  m_RepairCost = 0;
87 }
88 
89 
90 
91 
92 
93 cItem cItem::CopyOne(void) const
94 {
95  cItem res(*this);
96  res.m_ItemCount = 1;
97  return res;
98 }
99 
100 
101 
102 
103 
104 cItem & cItem::AddCount(char a_AmountToAdd)
105 {
106  m_ItemCount += a_AmountToAdd;
107  if (m_ItemCount <= 0)
108  {
109  Empty();
110  }
111  return *this;
112 }
113 
114 
115 
116 
117 
118 short cItem::GetMaxDamage(void) const
119 {
120  switch (m_ItemType)
121  {
122  case E_ITEM_BOW: return 384;
123  case E_ITEM_CHAIN_BOOTS: return 196;
124  case E_ITEM_CHAIN_CHESTPLATE:return 241;
125  case E_ITEM_CHAIN_HELMET: return 166;
126  case E_ITEM_CHAIN_LEGGINGS: return 226;
127  case E_ITEM_DIAMOND_AXE: return 1561;
128  case E_ITEM_DIAMOND_BOOTS: return 430;
129  case E_ITEM_DIAMOND_CHESTPLATE: return 529;
130  case E_ITEM_DIAMOND_HELMET: return 364;
131  case E_ITEM_DIAMOND_HOE: return 1561;
132  case E_ITEM_DIAMOND_LEGGINGS:return 496;
133  case E_ITEM_DIAMOND_PICKAXE: return 1561;
134  case E_ITEM_DIAMOND_SHOVEL: return 1561;
135  case E_ITEM_DIAMOND_SWORD: return 1561;
136  case E_ITEM_ELYTRA: return 432;
137  case E_ITEM_FLINT_AND_STEEL: return 64;
138  case E_ITEM_FISHING_ROD: return 65;
139  case E_ITEM_GOLD_AXE: return 32;
140  case E_ITEM_GOLD_BOOTS: return 92;
141  case E_ITEM_GOLD_CHESTPLATE: return 113;
142  case E_ITEM_GOLD_HELMET: return 78;
143  case E_ITEM_GOLD_HOE: return 32;
144  case E_ITEM_GOLD_LEGGINGS: return 106;
145  case E_ITEM_GOLD_PICKAXE: return 32;
146  case E_ITEM_GOLD_SHOVEL: return 32;
147  case E_ITEM_GOLD_SWORD: return 32;
148  case E_ITEM_IRON_AXE: return 250;
149  case E_ITEM_IRON_BOOTS: return 196;
150  case E_ITEM_IRON_CHESTPLATE: return 241;
151  case E_ITEM_IRON_HELMET: return 166;
152  case E_ITEM_IRON_HOE: return 250;
153  case E_ITEM_IRON_LEGGINGS: return 226;
154  case E_ITEM_IRON_PICKAXE: return 250;
155  case E_ITEM_IRON_SHOVEL: return 250;
156  case E_ITEM_IRON_SWORD: return 250;
157  case E_ITEM_LEATHER_BOOTS: return 66;
158  case E_ITEM_LEATHER_CAP: return 55;
159  case E_ITEM_LEATHER_PANTS: return 76;
160  case E_ITEM_LEATHER_TUNIC: return 81;
161  case E_ITEM_SHEARS: return 250;
162  case E_ITEM_STONE_AXE: return 131;
163  case E_ITEM_STONE_HOE: return 131;
164  case E_ITEM_STONE_PICKAXE: return 131;
165  case E_ITEM_STONE_SHOVEL: return 131;
166  case E_ITEM_STONE_SWORD: return 131;
167  case E_ITEM_WOODEN_AXE: return 59;
168  case E_ITEM_WOODEN_HOE: return 59;
169  case E_ITEM_WOODEN_PICKAXE: return 59;
170  case E_ITEM_WOODEN_SHOVEL: return 59;
171  case E_ITEM_WOODEN_SWORD: return 59;
172 
173  default: return 0;
174  }
175 }
176 
177 
178 
179 
180 
181 bool cItem::DamageItem(short a_Amount)
182 {
183  short MaxDamage = GetMaxDamage();
184  if (MaxDamage == 0)
185  {
186  // Item doesn't have damage
187  return false;
188  }
189 
190  m_ItemDamage += a_Amount;
191  return (m_ItemDamage > MaxDamage);
192 }
193 
194 
195 
196 
197 
198 bool cItem::IsFullStack(void) const
199 {
200  return (m_ItemCount >= GetMaxStackSize());
201 }
202 
203 
204 
205 
206 
207 char cItem::GetMaxStackSize(void) const
208 {
210 }
211 
212 
213 
214 
215 
216 const cItemHandler & cItem::GetHandler(void) const
217 {
219 }
220 
221 
222 
223 
224 
225 void cItem::GetJson(Json::Value & a_OutValue) const
226 {
227  a_OutValue["ID"] = m_ItemType;
228  if (m_ItemType > 0)
229  {
230  a_OutValue["Count"] = m_ItemCount;
231  a_OutValue["Health"] = m_ItemDamage;
232  AString Enchantments(m_Enchantments.ToString());
233  if (!Enchantments.empty())
234  {
235  a_OutValue["ench"] = Enchantments;
236  }
237  if (!IsCustomNameEmpty())
238  {
239  a_OutValue["Name"] = m_CustomName;
240  }
241  if (!IsLoreEmpty())
242  {
243  auto & LoreArray = (a_OutValue["Lore"] = Json::Value(Json::arrayValue));
244 
245  for (const auto & Line : m_LoreTable)
246  {
247  LoreArray.append(Line);
248  }
249  }
250 
251  if (m_ItemColor.IsValid())
252  {
253  a_OutValue["Color_Red"] = m_ItemColor.GetRed();
254  a_OutValue["Color_Green"] = m_ItemColor.GetGreen();
255  a_OutValue["Color_Blue"] = m_ItemColor.GetBlue();
256  }
257 
259  {
260  a_OutValue["Flicker"] = m_FireworkItem.m_HasFlicker;
261  a_OutValue["Trail"] = m_FireworkItem.m_HasTrail;
262  a_OutValue["Type"] = m_FireworkItem.m_Type;
263  a_OutValue["FlightTimeInTicks"] = m_FireworkItem.m_FlightTimeInTicks;
264  a_OutValue["Colours"] = m_FireworkItem.ColoursToString(m_FireworkItem);
265  a_OutValue["FadeColours"] = m_FireworkItem.FadeColoursToString(m_FireworkItem);
266  }
267 
268  a_OutValue["RepairCost"] = m_RepairCost;
269  }
270 }
271 
272 
273 
274 
275 
276 void cItem::FromJson(const Json::Value & a_Value)
277 {
278  m_ItemType = static_cast<ENUM_ITEM_TYPE>(a_Value.get("ID", -1).asInt());
279  if (m_ItemType > 0)
280  {
281  m_ItemCount = static_cast<char>(a_Value.get("Count", -1).asInt());
282  m_ItemDamage = static_cast<short>(a_Value.get("Health", -1).asInt());
284  m_Enchantments.AddFromString(a_Value.get("ench", "").asString());
285  m_CustomName = a_Value.get("Name", "").asString();
286  auto Lore = a_Value.get("Lore", Json::arrayValue);
287  for (auto & Line : Lore)
288  {
289  m_LoreTable.push_back(Line.asString());
290  }
291 
292  int red = a_Value.get("Color_Red", -1).asInt();
293  int green = a_Value.get("Color_Green", -1).asInt();
294  int blue = a_Value.get("Color_Blue", -1).asInt();
295  if ((red > -1) && (red < static_cast<int>(cColor::COLOR_LIMIT)) && (green > -1) && (green < static_cast<int>(cColor::COLOR_LIMIT)) && (blue > -1) && (blue < static_cast<int>(cColor::COLOR_LIMIT)))
296  {
297  m_ItemColor.SetColor(static_cast<unsigned char>(red), static_cast<unsigned char>(green), static_cast<unsigned char>(blue));
298  }
299  else if ((red != -1) || (blue != -1) || (green != -1))
300  {
301  LOGWARNING("Item with invalid red, green, and blue values read in from json file.");
302  }
303 
305  {
306  m_FireworkItem.m_HasFlicker = a_Value.get("Flicker", false).asBool();
307  m_FireworkItem.m_HasTrail = a_Value.get("Trail", false).asBool();
308  m_FireworkItem.m_Type = static_cast<NIBBLETYPE>(a_Value.get("Type", 0).asInt());
309  m_FireworkItem.m_FlightTimeInTicks = static_cast<short>(a_Value.get("FlightTimeInTicks", 0).asInt());
310  m_FireworkItem.ColoursFromString(a_Value.get("Colours", "").asString(), m_FireworkItem);
311  m_FireworkItem.FadeColoursFromString(a_Value.get("FadeColours", "").asString(), m_FireworkItem);
312  }
313 
314  m_RepairCost = a_Value.get("RepairCost", 0).asInt();
315  }
316 }
317 
318 
319 
320 
321 
322 bool cItem::IsEnchantable(short a_ItemType, bool a_FromBook)
323 {
324  if (
325  ItemCategory::IsAxe(a_ItemType) ||
326  ItemCategory::IsSword(a_ItemType) ||
327  ItemCategory::IsShovel(a_ItemType) ||
328  ItemCategory::IsPickaxe(a_ItemType) ||
329  (a_FromBook && ItemCategory::IsHoe(a_ItemType)) ||
330  ItemCategory::IsArmor(a_ItemType)
331  )
332  {
333  return true;
334  }
335 
336  switch (a_ItemType)
337  {
338  case E_ITEM_BOOK:
339  case E_ITEM_BOW:
340  case E_ITEM_FISHING_ROD:
341  {
342  return true;
343  }
344 
346  case E_ITEM_SHEARS:
348  {
349  return a_FromBook;
350  }
351  }
352 
353  return false;
354 }
355 
356 
357 
358 
359 
361 {
362  switch (m_ItemType)
363  {
364  case E_ITEM_WOODEN_SWORD:
367  case E_ITEM_WOODEN_AXE:
368  case E_ITEM_WOODEN_HOE: return 15;
369 
370  case E_ITEM_LEATHER_CAP:
373  case E_ITEM_LEATHER_BOOTS: return 15;
374 
375  case E_ITEM_STONE_SWORD:
377  case E_ITEM_STONE_SHOVEL:
378  case E_ITEM_STONE_AXE:
379  case E_ITEM_STONE_HOE: return 5;
380 
381  case E_ITEM_IRON_HELMET:
384  case E_ITEM_IRON_BOOTS: return 9;
385 
386  case E_ITEM_IRON_SWORD:
387  case E_ITEM_IRON_PICKAXE:
388  case E_ITEM_IRON_SHOVEL:
389  case E_ITEM_IRON_AXE:
390  case E_ITEM_IRON_HOE: return 14;
391 
392  case E_ITEM_CHAIN_HELMET:
395  case E_ITEM_CHAIN_BOOTS: return 12;
396 
400  case E_ITEM_DIAMOND_BOOTS: return 10;
401 
405  case E_ITEM_DIAMOND_AXE:
406  case E_ITEM_DIAMOND_HOE: return 10;
407 
408  case E_ITEM_GOLD_HELMET:
411  case E_ITEM_GOLD_BOOTS: return 25;
412 
413  case E_ITEM_GOLD_SWORD:
414  case E_ITEM_GOLD_PICKAXE:
415  case E_ITEM_GOLD_SHOVEL:
416  case E_ITEM_GOLD_AXE:
417  case E_ITEM_GOLD_HOE: return 22;
418 
419  case E_ITEM_FISHING_ROD:
420  case E_ITEM_BOW:
421  case E_ITEM_BOOK: return 1;
422  }
423 
424  return 0;
425 }
426 
427 
428 
429 
430 
431 bool cItem::EnchantByXPLevels(unsigned a_NumXPLevels, MTRand & a_Random)
432 {
434  {
435  return false;
436  }
437 
438  const auto Enchantability = GetEnchantability();
439  if (Enchantability == 0)
440  {
441  return false;
442  }
443 
444  const auto ModifiedEnchantmentLevel = a_NumXPLevels + a_Random.RandInt(Enchantability / 4) + a_Random.RandInt(Enchantability / 4) + 1;
445  const auto RandomBonus = 1.0F + (a_Random.RandReal() + a_Random.RandReal() - 1.0F) * 0.15F;
446  const auto FinalEnchantmentLevel = static_cast<unsigned>(ModifiedEnchantmentLevel * RandomBonus + 0.5F);
447 
448  cWeightedEnchantments Enchantments;
449  cEnchantments::AddItemEnchantmentWeights(Enchantments, m_ItemType, FinalEnchantmentLevel);
450 
451  if (m_ItemType == E_ITEM_BOOK)
452  {
454  }
455 
456  cEnchantments Enchantment1 = cEnchantments::GetRandomEnchantmentFromVector(Enchantments, a_Random);
457  m_Enchantments.AddFromString(Enchantment1.ToString());
458  cEnchantments::RemoveEnchantmentWeightFromVector(Enchantments, Enchantment1);
459 
460  // Checking for conflicting enchantments
461  cEnchantments::CheckEnchantmentConflictsFromVector(Enchantments, Enchantment1);
462 
463  // Next Enchantment (Second)
464  float NewEnchantmentLevel = a_NumXPLevels / 2.0f;
465  float SecondEnchantmentChance = (NewEnchantmentLevel + 1) / 50.0f;
466  if (Enchantments.empty() || !a_Random.RandBool(SecondEnchantmentChance))
467  {
468  return true;
469  }
470 
471  cEnchantments Enchantment2 = cEnchantments::GetRandomEnchantmentFromVector(Enchantments, a_Random);
472  m_Enchantments.AddFromString(Enchantment2.ToString());
473  cEnchantments::RemoveEnchantmentWeightFromVector(Enchantments, Enchantment2);
474 
475  // Checking for conflicting enchantments
476  cEnchantments::CheckEnchantmentConflictsFromVector(Enchantments, Enchantment2);
477 
478  // Next Enchantment (Third)
479  NewEnchantmentLevel = NewEnchantmentLevel / 2.0f;
480  float ThirdEnchantmentChance = (NewEnchantmentLevel + 1) / 50.0f;
481  if (Enchantments.empty() || !a_Random.RandBool(ThirdEnchantmentChance))
482  {
483  return true;
484  }
485 
486  cEnchantments Enchantment3 = cEnchantments::GetRandomEnchantmentFromVector(Enchantments, a_Random);
487  m_Enchantments.AddFromString(Enchantment3.ToString());
488  cEnchantments::RemoveEnchantmentWeightFromVector(Enchantments, Enchantment3);
489 
490  // Checking for conflicting enchantments
491  cEnchantments::CheckEnchantmentConflictsFromVector(Enchantments, Enchantment3);
492 
493  // Next Enchantment (Fourth)
494  NewEnchantmentLevel = NewEnchantmentLevel / 2.0f;
495  float FourthEnchantmentChance = (NewEnchantmentLevel + 1) / 50.0f;
496  if (Enchantments.empty() || !a_Random.RandBool(FourthEnchantmentChance))
497  {
498  return true;
499  }
500  cEnchantments Enchantment4 = cEnchantments::GetRandomEnchantmentFromVector(Enchantments, a_Random);
501  m_Enchantments.AddFromString(Enchantment4.ToString());
502 
503  return true;
504 }
505 
506 
507 
508 
509 
510 int cItem::AddEnchantment(int a_EnchantmentID, unsigned int a_Level, bool a_FromBook)
511 {
512  unsigned int OurLevel = m_Enchantments.GetLevel(a_EnchantmentID);
513  int Multiplier = cEnchantments::GetXPCostMultiplier(a_EnchantmentID, a_FromBook);
514  unsigned int NewLevel = 0;
515  if (OurLevel > a_Level)
516  {
517  // They don't add anything to us
518  NewLevel = OurLevel;
519  }
520  else if (OurLevel == a_Level)
521  {
522  // Bump it by 1
523  NewLevel = OurLevel + 1;
524  }
525  else
526  {
527  // Take the sacrifice's level
528  NewLevel = a_Level;
529  }
530  unsigned int LevelCap = cEnchantments::GetLevelCap(a_EnchantmentID);
531  if (NewLevel > LevelCap)
532  {
533  NewLevel = LevelCap;
534  }
535 
536  m_Enchantments.SetLevel(a_EnchantmentID, NewLevel);
537  return static_cast<int>(NewLevel) * Multiplier;
538 }
539 
540 
541 
542 
543 
544 bool cItem::CanHaveEnchantment(int a_EnchantmentID)
545 {
547  {
548  // Enchanted books can take anything
549  return true;
550  }
551 
552  // The organization here is based on the summary at:
553  // https://minecraft.wiki/w/Enchanting
554  // as of July 2017 (Minecraft 1.12).
555 
556  // Hand tool enchantments
557  static const std::set<int> SwordEnchantments =
558  {
566  };
567  static const std::set<int> AxeEnchantments =
568  {
576  };
577  static const std::set<int> ToolEnchantments =
578  {
583  };
584  static const std::set<int> ShearEnchantments =
585  {
588  };
589  static const std::set<int> BowEnchantments =
590  {
595  };
596  static const std::set<int> FishingEnchantments =
597  {
600  };
601  static const std::set<int> MiscEnchantments =
602  {
604  };
605 
607  {
608  return SwordEnchantments.count(a_EnchantmentID) > 0;
609  }
611  {
612  return AxeEnchantments.count(a_EnchantmentID) > 0;
613  }
615  {
616  return ToolEnchantments.count(a_EnchantmentID) > 0;
617  }
618  if (m_ItemType == E_ITEM_SHEARS)
619  {
620  return ShearEnchantments.count(a_EnchantmentID) > 0;
621  }
622  if (m_ItemType == E_ITEM_BOW)
623  {
624  return BowEnchantments.count(a_EnchantmentID) > 0;
625  }
627  {
628  return FishingEnchantments.count(a_EnchantmentID) > 0;
629  }
631  {
632  return MiscEnchantments.count(a_EnchantmentID) > 0;
633  }
634 
635  // Armor enchantments
636  static const std::set<int> ArmorEnchantments =
637  {
644  };
645  static const std::set<int> HatOnlyEnchantments =
646  {
649  };
650  static const std::set<int> BootOnlyEnchantments =
651  {
654  };
655 
657  {
658  return (BootOnlyEnchantments.count(a_EnchantmentID) > 0) || (ArmorEnchantments.count(a_EnchantmentID) > 0);
659  }
661  {
662  return (HatOnlyEnchantments.count(a_EnchantmentID) > 0) || (ArmorEnchantments.count(a_EnchantmentID) > 0);
663  }
665  {
666  return ArmorEnchantments.count(a_EnchantmentID) > 0;
667  }
668  return false;
669 }
670 
671 
672 
673 
674 
676 {
677  bool FromBook = (a_Other.m_ItemType == E_ITEM_ENCHANTED_BOOK);
678 
679  // Consider each enchantment seperately
680  int EnchantingCost = 0;
681  for (auto & Enchantment : a_Other.m_Enchantments)
682  {
683  if (CanHaveEnchantment(Enchantment.first))
684  {
685  if (!m_Enchantments.CanAddEnchantment(Enchantment.first))
686  {
687  // Cost of incompatible enchantments
688  EnchantingCost += 1;
689  }
690  else
691  {
692  EnchantingCost += AddEnchantment(Enchantment.first, Enchantment.second, FromBook);
693  }
694  }
695  }
696  return EnchantingCost;
697 }
698 
699 
700 
701 
702 
704 // cItems:
705 
706 cItems::cItems(cItem && a_InitialItem)
707 {
708  push_back(std::move(a_InitialItem));
709 }
710 
711 
712 
713 
714 
715 cItem * cItems::Get(int a_Idx)
716 {
717  if ((a_Idx < 0) || (a_Idx >= static_cast<int>(size())))
718  {
719  LOGWARNING("cItems: Attempt to get an out-of-bounds item at index %d; there are currently %zu items. Returning a nil.", a_Idx, size());
720  return nullptr;
721  }
722  return &at(static_cast<size_t>(a_Idx));
723 }
724 
725 
726 
727 
728 
729 void cItems::Set(int a_Idx, const cItem & a_Item)
730 {
731  if ((a_Idx < 0) || (a_Idx >= static_cast<int>(size())))
732  {
733  LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %zu items. Not setting.", a_Idx, size());
734  return;
735  }
736  at(static_cast<size_t>(a_Idx)) = a_Item;
737 }
738 
739 
740 
741 
742 
743 void cItems::Delete(int a_Idx)
744 {
745  if ((a_Idx < 0) || (a_Idx >= static_cast<int>(size())))
746  {
747  LOGWARNING("cItems: Attempt to delete an item at an out-of-bounds index %d; there are currently %zu items. Ignoring.", a_Idx, size());
748  return;
749  }
750  erase(begin() + a_Idx);
751 }
752 
753 
754 
755 
756 
757 void cItems::Set(int a_Idx, short a_ItemType, char a_ItemCount, short a_ItemDamage)
758 {
759  if ((a_Idx < 0) || (a_Idx >= static_cast<int>(size())))
760  {
761  LOGWARNING("cItems: Attempt to set an item at an out-of-bounds index %d; there are currently %zu items. Not setting.", a_Idx, size());
762  return;
763  }
764  at(static_cast<size_t>(a_Idx)) = cItem(a_ItemType, a_ItemCount, a_ItemDamage);
765 }
766 
767 
768 
769 
770 
771 bool cItems::Contains(const cItem & a_Item)
772 {
773  for (const auto & itr : *this)
774  {
775  if (a_Item.IsEqual(itr))
776  {
777  return true;
778  }
779  }
780  return false;
781 }
782 
783 
784 
785 
786 
787 bool cItems::ContainsType(const cItem & a_Item)
788 {
789  for (const auto & itr : *this)
790  {
791  if (a_Item.IsSameType(itr))
792  {
793  return true;
794  }
795  }
796  return false;
797 }
798 
799 
800 
801 
802 
803 void cItems::AddItemGrid(const cItemGrid & a_ItemGrid)
804 {
805  for (int i = 0; i < a_ItemGrid.GetNumSlots(); ++i)
806  {
807  const auto & Slot = a_ItemGrid.GetSlot(i);
808  if (!Slot.IsEmpty())
809  {
810  Add(Slot);
811  }
812  }
813 }
@ E_BLOCK_AIR
Definition: BlockType.h:10
ENUM_ITEM_TYPE
Definition: BlockType.h:295
@ E_ITEM_WOODEN_PICKAXE
Definition: BlockType.h:314
@ E_ITEM_GOLD_BOOTS
Definition: BlockType.h:361
@ E_ITEM_STONE_PICKAXE
Definition: BlockType.h:318
@ E_ITEM_DIAMOND_AXE
Definition: BlockType.h:323
@ E_ITEM_LEATHER_PANTS
Definition: BlockType.h:344
@ E_ITEM_FIREWORK_STAR
Definition: BlockType.h:448
@ E_ITEM_CHAIN_BOOTS
Definition: BlockType.h:349
@ E_ITEM_IRON_LEGGINGS
Definition: BlockType.h:352
@ E_ITEM_EMPTY
Definition: BlockType.h:296
@ E_ITEM_DIAMOND_BOOTS
Definition: BlockType.h:357
@ E_ITEM_STONE_AXE
Definition: BlockType.h:319
@ E_ITEM_CHAIN_HELMET
Definition: BlockType.h:346
@ E_ITEM_IRON_HOE
Definition: BlockType.h:336
@ E_ITEM_GOLD_HELMET
Definition: BlockType.h:358
@ E_ITEM_IRON_SWORD
Definition: BlockType.h:311
@ E_ITEM_GOLD_CHESTPLATE
Definition: BlockType.h:359
@ E_ITEM_IRON_HELMET
Definition: BlockType.h:350
@ E_ITEM_DIAMOND_HOE
Definition: BlockType.h:337
@ E_ITEM_DIAMOND_PICKAXE
Definition: BlockType.h:322
@ E_ITEM_FISHING_ROD
Definition: BlockType.h:391
@ E_ITEM_WOODEN_HOE
Definition: BlockType.h:334
@ E_ITEM_IRON_CHESTPLATE
Definition: BlockType.h:351
@ E_ITEM_GOLD_LEGGINGS
Definition: BlockType.h:360
@ E_ITEM_DIAMOND_CHESTPLATE
Definition: BlockType.h:355
@ E_ITEM_SHIELD
Definition: BlockType.h:489
@ E_ITEM_DIAMOND_HELMET
Definition: BlockType.h:354
@ E_ITEM_IRON_BOOTS
Definition: BlockType.h:353
@ E_ITEM_GOLD_SHOVEL
Definition: BlockType.h:328
@ E_ITEM_IRON_PICKAXE
Definition: BlockType.h:301
@ E_ITEM_GOLD_PICKAXE
Definition: BlockType.h:329
@ E_ITEM_FIREWORK_ROCKET
Definition: BlockType.h:447
@ E_ITEM_BOOK
Definition: BlockType.h:385
@ E_ITEM_WOODEN_SHOVEL
Definition: BlockType.h:313
@ E_ITEM_LEATHER_TUNIC
Definition: BlockType.h:343
@ E_ITEM_ELYTRA
Definition: BlockType.h:490
@ E_ITEM_DIAMOND_SWORD
Definition: BlockType.h:320
@ E_ITEM_IRON_SHOVEL
Definition: BlockType.h:300
@ E_ITEM_GOLD_HOE
Definition: BlockType.h:338
@ E_ITEM_STONE_SWORD
Definition: BlockType.h:316
@ E_ITEM_STONE_SHOVEL
Definition: BlockType.h:317
@ E_ITEM_DIAMOND_LEGGINGS
Definition: BlockType.h:356
@ E_ITEM_ENCHANTED_BOOK
Definition: BlockType.h:449
@ E_ITEM_DIAMOND_SHOVEL
Definition: BlockType.h:321
@ E_ITEM_STONE_HOE
Definition: BlockType.h:335
@ E_ITEM_WOODEN_SWORD
Definition: BlockType.h:312
@ E_ITEM_LEATHER_CAP
Definition: BlockType.h:342
@ E_ITEM_CARROT_ON_STICK
Definition: BlockType.h:444
@ E_ITEM_WOODEN_AXE
Definition: BlockType.h:315
@ E_ITEM_GOLD_AXE
Definition: BlockType.h:330
@ E_ITEM_GOLD_SWORD
Definition: BlockType.h:327
@ E_ITEM_CHAIN_CHESTPLATE
Definition: BlockType.h:347
@ E_ITEM_SHEARS
Definition: BlockType.h:404
@ E_ITEM_LEATHER_BOOTS
Definition: BlockType.h:345
@ E_ITEM_FLINT_AND_STEEL
Definition: BlockType.h:303
@ E_ITEM_CHAIN_LEGGINGS
Definition: BlockType.h:348
@ E_ITEM_IRON_AXE
Definition: BlockType.h:302
@ E_ITEM_BOW
Definition: BlockType.h:305
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
bool IsValidItem(int a_ItemType)
Returns true if the specified item type is valid (known).
Definition: Defines.cpp:172
std::vector< cWeightedEnchantment > cWeightedEnchantments
Definition: Enchantments.h:23
void LOGWARNING(std::string_view a_Format, const Args &... args)
Definition: LoggerSimple.h:67
std::vector< AString > AStringVector
Definition: StringUtils.h:12
std::string AString
Definition: StringUtils.h:11
bool IsHoe(short a_ItemType)
Definition: Defines.cpp:473
bool IsHelmet(short a_ItemType)
Definition: Defines.cpp:512
bool IsPickaxe(short a_ItemType)
Definition: Defines.cpp:414
bool IsAxe(short a_ItemType)
Definition: Defines.cpp:437
bool IsArmor(short a_ItemType)
Definition: Defines.cpp:588
bool IsBoots(short a_ItemType)
Definition: Defines.cpp:558
bool IsShovel(short a_ItemType)
Definition: Defines.cpp:486
bool IsSword(short a_ItemType)
Definition: Defines.cpp:460
void SetColor(unsigned char a_Red, unsigned char a_Green, unsigned char a_Blue)
Changes the color.
Definition: Color.cpp:19
unsigned char GetRed() const
Returns the red value of the color.
Definition: Color.cpp:55
@ COLOR_LIMIT
Definition: Color.h:21
unsigned char GetGreen() const
Returns the green value of the color.
Definition: Color.cpp:64
void Clear()
Resets the color.
Definition: Color.h:53
unsigned char GetBlue() const
Returns the blue value of the color.
Definition: Color.cpp:73
bool IsValid() const
Returns whether the color is a valid color.
Definition: Color.h:28
Class that stores item enchantments or stored-enchantments The enchantments may be serialized to a st...
Definition: Enchantments.h:42
bool CanAddEnchantment(int a_EnchantmentID) const
Returns true if the given enchantment could be legally added to this object.
void Clear(void)
Removes all enchantments.
@ enchProjectileProtection
Definition: Enchantments.h:54
void SetLevel(int a_EnchantmentID, unsigned int a_Level)
Sets the level for the specified enchantment, adding it if not stored before or removing it if level ...
static unsigned int GetLevelCap(int a_EnchantmentID)
Get the maximum level the enchantment can have.
unsigned int GetLevel(int a_EnchantmentID) const
Returns the level for the specified enchantment; 0 if not stored.
static void RemoveEnchantmentWeightFromVector(cWeightedEnchantments &a_Enchantments, int a_EnchantmentID)
Remove the entire enchantment (with weight) from the vector.
void AddFromString(const AString &a_StringSpec)
Adds enchantments in the stringspec; if a specified enchantment already exists, overwrites it.
AString ToString(void) const
Serializes all the enchantments into a string.
static cEnchantments GetRandomEnchantmentFromVector(const cWeightedEnchantments &a_Enchantments, MTRand &a_Random)
Gets random enchantment from Vector and returns it, with randomness derived from the provided PRNG.
static int GetXPCostMultiplier(int a_EnchantmentID, bool FromBook)
Get the XP cost multiplier for the enchantment (for anvils).
static void CheckEnchantmentConflictsFromVector(cWeightedEnchantments &a_Enchantments, const cEnchantments &a_FirstEnchantment)
Check enchantment conflicts from enchantments from the vector.
static void AddItemEnchantmentWeights(cWeightedEnchantments &a_Enchantments, short a_ItemType, unsigned a_EnchantmentLevel)
Add enchantment weights from item to the vector.
Class to wrap any random engine to provide a more convenient interface.
Definition: FastRandom.h:58
RealType RandReal(RealType a_Min, RealType a_Max)
Return a random RealType in the range [a_Min, a_Max).
Definition: FastRandom.h:123
IntType RandInt(IntType a_Min, IntType a_Max)
Return a random IntType in the range [a_Min, a_Max].
Definition: FastRandom.h:78
bool RandBool(double a_TrueProbability=0.5)
Return a random bool with the given probability of being true.
Definition: FastRandom.h:158
Definition: Item.h:37
void FromJson(const Json::Value &a_Value)
Loads the item data from JSON representation.
Definition: Item.cpp:276
cItem & AddCount(char a_AmountToAdd)
Adds the specified count to this object and returns the reference to self (useful for chaining)
Definition: Item.cpp:104
const cItemHandler & GetHandler(void) const
Returns the cItemHandler responsible for this item type.
Definition: Item.cpp:216
bool CanHaveEnchantment(int a_EnchantmentID)
Returns whether or not this item is allowed to have the given enchantment.
Definition: Item.cpp:544
static bool IsEnchantable(short a_ItemType, bool a_FromBook=false)
Returns true if the specified item type is enchantable.
Definition: Item.cpp:322
cEnchantments m_Enchantments
Definition: Item.h:166
bool IsCustomNameEmpty(void) const
Definition: Item.h:101
bool EnchantByXPLevels(unsigned a_NumXPLevels, MTRand &a_Random)
Randomly enchants the item using the specified number of XP levels.
Definition: Item.cpp:431
char m_ItemCount
Definition: Item.h:164
bool DamageItem(short a_Amount=1)
Damages a weapon / tool.
Definition: Item.cpp:181
AString m_CustomName
Definition: Item.h:167
unsigned GetEnchantability()
Returns the enchantability of the item.
Definition: Item.cpp:360
void GetJson(Json::Value &a_OutValue) const
Saves the item data into JSON representation.
Definition: Item.cpp:225
char GetMaxStackSize(void) const
Returns the maximum amount of stacked items of this type.
Definition: Item.cpp:207
cColor m_ItemColor
Definition: Item.h:202
bool IsLoreEmpty(void) const
Definition: Item.h:102
bool IsEqual(const cItem &a_Item) const
Definition: Item.h:76
int AddEnchantment(int a_EnchantmentID, unsigned int a_Level, bool a_FromBook)
Adds this specific enchantment to this item, returning the cost.
Definition: Item.cpp:510
AStringVector m_LoreTable
Definition: Item.h:171
short m_ItemType
Definition: Item.h:163
void Clear(void)
Empties the item and frees up any dynamic storage used by the internals.
Definition: Item.cpp:80
int AddEnchantmentsFromItem(const cItem &a_Other)
Adds the enchantments on a_Other to this item, returning the XP cost of the transfer.
Definition: Item.cpp:675
int m_RepairCost
Definition: Item.h:200
void Empty(void)
Empties the item and frees up any dynamic storage used by the internals.
Definition: Item.cpp:63
short GetMaxDamage(void) const
Returns the maximum damage value that this item can have; zero if damage is not applied.
Definition: Item.cpp:118
bool IsFullStack(void) const
Returns true if the item is stacked up to its maximum stacking.
Definition: Item.cpp:198
cFireworkItem m_FireworkItem
Definition: Item.h:201
cItem CopyOne(void) const
Returns a copy of this item with m_ItemCount set to 1.
Definition: Item.cpp:93
cItem(void)
Creates an empty item.
Definition: Item.cpp:16
short m_ItemDamage
Definition: Item.h:165
bool IsSameType(const cItem &a_Item) const
Definition: Item.h:89
bool Contains(const cItem &a_Item)
Definition: Item.cpp:771
cItems(void)
Need a Lua-accessible constructor.
Definition: Item.h:229
void Delete(int a_Idx)
Definition: Item.cpp:743
cItem * Get(int a_Idx)
Definition: Item.cpp:715
bool ContainsType(const cItem &a_Item)
Definition: Item.cpp:787
void AddItemGrid(const cItemGrid &a_ItemGrid)
Adds a copy of all items in a_ItemGrid.
Definition: Item.cpp:803
void Add(const cItem &a_Item)
Definition: Item.h:233
void Set(int a_Idx, const cItem &a_Item)
Definition: Item.cpp:729
const cItem & GetSlot(int a_X, int a_Y) const
Definition: ItemGrid.cpp:96
int GetNumSlots(void) const
Definition: ItemGrid.h:40
static const cItemHandler & For(int a_ItemType)
virtual char GetMaxStackSize(void) const
Returns the maximum stack size for a given item.
static AString FadeColoursToString(const cFireworkItem &a_FireworkItem)
Converts the firework's vector of fade colours into a string of values separated by a semicolon.
static void FadeColoursFromString(const AString &a_String, cFireworkItem &a_FireworkItem)
Parses a string containing encoded firework fade colours and populates a FireworkItem with it.
static AString ColoursToString(const cFireworkItem &a_FireworkItem)
Converts the firework's vector of colours into a string of values separated by a semicolon.
static void ColoursFromString(const AString &a_String, cFireworkItem &a_FireworkItem)
Parses a string containing encoded firework colours and populates a FireworkItem with it.
void EmptyData(void)