From 396739cc0faf01a099acbe669c5a9def98d3aaae Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 23 Jul 2014 16:32:09 +0200 Subject: Fix item durability. Fixes #1181 --- src/Items/ItemHandler.cpp | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'src/Items/ItemHandler.cpp') diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index bf1d4e4cb..f0a91214d 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -335,8 +335,21 @@ void cItemHandler::OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const Handler->DropBlock(ChunkInterface, *a_World, PluginInterface, a_Player, a_BlockX, a_BlockY, a_BlockZ); } } - - a_Player->UseEquippedItem(); + + if (!cBlockInfo::IsOneHitDig(Block)) + { + a_Player->UseEquippedItem(GetDurabilityLostWithThatAction(dlaBreakBlock)); + } +} + + + + + +void cItemHandler::OnEntityAttack(cPlayer * a_Attacker, cEntity * a_AttackedEntity) +{ + UNUSED(a_AttackedEntity); + a_Attacker->UseEquippedItem(GetDurabilityLostWithThatAction(dlaAttackEntity)); } @@ -354,6 +367,20 @@ void cItemHandler::OnFoodEaten(cWorld * a_World, cPlayer * a_Player, cItem * a_I +short cItemHandler::GetDurabilityLostWithThatAction(eDurabilityLostAction a_Action) +{ + switch (a_Action) + { + case dlaAttackEntity: return 2; + case dlaBreakBlock: return 1; + } + return 0; +} + + + + + char cItemHandler::GetMaxStackSize(void) { if (m_ItemType < 256) @@ -505,6 +532,7 @@ bool cItemHandler::IsPlaceable(void) bool cItemHandler::CanRepairWithRawMaterial(short a_ItemType) { + UNUSED(a_ItemType); return false; } -- cgit v1.2.3 From 4de8f5ca2926068eb855ba19c35de2a63ddebf28 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 26 Jul 2014 13:26:14 +0200 Subject: Rename function. --- src/Items/ItemHandler.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Items/ItemHandler.cpp') diff --git a/src/Items/ItemHandler.cpp b/src/Items/ItemHandler.cpp index e256fa232..ec86648b3 100644 --- a/src/Items/ItemHandler.cpp +++ b/src/Items/ItemHandler.cpp @@ -335,7 +335,7 @@ void cItemHandler::OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const if (!cBlockInfo::IsOneHitDig(Block)) { - a_Player->UseEquippedItem(GetDurabilityLostWithThatAction(dlaBreakBlock)); + a_Player->UseEquippedItem(GetDurabilityLossByAction(dlaBreakBlock)); } } @@ -346,7 +346,7 @@ void cItemHandler::OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const void cItemHandler::OnEntityAttack(cPlayer * a_Attacker, cEntity * a_AttackedEntity) { UNUSED(a_AttackedEntity); - a_Attacker->UseEquippedItem(GetDurabilityLostWithThatAction(dlaAttackEntity)); + a_Attacker->UseEquippedItem(GetDurabilityLossByAction(dlaAttackEntity)); } @@ -364,7 +364,7 @@ void cItemHandler::OnFoodEaten(cWorld * a_World, cPlayer * a_Player, cItem * a_I -short cItemHandler::GetDurabilityLostWithThatAction(eDurabilityLostAction a_Action) +short cItemHandler::GetDurabilityLossByAction(eDurabilityLostAction a_Action) { switch (a_Action) { -- cgit v1.2.3