summaryrefslogtreecommitdiffstats
path: root/src/Entities/Player.cpp
diff options
context:
space:
mode:
authorMasy98 <masy@antheruscraft.de>2014-09-01 21:30:45 +0200
committerMasy98 <masy@antheruscraft.de>2014-09-01 21:30:45 +0200
commitcc9acd13b90c2dff21b6a7b7d4db57780aba0fc7 (patch)
treede161c8abb3a9fb961b794e4d4cf255102b83715 /src/Entities/Player.cpp
parentFixed spacing and light gray wool name! (diff)
parentMerge pull request #1368 from mc-server/coverityFixes (diff)
downloadcuberite-cc9acd13b90c2dff21b6a7b7d4db57780aba0fc7.tar
cuberite-cc9acd13b90c2dff21b6a7b7d4db57780aba0fc7.tar.gz
cuberite-cc9acd13b90c2dff21b6a7b7d4db57780aba0fc7.tar.bz2
cuberite-cc9acd13b90c2dff21b6a7b7d4db57780aba0fc7.tar.lz
cuberite-cc9acd13b90c2dff21b6a7b7d4db57780aba0fc7.tar.xz
cuberite-cc9acd13b90c2dff21b6a7b7d4db57780aba0fc7.tar.zst
cuberite-cc9acd13b90c2dff21b6a7b7d4db57780aba0fc7.zip
Diffstat (limited to 'src/Entities/Player.cpp')
-rw-r--r--src/Entities/Player.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index b0dd40615..756410989 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -15,6 +15,7 @@
#include "../Chunk.h"
#include "../Items/ItemHandler.h"
#include "../Vector3.h"
+#include "../FastRandom.h"
#include "../WorldStorage/StatSerializer.h"
#include "../CompositeChat.h"
@@ -1795,6 +1796,28 @@ void cPlayer::UseEquippedItem(int a_Amount)
return;
}
+ // If the item has an unbreaking enchantment, give it a random chance of not breaking:
+ 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(101) <= 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));