Cuberite
A lightweight, fast and extensible game server for Minecraft
ItemSword.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "ItemHandler.h"
5 
6 
7 
8 
9 
11  public cItemHandler
12 {
14 public:
15  cItemSwordHandler(int a_ItemType)
16  : cItemHandler(a_ItemType)
17  {
18  }
19 
20 
21  virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType) override
22  {
23  if (a_BlockType == E_BLOCK_COBWEB)
24  {
25  return true;
26  }
27  return super::CanHarvestBlock(a_BlockType);
28  }
29 
30 
31  virtual bool CanRepairWithRawMaterial(short a_ItemType) override
32  {
33  switch (m_ItemType)
34  {
35  case E_ITEM_WOODEN_SWORD: return (a_ItemType == E_BLOCK_PLANKS);
36  case E_ITEM_STONE_SWORD: return (a_ItemType == E_BLOCK_COBBLESTONE);
37  case E_ITEM_IRON_SWORD: return (a_ItemType == E_ITEM_IRON);
38  case E_ITEM_GOLD_SWORD: return (a_ItemType == E_ITEM_GOLD);
39  case E_ITEM_DIAMOND_SWORD: return (a_ItemType == E_ITEM_DIAMOND);
40  }
41  return false;
42  }
43 
44 
45  virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) override
46  {
47  switch (a_Action)
48  {
49  case dlaAttackEntity: return 1;
50  case dlaBreakBlock: return 2;
51  case dlaBreakBlockInstant: return 0;
52  }
53  UNREACHABLE("Unsupported durability loss action");
54  }
55 
56 
57 
58  virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) override
59  {
60  if (a_Block == E_BLOCK_COBWEB)
61  {
62  return 15.0f;
63  }
64  else
65  {
66  if (
67  IsBlockMaterialPlants(a_Block) ||
68  IsBlockMaterialVine(a_Block) ||
69  IsBlockMaterialCoral(a_Block) ||
70  IsBlockMaterialLeaves(a_Block) ||
71  IsBlockMaterialGourd(a_Block)
72  )
73  {
74  return 1.5f;
75  }
76  else
77  {
78  return 1.0f;
79  }
80  }
81  }
82 
83 } ;
bool IsBlockMaterialVine(BLOCKTYPE a_BlockType)
Definition: Defines.h:659
bool IsBlockMaterialPlants(BLOCKTYPE a_BlockType)
Definition: Defines.h:624
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) override
Returns the strength to break a specific block.
Definition: ItemSword.h:58
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) override
Get the durability lost which the item will get, when a specified action was performed.
Definition: ItemSword.h:45
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType)
Returns whether this tool / item can harvest a specific block (e.g.
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType) override
Returns whether this tool / item can harvest a specific block (e.g.
Definition: ItemSword.h:21
bool IsBlockMaterialCoral(BLOCKTYPE a_BlockType)
Definition: Defines.h:774
cItemSwordHandler(int a_ItemType)
Definition: ItemSword.h:15
cItemHandler super
Definition: ItemSword.h:13
bool IsBlockMaterialLeaves(BLOCKTYPE a_BlockType)
Definition: Defines.h:735
eDurabilityLostAction
Actions that may cause durability of an item may be lost, where the magnitude of the loss depends on ...
Definition: ItemHandler.h:27
#define UNREACHABLE(x)
Use to mark code that should be impossible to reach.
Definition: Globals.h:344
bool IsBlockMaterialGourd(BLOCKTYPE a_BlockType)
Definition: Defines.h:753
virtual bool CanRepairWithRawMaterial(short a_ItemType) override
Can the anvil repair this item, when a_Item is the second input?
Definition: ItemSword.h:31