Cuberite
A lightweight, fast and extensible game server for Minecraft
|
Class that stores item enchantments or stored-enchantments The enchantments may be serialized to a stringspec and read back from such stringspec. More...
#include <Enchantments.h>
Public Types | |
enum | eEnchantment { enchProtection = 0 , enchFireProtection = 1 , enchFeatherFalling = 2 , enchBlastProtection = 3 , enchProjectileProtection = 4 , enchRespiration = 5 , enchAquaAffinity = 6 , enchThorns = 7 , enchDepthStrider = 8 , enchSharpness = 16 , enchSmite = 17 , enchBaneOfArthropods = 18 , enchKnockback = 19 , enchFireAspect = 20 , enchLooting = 21 , enchEfficiency = 32 , enchSilkTouch = 33 , enchUnbreaking = 34 , enchFortune = 35 , enchPower = 48 , enchPunch = 49 , enchFlame = 50 , enchInfinity = 51 , enchLuckOfTheSea = 61 , enchLure = 62 } |
Individual enchantment IDs, corresponding to their NBT IDs: https://minecraft.wiki/w/Data_values#Enchantment_IDs. More... | |
Public Member Functions | |
void | Add (const cEnchantments &a_Other) |
Adds the enchantments contained in a_Other into this object. More... | |
void | AddFromString (const AString &a_StringSpec) |
Adds enchantments in the stringspec; if a specified enchantment already exists, overwrites it. More... | |
cMap::const_iterator | begin () const |
Make this class iterable. More... | |
bool | CanAddEnchantment (int a_EnchantmentID) const |
Returns true if the given enchantment could be legally added to this object. More... | |
cEnchantments (const AString &a_StringSpec) | |
Creates an enchantments container filled with enchantments parsed from stringspec. More... | |
cEnchantments (void) | |
Creates an empty enchantments container. More... | |
void | Clear (void) |
Removes all enchantments. More... | |
size_t | Count (void) const |
Get the count of enchantments. More... | |
cMap::const_iterator | end () const |
unsigned int | GetLevel (int a_EnchantmentID) const |
Returns the level for the specified enchantment; 0 if not stored. More... | |
bool | IsEmpty (void) const |
Returns true if there are no enchantments. More... | |
bool | operator!= (const cEnchantments &a_Other) const |
Returns true if a_Other doesn't contain exactly the same enchantments and levels. More... | |
bool | operator== (const cEnchantments &a_Other) const |
Returns true if a_Other contains exactly the same enchantments and levels. More... | |
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 <= 0. More... | |
AString | ToString (void) const |
Serializes all the enchantments into a string. More... | |
Static Public Member Functions | |
static void | AddEnchantmentWeightToVector (cWeightedEnchantments &a_Enchantments, int a_Weight, int a_EnchantmentID, unsigned int a_EnchantmentLevel) |
Add a enchantment with weight to the vector. More... | |
static void | AddItemEnchantmentWeights (cWeightedEnchantments &a_Enchantments, short a_ItemType, unsigned a_EnchantmentLevel) |
Add enchantment weights from item to the vector. More... | |
static void | CheckEnchantmentConflictsFromVector (cWeightedEnchantments &a_Enchantments, const cEnchantments &a_FirstEnchantment) |
Check enchantment conflicts from enchantments from the vector. More... | |
static unsigned int | GetLevelCap (int a_EnchantmentID) |
Get the maximum level the enchantment can have. More... | |
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. More... | |
static int | GetXPCostMultiplier (int a_EnchantmentID, bool FromBook) |
Get the XP cost multiplier for the enchantment (for anvils). More... | |
static void | RemoveEnchantmentWeightFromVector (cWeightedEnchantments &a_Enchantments, const cEnchantments &a_Enchantment) |
Remove the entire enchantment (with weight) from the vector. More... | |
static void | RemoveEnchantmentWeightFromVector (cWeightedEnchantments &a_Enchantments, int a_EnchantmentID) |
Remove the entire enchantment (with weight) from the vector. More... | |
static cEnchantments | SelectEnchantmentFromVector (const cWeightedEnchantments &a_Enchantments, int a_Seed) |
Selects one enchantment from a Vector using cNoise. More... | |
static int | StringToEnchantmentID (const AString &a_EnchantmentName) |
Converts enchantment name or ID (number in string) to the numeric representation; returns -1 if enchantment name not found; case insensitive. More... | |
Protected Types | |
typedef std::map< int, unsigned int > | cMap |
Maps enchantment ID -> enchantment level. More... | |
Protected Attributes | |
cMap | m_Enchantments |
Currently stored enchantments. More... | |
Friends | |
void | EnchantmentSerializer::ParseFromNBT (cEnchantments &a_Enchantments, const cParsedNBT &a_NBT, int a_EnchListTagIdx) |
Reads the enchantments from the specified NBT list tag (ench or StoredEnchantments) More... | |
void | EnchantmentSerializer::WriteToNBTCompound (const cEnchantments &a_Enchantments, cFastNBTWriter &a_Writer, const AString &a_ListTagName) |
Writes the enchantments into the specified NBT writer; begins with the LIST tag of the specified name ("ench" or "StoredEnchantments") More... | |
Class that stores item enchantments or stored-enchantments The enchantments may be serialized to a stringspec and read back from such stringspec.
The format for the stringspec is "id=lvl;id=lvl;id=lvl...", with an optional semicolon at the end, mapping each enchantment's id onto its level. ID may be either a number or the enchantment name. Level value of 0 means no such enchantment, and it will not be stored in the m_Enchantments. Serialization will never put zero-level enchantments into the stringspec and will always use numeric IDs.
Definition at line 41 of file Enchantments.h.
|
protected |
Maps enchantment ID -> enchantment level.
Definition at line 162 of file Enchantments.h.
Individual enchantment IDs, corresponding to their NBT IDs: https://minecraft.wiki/w/Data_values#Enchantment_IDs.
Definition at line 47 of file Enchantments.h.
cEnchantments::cEnchantments | ( | void | ) |
Creates an empty enchantments container.
Definition at line 16 of file Enchantments.cpp.
cEnchantments::cEnchantments | ( | const AString & | a_StringSpec | ) |
Creates an enchantments container filled with enchantments parsed from stringspec.
Definition at line 25 of file Enchantments.cpp.
void cEnchantments::Add | ( | const cEnchantments & | a_Other | ) |
Adds the enchantments contained in a_Other into this object.
Existing enchantments are preserved, unless a_Other specifies a different level, in which case the level is changed to the a_Other's one.
Definition at line 34 of file Enchantments.cpp.
|
static |
Add a enchantment with weight to the vector.
Definition at line 1069 of file Enchantments.cpp.
void cEnchantments::AddFromString | ( | const AString & | a_StringSpec | ) |
Adds enchantments in the stringspec; if a specified enchantment already exists, overwrites it.
Definition at line 46 of file Enchantments.cpp.
|
static |
Add enchantment weights from item to the vector.
Definition at line 403 of file Enchantments.cpp.
|
inline |
Make this class iterable.
Definition at line 169 of file Enchantments.h.
bool cEnchantments::CanAddEnchantment | ( | int | a_EnchantmentID | ) | const |
Returns true if the given enchantment could be legally added to this object.
Note that adding the enchantment may not actually increase the level.
Definition at line 282 of file Enchantments.cpp.
|
static |
Check enchantment conflicts from enchantments from the vector.
Definition at line 1115 of file Enchantments.cpp.
void cEnchantments::Clear | ( | void | ) |
Removes all enchantments.
Definition at line 152 of file Enchantments.cpp.
size_t cEnchantments::Count | ( | void | ) | const |
Get the count of enchantments.
Definition at line 88 of file Enchantments.cpp.
|
inline |
Definition at line 170 of file Enchantments.h.
unsigned int cEnchantments::GetLevel | ( | int | a_EnchantmentID | ) | const |
Returns the level for the specified enchantment; 0 if not stored.
Definition at line 112 of file Enchantments.cpp.
|
static |
Get the maximum level the enchantment can have.
Definition at line 170 of file Enchantments.cpp.
|
static |
Gets random enchantment from Vector and returns it, with randomness derived from the provided PRNG.
Definition at line 1173 of file Enchantments.cpp.
|
static |
Get the XP cost multiplier for the enchantment (for anvils).
If FromBook is true, then this function returns the XP multiplier if the enchantment is coming from a book, otherwise it returns the normal item multiplier.
Definition at line 208 of file Enchantments.cpp.
bool cEnchantments::IsEmpty | ( | void | ) | const |
Returns true if there are no enchantments.
Definition at line 161 of file Enchantments.cpp.
bool cEnchantments::operator!= | ( | const cEnchantments & | a_Other | ) | const |
Returns true if a_Other doesn't contain exactly the same enchantments and levels.
Definition at line 394 of file Enchantments.cpp.
bool cEnchantments::operator== | ( | const cEnchantments & | a_Other | ) | const |
Returns true if a_Other contains exactly the same enchantments and levels.
Definition at line 385 of file Enchantments.cpp.
|
static |
Remove the entire enchantment (with weight) from the vector.
Definition at line 1099 of file Enchantments.cpp.
|
static |
Remove the entire enchantment (with weight) from the vector.
Definition at line 1083 of file Enchantments.cpp.
|
static |
Selects one enchantment from a Vector using cNoise.
Mostly used for generators. Uses the enchantments' weights for the random distribution. If a_Enchantments is empty, returns an empty enchantment.
Definition at line 1197 of file Enchantments.cpp.
void cEnchantments::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 <= 0.
Definition at line 129 of file Enchantments.cpp.
|
static |
Converts enchantment name or ID (number in string) to the numeric representation; returns -1 if enchantment name not found; case insensitive.
Definition at line 328 of file Enchantments.cpp.
AString cEnchantments::ToString | ( | void | ) | const |
Serializes all the enchantments into a string.
Definition at line 97 of file Enchantments.cpp.
|
friend |
Reads the enchantments from the specified NBT list tag (ench or StoredEnchantments)
|
friend |
Writes the enchantments into the specified NBT writer; begins with the LIST tag of the specified name ("ench" or "StoredEnchantments")
|
protected |
Currently stored enchantments.
Definition at line 165 of file Enchantments.h.