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 #include "../BlockInfo.h"
6 
7 
8 
9 
10 
11 class cItemSwordHandler final :
12  public cItemHandler
13 {
15 
16 public:
17 
18  using Super::Super;
19 
20  virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType) const override
21  {
22  if (a_BlockType == E_BLOCK_COBWEB)
23  {
24  return true;
25  }
26  return Super::CanHarvestBlock(a_BlockType);
27  }
28 
29 
30  virtual bool CanRepairWithRawMaterial(short a_ItemType) const override
31  {
32  switch (m_ItemType)
33  {
34  case E_ITEM_WOODEN_SWORD: return (a_ItemType == E_BLOCK_PLANKS);
35  case E_ITEM_STONE_SWORD: return (a_ItemType == E_BLOCK_COBBLESTONE);
36  case E_ITEM_IRON_SWORD: return (a_ItemType == E_ITEM_IRON);
37  case E_ITEM_GOLD_SWORD: return (a_ItemType == E_ITEM_GOLD);
38  case E_ITEM_DIAMOND_SWORD: return (a_ItemType == E_ITEM_DIAMOND);
39  }
40  return false;
41  }
42 
43 
44  virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) const override
45  {
46  switch (a_Action)
47  {
48  case dlaAttackEntity: return 1;
49  case dlaBreakBlock: return 2;
50  case dlaBreakBlockInstant: return 0;
51  }
52  UNREACHABLE("Unsupported durability loss action");
53  }
54 
55 
56 
57  virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) const override
58  {
59  if (a_Block == E_BLOCK_COBWEB)
60  {
61  return 15.0f;
62  }
63  else
64  {
65  if (
66  IsBlockMaterialPlants(a_Block) ||
67  IsBlockMaterialVine(a_Block) ||
68  IsBlockMaterialLeaves(a_Block) ||
69  IsBlockMaterialGourd(a_Block)
70  )
71  {
72  return 1.5f;
73  }
74  else
75  {
76  return 1.0f;
77  }
78  }
79  }
80 
81 } ;
bool IsBlockMaterialLeaves(BLOCKTYPE a_BlockType)
Definition: BlockInfo.cpp:302
bool IsBlockMaterialVine(BLOCKTYPE a_BlockType)
Definition: BlockInfo.cpp:244
bool IsBlockMaterialGourd(BLOCKTYPE a_BlockType)
Definition: BlockInfo.cpp:311
bool IsBlockMaterialPlants(BLOCKTYPE a_BlockType)
Definition: BlockInfo.cpp:209
@ E_BLOCK_COBWEB
Definition: BlockType.h:40
@ E_BLOCK_PLANKS
Definition: BlockType.h:15
@ E_BLOCK_COBBLESTONE
Definition: BlockType.h:14
@ E_ITEM_IRON
Definition: BlockType.h:309
@ E_ITEM_GOLD
Definition: BlockType.h:310
@ E_ITEM_IRON_SWORD
Definition: BlockType.h:311
@ E_ITEM_DIAMOND
Definition: BlockType.h:308
@ E_ITEM_DIAMOND_SWORD
Definition: BlockType.h:320
@ E_ITEM_STONE_SWORD
Definition: BlockType.h:316
@ E_ITEM_WOODEN_SWORD
Definition: BlockType.h:312
@ E_ITEM_GOLD_SWORD
Definition: BlockType.h:327
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
#define UNREACHABLE(x)
Definition: Globals.h:288
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
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType) const
Returns whether this tool / item can harvest a specific block (e.g.
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) const override
Get the durability lost which the item will get, when a specified action was performed.
Definition: ItemSword.h:44
virtual bool CanRepairWithRawMaterial(short a_ItemType) const override
Can the anvil repair this item, when a_Item is the second input?
Definition: ItemSword.h:30
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType) const override
Returns whether this tool / item can harvest a specific block (e.g.
Definition: ItemSword.h:20
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) const override
Returns the strength to break a specific block.
Definition: ItemSword.h:57