Cuberite
A lightweight, fast and extensible game server for Minecraft
ItemShovel.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "ItemHandler.h"
5 #include "../World.h"
6 #include "../Entities/Player.h"
7 
8 
9 #include "../BlockInServerPluginInterface.h"
10 
11 
12 
13 
14 
15 class cItemShovelHandler final:
16  public cItemHandler
17 {
19 
20 public:
21 
22  using Super::Super;
23 
24 
25 
26  virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) const override
27  {
28  switch (a_Action)
29  {
30  case dlaAttackEntity: return 2;
31  case dlaBreakBlock: return 1;
32  case dlaBreakBlockInstant: return 0;
33  }
34  UNREACHABLE("Unsupported durability loss action");
35  }
36 
37 
38 
39 
40 
41  virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType) const override
42  {
43  if (a_BlockType == E_BLOCK_SNOW)
44  {
45  return true;
46  }
47  return Super::CanHarvestBlock(a_BlockType);
48  }
49 
50 
51 
52 
53 
54  virtual bool CanRepairWithRawMaterial(short a_ItemType) const override
55  {
56  switch (m_ItemType)
57  {
58  case E_ITEM_WOODEN_SHOVEL: return (a_ItemType == E_BLOCK_PLANKS);
59  case E_ITEM_STONE_SHOVEL: return (a_ItemType == E_BLOCK_COBBLESTONE);
60  case E_ITEM_IRON_SHOVEL: return (a_ItemType == E_ITEM_IRON);
61  case E_ITEM_GOLD_SHOVEL: return (a_ItemType == E_ITEM_GOLD);
62  case E_ITEM_DIAMOND_SHOVEL: return (a_ItemType == E_ITEM_DIAMOND);
63  }
64  return false;
65  }
66 
67 
68 
69 
70 
71  virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) const override
72  {
73  switch (a_Block)
74  {
75  case E_BLOCK_CLAY:
77  case E_BLOCK_DIRT:
78  case E_BLOCK_FARMLAND:
79  case E_BLOCK_GRASS:
80  case E_BLOCK_GRASS_PATH:
81  case E_BLOCK_GRAVEL:
82  case E_BLOCK_MYCELIUM:
83  case E_BLOCK_SAND:
84  case E_BLOCK_SNOW:
85  case E_BLOCK_SNOW_BLOCK:
86  case E_BLOCK_SOULSAND:
87  {
88  switch (m_ItemType)
89  {
90  case E_ITEM_WOODEN_SHOVEL: return 2.0f;
91  case E_ITEM_STONE_SHOVEL: return 4.0f;
92  case E_ITEM_IRON_SHOVEL: return 6.0f;
93  case E_ITEM_GOLD_SHOVEL: return 12.0f;
94  case E_ITEM_DIAMOND_SHOVEL: return 8.0f;
95  }
96  break;
97  }
98  }
99  return Super::GetBlockBreakingStrength(a_Block);
100  }
101 };
@ E_BLOCK_CLAY
Definition: BlockType.h:96
@ E_BLOCK_GRASS_PATH
Definition: BlockType.h:227
@ E_BLOCK_FARMLAND
Definition: BlockType.h:72
@ E_BLOCK_GRASS
Definition: BlockType.h:12
@ E_BLOCK_SOULSAND
Definition: BlockType.h:103
@ E_BLOCK_MYCELIUM
Definition: BlockType.h:125
@ E_BLOCK_SNOW_BLOCK
Definition: BlockType.h:94
@ E_BLOCK_SNOW
Definition: BlockType.h:92
@ E_BLOCK_PLANKS
Definition: BlockType.h:15
@ E_BLOCK_GRAVEL
Definition: BlockType.h:23
@ E_BLOCK_CONCRETE_POWDER
Definition: BlockType.h:271
@ E_BLOCK_DIRT
Definition: BlockType.h:13
@ E_BLOCK_SAND
Definition: BlockType.h:22
@ E_BLOCK_COBBLESTONE
Definition: BlockType.h:14
@ E_ITEM_IRON
Definition: BlockType.h:309
@ E_ITEM_GOLD
Definition: BlockType.h:310
@ E_ITEM_GOLD_SHOVEL
Definition: BlockType.h:328
@ E_ITEM_DIAMOND
Definition: BlockType.h:308
@ E_ITEM_WOODEN_SHOVEL
Definition: BlockType.h:313
@ E_ITEM_IRON_SHOVEL
Definition: BlockType.h:300
@ E_ITEM_STONE_SHOVEL
Definition: BlockType.h:317
@ E_ITEM_DIAMOND_SHOVEL
Definition: BlockType.h:321
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
#define UNREACHABLE(x)
Definition: Globals.h:288
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
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType) const
Returns whether this tool / item can harvest a specific block (e.g.
virtual bool CanRepairWithRawMaterial(short a_ItemType) const override
Can the anvil repair this item, when a_Item is the second input?
Definition: ItemShovel.h:54
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) const override
Get the durability lost which the item will get, when a specified action was performed.
Definition: ItemShovel.h:26
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType) const override
Returns whether this tool / item can harvest a specific block (e.g.
Definition: ItemShovel.h:41
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) const override
Returns the strength to break a specific block.
Definition: ItemShovel.h:71