Cuberite
A lightweight, fast and extensible game server for Minecraft
ItemPickaxe.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "ItemHandler.h"
5 
6 
7 
8 class cItemPickaxeHandler final:
9  public cItemHandler
10 {
12 
13 public:
14 
15  constexpr cItemPickaxeHandler(int a_ItemType):
16  Super(a_ItemType)
17  {
18 
19  }
20 
21 
22 
23  virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) const override
24  {
25  switch (a_Action)
26  {
27  case dlaAttackEntity: return 2;
28  case dlaBreakBlock: return 1;
29  case dlaBreakBlockInstant: return 0;
30  }
31  UNREACHABLE("Unsupported durability loss action");
32  }
33 
34 
35 
36  char PickaxeLevel() const
37  {
38  switch (m_ItemType)
39  {
40  case E_ITEM_WOODEN_PICKAXE: return 1;
41  case E_ITEM_GOLD_PICKAXE: return 1;
42  case E_ITEM_STONE_PICKAXE: return 2;
43  case E_ITEM_IRON_PICKAXE: return 3;
44  case E_ITEM_DIAMOND_PICKAXE: return 4;
45 
46  default: return 0;
47  }
48  }
49 
50  virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType) const override
51  {
52  // NOTICE: Make sure to update cItemHandler::CanHarvestBlock() if adding new blocks here!
53  switch (a_BlockType)
54  {
55  case E_BLOCK_OBSIDIAN:
56  {
57  return PickaxeLevel() >= 4;
58  }
59 
63  case E_BLOCK_GOLD_BLOCK:
64  case E_BLOCK_GOLD_ORE:
67  {
68  return PickaxeLevel() >= 3;
69  }
70 
71  case E_BLOCK_IRON_BLOCK:
72  case E_BLOCK_IRON_ORE:
73  case E_BLOCK_LAPIS_ORE:
75  {
76  return PickaxeLevel() >= 2;
77  }
78 
79  case E_BLOCK_ANVIL:
84  case E_BLOCK_BONE_BLOCK:
86  case E_BLOCK_BRICK:
89  case E_BLOCK_CAULDRON:
90  case E_BLOCK_COAL_ORE:
94  case E_BLOCK_CONCRETE:
96  case E_BLOCK_DISPENSER:
97  case E_BLOCK_DROPPER:
101  case E_BLOCK_END_BRICKS:
102  case E_BLOCK_END_STONE:
103  case E_BLOCK_FURNACE:
108  case E_BLOCK_HOPPER:
109  case E_BLOCK_IRON_BARS:
110  case E_BLOCK_IRON_DOOR:
115  case E_BLOCK_LIT_FURNACE:
118  case E_BLOCK_MOB_SPAWNER:
120  case E_BLOCK_MAGMA:
125  case E_BLOCK_NETHERRACK:
126  case E_BLOCK_OBSERVER:
134  case E_BLOCK_PURPUR_SLAB:
142  case E_BLOCK_SANDSTONE:
144  case E_BLOCK_STONE:
148  case E_BLOCK_STONE_SLAB:
151  {
152  return PickaxeLevel() >= 1;
153  }
154  }
155  return Super::CanHarvestBlock(a_BlockType);
156  }
157 
158  virtual bool CanRepairWithRawMaterial(short a_ItemType) const override
159  {
160  switch (m_ItemType)
161  {
162  case E_ITEM_WOODEN_PICKAXE: return (a_ItemType == E_BLOCK_PLANKS);
163  case E_ITEM_STONE_PICKAXE: return (a_ItemType == E_BLOCK_COBBLESTONE);
164  case E_ITEM_IRON_PICKAXE: return (a_ItemType == E_ITEM_IRON);
165  case E_ITEM_GOLD_PICKAXE: return (a_ItemType == E_ITEM_GOLD);
166  case E_ITEM_DIAMOND_PICKAXE: return (a_ItemType == E_ITEM_DIAMOND);
167  }
168  return false;
169  }
170 
171 
172  virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) const override
173  {
174  if (!IsBlockMaterialIron(a_Block) && (a_Block != E_BLOCK_ANVIL) && !IsBlockMaterialRock(a_Block))
175  {
176  return Super::GetBlockBreakingStrength(a_Block);
177  }
178  else
179  {
180  switch (m_ItemType)
181  {
182  case E_ITEM_WOODEN_PICKAXE: return 2.0f;
183  case E_ITEM_STONE_PICKAXE: return 4.0f;
184  case E_ITEM_IRON_PICKAXE: return 6.0f;
185  case E_ITEM_GOLD_PICKAXE: return 12.0f;
186  case E_ITEM_DIAMOND_PICKAXE: return 8.0f;
187  }
188  }
189  ASSERT(!"Something is wrong here... Maybe they are pickaxes out of a new material?");
190  return 1.0f;
191  }
192 
193 } ;
bool IsBlockMaterialRock(BLOCKTYPE a_BlockType)
Definition: BlockInfo.cpp:332
bool IsBlockMaterialIron(BLOCKTYPE a_BlockType)
Definition: BlockInfo.cpp:266
@ E_BLOCK_ORANGE_GLAZED_TERRACOTTA
Definition: BlockType.h:255
@ E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE
Definition: BlockType.h:163
@ E_BLOCK_NETHER_BRICK_STAIRS
Definition: BlockType.h:129
@ E_BLOCK_PINK_GLAZED_TERRACOTTA
Definition: BlockType.h:260
@ E_BLOCK_STONE_PRESSURE_PLATE
Definition: BlockType.h:84
@ E_BLOCK_GRAY_GLAZED_TERRACOTTA
Definition: BlockType.h:261
@ E_BLOCK_PURPUR_BLOCK
Definition: BlockType.h:220
@ E_BLOCK_BREWING_STAND
Definition: BlockType.h:132
@ E_BLOCK_PURPUR_STAIRS
Definition: BlockType.h:222
@ E_BLOCK_BONE_BLOCK
Definition: BlockType.h:235
@ E_BLOCK_COBBLESTONE_STAIRS
Definition: BlockType.h:81
@ E_BLOCK_DIAMOND_BLOCK
Definition: BlockType.h:67
@ E_BLOCK_REDSTONE_ORE
Definition: BlockType.h:87
@ E_BLOCK_COAL_ORE
Definition: BlockType.h:26
@ E_BLOCK_BLACK_GLAZED_TERRACOTTA
Definition: BlockType.h:269
@ E_BLOCK_DIAMOND_ORE
Definition: BlockType.h:66
@ E_BLOCK_BRICK_STAIRS
Definition: BlockType.h:123
@ E_BLOCK_CAULDRON
Definition: BlockType.h:133
@ E_BLOCK_BRICK
Definition: BlockType.h:55
@ E_BLOCK_STONE_BRICK_STAIRS
Definition: BlockType.h:124
@ E_BLOCK_ENCHANTMENT_TABLE
Definition: BlockType.h:131
@ E_BLOCK_FURNACE
Definition: BlockType.h:73
@ E_BLOCK_PRISMARINE_BLOCK
Definition: BlockType.h:187
@ E_BLOCK_GOLD_BLOCK
Definition: BlockType.h:51
@ E_BLOCK_RED_NETHER_BRICK
Definition: BlockType.h:234
@ E_BLOCK_BLOCK_OF_REDSTONE
Definition: BlockType.h:168
@ E_BLOCK_STONE_BRICKS
Definition: BlockType.h:113
@ E_BLOCK_PURPUR_PILLAR
Definition: BlockType.h:221
@ E_BLOCK_MOSSY_COBBLESTONE
Definition: BlockType.h:58
@ E_BLOCK_OBSERVER
Definition: BlockType.h:237
@ E_BLOCK_REDSTONE_ORE_GLOWING
Definition: BlockType.h:88
@ E_BLOCK_BLUE_GLAZED_TERRACOTTA
Definition: BlockType.h:265
@ E_BLOCK_LAPIS_ORE
Definition: BlockType.h:31
@ E_BLOCK_IRON_BLOCK
Definition: BlockType.h:52
@ E_BLOCK_CONCRETE
Definition: BlockType.h:270
@ E_BLOCK_DOUBLE_RED_SANDSTONE_SLAB
Definition: BlockType.h:200
@ E_BLOCK_END_BRICKS
Definition: BlockType.h:225
@ E_BLOCK_BLOCK_OF_COAL
Definition: BlockType.h:192
@ E_BLOCK_LIT_FURNACE
Definition: BlockType.h:74
@ E_BLOCK_LAPIS_BLOCK
Definition: BlockType.h:32
@ E_BLOCK_IRON_DOOR
Definition: BlockType.h:85
@ E_BLOCK_YELLOW_GLAZED_TERRACOTTA
Definition: BlockType.h:258
@ E_BLOCK_MAGENTA_GLAZED_TERRACOTTA
Definition: BlockType.h:256
@ E_BLOCK_STONE_SLAB
Definition: BlockType.h:54
@ E_BLOCK_EMERALD_ORE
Definition: BlockType.h:144
@ E_BLOCK_CYAN_GLAZED_TERRACOTTA
Definition: BlockType.h:263
@ E_BLOCK_DOUBLE_STONE_SLAB
Definition: BlockType.h:53
@ E_BLOCK_OBSIDIAN
Definition: BlockType.h:59
@ E_BLOCK_RED_SANDSTONE_STAIRS
Definition: BlockType.h:199
@ E_BLOCK_RED_SANDSTONE
Definition: BlockType.h:198
@ E_BLOCK_IRON_ORE
Definition: BlockType.h:25
@ E_BLOCK_PLANKS
Definition: BlockType.h:15
@ E_BLOCK_IRON_BARS
Definition: BlockType.h:116
@ E_BLOCK_LIGHT_BLUE_GLAZED_TERRACOTTA
Definition: BlockType.h:257
@ E_BLOCK_PURPLE_GLAZED_TERRACOTTA
Definition: BlockType.h:264
@ E_BLOCK_ANVIL
Definition: BlockType.h:160
@ E_BLOCK_HARDENED_CLAY
Definition: BlockType.h:191
@ E_BLOCK_SANDSTONE
Definition: BlockType.h:34
@ E_BLOCK_GOLD_ORE
Definition: BlockType.h:24
@ E_BLOCK_STONE
Definition: BlockType.h:11
@ E_BLOCK_LIGHT_GRAY_GLAZED_TERRACOTTA
Definition: BlockType.h:262
@ E_BLOCK_NETHER_QUARTZ_ORE
Definition: BlockType.h:170
@ E_BLOCK_GREEN_GLAZED_TERRACOTTA
Definition: BlockType.h:267
@ E_BLOCK_SANDSTONE_STAIRS
Definition: BlockType.h:143
@ E_BLOCK_QUARTZ_BLOCK
Definition: BlockType.h:172
@ E_BLOCK_NETHERRACK
Definition: BlockType.h:102
@ E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE
Definition: BlockType.h:162
@ E_BLOCK_HOPPER
Definition: BlockType.h:171
@ E_BLOCK_DROPPER
Definition: BlockType.h:176
@ E_BLOCK_DISPENSER
Definition: BlockType.h:33
@ E_BLOCK_IRON_TRAPDOOR
Definition: BlockType.h:186
@ E_BLOCK_MAGMA
Definition: BlockType.h:232
@ E_BLOCK_PURPUR_DOUBLE_SLAB
Definition: BlockType.h:223
@ E_BLOCK_LIME_GLAZED_TERRACOTTA
Definition: BlockType.h:259
@ E_BLOCK_WHITE_GLAZED_TERRACOTTA
Definition: BlockType.h:254
@ E_BLOCK_END_STONE
Definition: BlockType.h:136
@ E_BLOCK_COBBLESTONE_WALL
Definition: BlockType.h:154
@ E_BLOCK_PURPUR_SLAB
Definition: BlockType.h:224
@ E_BLOCK_BROWN_GLAZED_TERRACOTTA
Definition: BlockType.h:266
@ E_BLOCK_MOB_SPAWNER
Definition: BlockType.h:62
@ E_BLOCK_NETHER_BRICK_FENCE
Definition: BlockType.h:128
@ E_BLOCK_QUARTZ_STAIRS
Definition: BlockType.h:173
@ E_BLOCK_NETHER_BRICK
Definition: BlockType.h:127
@ E_BLOCK_RED_GLAZED_TERRACOTTA
Definition: BlockType.h:268
@ E_BLOCK_COBBLESTONE
Definition: BlockType.h:14
@ E_ITEM_WOODEN_PICKAXE
Definition: BlockType.h:314
@ E_ITEM_IRON
Definition: BlockType.h:309
@ E_ITEM_STONE_PICKAXE
Definition: BlockType.h:318
@ E_ITEM_GOLD
Definition: BlockType.h:310
@ E_ITEM_DIAMOND_PICKAXE
Definition: BlockType.h:322
@ E_ITEM_IRON_PICKAXE
Definition: BlockType.h:301
@ E_ITEM_GOLD_PICKAXE
Definition: BlockType.h:329
@ E_ITEM_DIAMOND
Definition: BlockType.h:308
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
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 CanHarvestBlock(BLOCKTYPE a_BlockType) const override
Returns whether this tool / item can harvest a specific block (e.g.
Definition: ItemPickaxe.h:50
virtual bool CanRepairWithRawMaterial(short a_ItemType) const override
Can the anvil repair this item, when a_Item is the second input?
Definition: ItemPickaxe.h:158
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) const override
Get the durability lost which the item will get, when a specified action was performed.
Definition: ItemPickaxe.h:23
constexpr cItemPickaxeHandler(int a_ItemType)
Definition: ItemPickaxe.h:15
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) const override
Returns the strength to break a specific block.
Definition: ItemPickaxe.h:172
char PickaxeLevel() const
Definition: ItemPickaxe.h:36