summaryrefslogtreecommitdiffstats
path: root/src/Entities/Player.cpp
diff options
context:
space:
mode:
authorAlexander Harkness <me@bearbin.net>2018-01-05 12:28:06 +0100
committerGitHub <noreply@github.com>2018-01-05 12:28:06 +0100
commitb4aa19f329b06e42eb2591fc488b70dc0df41940 (patch)
tree5b18f7bde0b3129310d273f63b68151850c43ea7 /src/Entities/Player.cpp
parentAdd the fmt library (#4065) (diff)
downloadcuberite-b4aa19f329b06e42eb2591fc488b70dc0df41940.tar
cuberite-b4aa19f329b06e42eb2591fc488b70dc0df41940.tar.gz
cuberite-b4aa19f329b06e42eb2591fc488b70dc0df41940.tar.bz2
cuberite-b4aa19f329b06e42eb2591fc488b70dc0df41940.tar.lz
cuberite-b4aa19f329b06e42eb2591fc488b70dc0df41940.tar.xz
cuberite-b4aa19f329b06e42eb2591fc488b70dc0df41940.tar.zst
cuberite-b4aa19f329b06e42eb2591fc488b70dc0df41940.zip
Diffstat (limited to '')
-rw-r--r--src/Entities/Player.cpp43
1 files changed, 24 insertions, 19 deletions
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 22f0655f2..71f7b582f 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -2330,35 +2330,25 @@ bool cPlayer::SaveToDisk()
-void cPlayer::UseEquippedItem(int a_Amount)
+void cPlayer::UseEquippedItem(short a_Damage)
{
- if (IsGameModeCreative() || IsGameModeSpectator()) // No damage in creative or spectator
+ // No durability loss in creative or spectator modes:
+ if (IsGameModeCreative() || IsGameModeSpectator())
{
return;
}
- // If the item has an unbreaking enchantment, give it a random chance of not breaking:
+ // If the item has an unbreaking enchantment, give it a chance of escaping damage:
+ // Ref: https://minecraft.gamepedia.com/Enchanting#Unbreaking
cItem Item = GetEquippedItem();
int UnbreakingLevel = static_cast<int>(Item.m_Enchantments.GetLevel(cEnchantments::enchUnbreaking));
- if (UnbreakingLevel > 0)
+ double chance = 1 - (1.0 / (UnbreakingLevel + 1));
+ if (GetRandomProvider().RandBool(chance))
{
- double chance = 0.0;
- if (ItemCategory::IsArmor(Item.m_ItemType))
- {
- chance = 0.6 + (0.4 / (UnbreakingLevel + 1));
- }
- else
- {
- chance = 1.0 / (UnbreakingLevel + 1);
- }
-
- if (GetRandomProvider().RandBool(chance))
- {
- return;
- }
+ return;
}
- if (GetInventory().DamageEquippedItem(static_cast<Int16>(a_Amount)))
+ if (GetInventory().DamageEquippedItem(a_Damage))
{
m_World->BroadcastSoundEffect("entity.item.break", GetPosition(), 0.5f, static_cast<float>(0.75 + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64));
}
@@ -2368,6 +2358,21 @@ void cPlayer::UseEquippedItem(int a_Amount)
+void cPlayer::UseEquippedItem(cItemHandler::eDurabilityLostAction a_Action)
+{
+ // Get item being used:
+ cItem Item = GetEquippedItem();
+
+ // Get base damage for action type:
+ short Dmg = cItemHandler::GetItemHandler(Item)->GetDurabilityLossByAction(a_Action);
+
+ UseEquippedItem(Dmg);
+}
+
+
+
+
+
void cPlayer::HandleFood(void)
{
// Ref.: https://minecraft.gamepedia.com/Hunger