diff options
author | Jaume Aloy <hircine45@gmail.com> | 2014-08-19 16:08:17 +0200 |
---|---|---|
committer | Jaume Aloy <hircine45@gmail.com> | 2014-08-19 16:08:17 +0200 |
commit | 1897f678f93bb038fdc4caf1fb2995a28ef8f92e (patch) | |
tree | 08feb248f0a51b067fd61192ca10d3272dcd4d90 /src/Entities/Player.cpp | |
parent | Added some Enchantments (diff) | |
download | cuberite-1897f678f93bb038fdc4caf1fb2995a28ef8f92e.tar cuberite-1897f678f93bb038fdc4caf1fb2995a28ef8f92e.tar.gz cuberite-1897f678f93bb038fdc4caf1fb2995a28ef8f92e.tar.bz2 cuberite-1897f678f93bb038fdc4caf1fb2995a28ef8f92e.tar.lz cuberite-1897f678f93bb038fdc4caf1fb2995a28ef8f92e.tar.xz cuberite-1897f678f93bb038fdc4caf1fb2995a28ef8f92e.tar.zst cuberite-1897f678f93bb038fdc4caf1fb2995a28ef8f92e.zip |
Diffstat (limited to 'src/Entities/Player.cpp')
-rw-r--r-- | src/Entities/Player.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index ab4ff3161..c1031907d 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -17,6 +17,7 @@ #include "../Chunk.h" #include "../Items/ItemHandler.h" #include "../Vector3.h" +#include "../FastRandom.h" #include "../WorldStorage/StatSerializer.h" #include "../CompositeChat.h" @@ -1962,7 +1963,26 @@ void cPlayer::UseEquippedItem(int a_Amount) { return; } + cItem Item = GetEquippedItem(); + int UnbreakingLevel = Item.m_Enchantments.GetLevel(cEnchantments::enchUnbreaking); + if (UnbreakingLevel > 0) + { + int chance; + if (ItemCategory::IsArmor(Item.m_ItemType)) + { + chance = 60 + (40 / (UnbreakingLevel + 1)); + } + else + { + chance = 100 / (UnbreakingLevel + 1); + } + cFastRandom Random; + if (Random.NextInt(100) <= chance) + { + return; + } + } if (GetInventory().DamageEquippedItem(a_Amount)) { m_World->BroadcastSoundEffect("random.break", GetPosX(), GetPosY(), GetPosZ(), 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); |