Fix item durability.

Fixes #1181
This commit is contained in:
Howaner
2014-07-23 16:32:09 +02:00
parent 63cc008340
commit 396739cc0f
16 changed files with 149 additions and 69 deletions
+30 -2
View File
@@ -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;
}
+15 -2
View File
@@ -19,6 +19,13 @@ class cPlayer;
class cItemHandler
{
public:
enum eDurabilityLostAction
{
dlaBreakBlock,
dlaAttackEntity,
};
cItemHandler(int a_ItemType);
/** Force virtual destructor */
@@ -48,11 +55,17 @@ public:
virtual bool OnDiggingBlock(cWorld * a_World, cPlayer * a_Player, const cItem & a_HeldItem, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace);
/** Called when the player destroys a block using this item. This also calls the drop function for the destroyed block */
virtual void OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_X, int a_Y, int a_Z);
virtual void OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ);
/** Called when a player attacks a other entity. */
virtual void OnEntityAttack(cPlayer * a_Attacker, cEntity * a_AttackedEntity);
/** Called after the player has eaten this item. */
virtual void OnFoodEaten(cWorld *a_World, cPlayer *a_Player, cItem *a_Item);
/** Get the durability lost which the item will get, when a specified action was performed. */
virtual short GetDurabilityLostWithThatAction(eDurabilityLostAction a_Action);
/** Returns the maximum stack size for a given item */
virtual char GetMaxStackSize(void);
+7 -3
View File
@@ -16,7 +16,6 @@ public:
cItemHoeHandler(int a_ItemType)
: cItemHandler(a_ItemType)
{
}
virtual bool OnItemUse(cWorld *a_World, cPlayer *a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override
@@ -26,13 +25,18 @@ public:
if ((Block == E_BLOCK_DIRT) || (Block == E_BLOCK_GRASS))
{
a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_FARMLAND, 0);
a_Player->UseEquippedItem();
return true;
}
return false;
}
virtual short GetDurabilityLostWithThatAction(eDurabilityLostAction a_Action) override
{
return 0;
}
} ;
+24 -1
View File
@@ -12,6 +12,7 @@
class cItemShearsHandler :
public cItemHandler
{
typedef cItemHandler super;
public:
cItemShearsHandler(int a_ItemType) :
cItemHandler(a_ItemType)
@@ -30,8 +31,12 @@ public:
BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
if ((Block == E_BLOCK_LEAVES) || (Block == E_BLOCK_NEW_LEAVES))
{
NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
cBlockHandler * Handler = cBlockInfo::GetHandler(Block);
cItems Drops;
Drops.push_back(cItem(Block, 1, a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x03));
Handler->ConvertToPickups(Drops, Meta);
Drops.push_back(cItem(Block, 1, Meta & 3));
a_World->SpawnItemPickups(Drops, a_BlockX, a_BlockY, a_BlockZ);
a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0);
@@ -56,6 +61,24 @@ public:
} // switch (a_BlockType)
return false;
}
virtual short GetDurabilityLostWithThatAction(eDurabilityLostAction a_Action) override
{
return 0;
}
virtual void OnBlockDestroyed(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ) override
{
super::OnBlockDestroyed(a_World, a_Player, a_Item, a_BlockX, a_BlockY, a_BlockZ);
BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
if ((Block == E_BLOCK_TRIPWIRE) || (Block == E_BLOCK_VINES))
{
a_Player->UseEquippedItem();
}
}
} ;
+15 -2
View File
@@ -12,18 +12,20 @@
class cItemSwordHandler :
public cItemHandler
{
typedef cItemHandler super;
public:
cItemSwordHandler(int a_ItemType)
: cItemHandler(a_ItemType)
{
}
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType) override
{
return (a_BlockType == E_BLOCK_COBWEB);
}
virtual bool CanRepairWithRawMaterial(short a_ItemType) override
{
switch (m_ItemType)
@@ -36,6 +38,17 @@ public:
}
return false;
}
virtual short GetDurabilityLostWithThatAction(eDurabilityLostAction a_Action) override
{
switch (a_Action)
{
case dlaAttackEntity: return 1;
case dlaBreakBlock: return 2;
}
return 0;
}
} ;