Cuberite
A lightweight, fast and extensible game server for Minecraft
ItemAxe.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "ItemHandler.h"
5 #include "../BlockInfo.h"
6 
7 
8 
9 
10 
11 class cItemAxeHandler final :
12  public cItemHandler
13 {
15 
16 public:
17 
18  using Super::Super;
19 
20 
21 
22  virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) const override
23  {
24  switch (a_Action)
25  {
26  case dlaAttackEntity: return 2;
27  case dlaBreakBlock: return 1;
28  case dlaBreakBlockInstant: return 0;
29  }
30  UNREACHABLE("Unsupported durability loss action");
31  }
32 
33 
34 
35  virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) const override
36  {
37  if (!IsBlockMaterialWood(a_Block) && !IsBlockMaterialPlants(a_Block) && !IsBlockMaterialVine(a_Block))
38  {
39  return Super::GetBlockBreakingStrength(a_Block);
40  }
41  else
42  {
43  switch (m_ItemType)
44  {
45  case E_ITEM_WOODEN_AXE: return 2.0f;
46  case E_ITEM_STONE_AXE: return 4.0f;
47  case E_ITEM_IRON_AXE: return 6.0f;
48  case E_ITEM_GOLD_AXE: return 12.0f;
49  case E_ITEM_DIAMOND_AXE: return 8.0f;
50  }
51  }
52  ASSERT(!"Something is wrong here... Maybe they are axes out of a new material?");
53  return 1.0f;
54  }
55 
56 } ;
bool IsBlockMaterialVine(BLOCKTYPE a_BlockType)
Definition: BlockInfo.cpp:244
bool IsBlockMaterialWood(BLOCKTYPE a_BlockType)
Definition: BlockInfo.cpp:146
bool IsBlockMaterialPlants(BLOCKTYPE a_BlockType)
Definition: BlockInfo.cpp:209
@ E_ITEM_DIAMOND_AXE
Definition: BlockType.h:323
@ E_ITEM_STONE_AXE
Definition: BlockType.h:319
@ E_ITEM_WOODEN_AXE
Definition: BlockType.h:315
@ E_ITEM_GOLD_AXE
Definition: BlockType.h:330
@ E_ITEM_IRON_AXE
Definition: BlockType.h:302
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
#define UNREACHABLE(x)
Definition: Globals.h:288
#define ASSERT(x)
Definition: Globals.h:276
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) const override
Returns the strength to break a specific block.
Definition: ItemAxe.h:35
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) const override
Get the durability lost which the item will get, when a specified action was performed.
Definition: ItemAxe.h:22
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) const
Returns the strength to break a specific block.
const int m_ItemType
Definition: ItemHandler.h:141
constexpr cItemHandler(int a_ItemType)
Definition: ItemHandler.h:37
eDurabilityLostAction
Actions that may cause durability of an item may be lost, where the magnitude of the loss depends on ...
Definition: ItemHandler.h:31
@ dlaBreakBlockInstant
Definition: ItemHandler.h:34