Cuberite
A lightweight, fast and extensible game server for Minecraft
ItemShears.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 
10 
11 
12 class cItemShearsHandler final:
13  public cItemHandler
14 {
16 
17 public:
18 
19  using Super::Super;
20 
21 
22 
23 
24 
25  virtual bool OnDiggingBlock(
26  cWorld * a_World,
27  cPlayer * a_Player,
28  const cItem & a_HeldItem,
29  const Vector3i a_ClickedBlockPos,
30  eBlockFace a_ClickedBlockFace
31  ) const override
32  {
34  NIBBLETYPE BlockMeta;
35  a_World->GetBlockTypeMeta(a_ClickedBlockPos, Block, BlockMeta);
36 
38  {
39  a_World->DropBlockAsPickups(a_ClickedBlockPos, a_Player, &a_HeldItem);
40  return true;
41  }
42 
43  return false;
44  }
45 
46 
47 
48 
49 
50  virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType) const override
51  {
52  switch (a_BlockType)
53  {
54  case E_BLOCK_COBWEB:
55  case E_BLOCK_DEAD_BUSH:
56  case E_BLOCK_VINES:
57  {
58  return true;
59  }
60  }
61  return Super::CanHarvestBlock(a_BlockType);
62  }
63 
64 
65 
66 
67 
68  virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) const override
69  {
70  switch (a_Action)
71  {
72  case dlaAttackEntity: return 0;
73  case dlaBreakBlock: return 0;
74  case dlaBreakBlockInstant: return 1;
75  }
76  UNREACHABLE("Unsupported durability loss action");
77  }
78 
79 
80 
81 
82 
83  virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) const override
84  {
85  if ((a_Block == E_BLOCK_COBWEB) || IsBlockMaterialLeaves(a_Block))
86  {
87  return 15.0f;
88  }
89  else if (a_Block == E_BLOCK_WOOL)
90  {
91  return 5.0f;
92  }
93  else
94  {
95  return Super::GetBlockBreakingStrength(a_Block);
96  }
97  }
98 } ;
bool IsBlockMaterialLeaves(BLOCKTYPE a_BlockType)
Definition: BlockInfo.cpp:302
@ E_BLOCK_NEW_LEAVES
Definition: BlockType.h:180
@ E_BLOCK_DEAD_BUSH
Definition: BlockType.h:42
@ E_BLOCK_WOOL
Definition: BlockType.h:45
@ E_BLOCK_LEAVES
Definition: BlockType.h:28
@ E_BLOCK_COBWEB
Definition: BlockType.h:40
@ E_BLOCK_VINES
Definition: BlockType.h:121
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
Definition: Defines.h:38
#define UNREACHABLE(x)
Definition: Globals.h:288
Definition: Player.h:29
Definition: Item.h:37
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) const
Returns the strength to break a specific block.
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: ItemShears.h:50
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) const override
Get the durability lost which the item will get, when a specified action was performed.
Definition: ItemShears.h:68
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) const override
Returns the strength to break a specific block.
Definition: ItemShears.h:83
virtual bool OnDiggingBlock(cWorld *a_World, cPlayer *a_Player, const cItem &a_HeldItem, const Vector3i a_ClickedBlockPos, eBlockFace a_ClickedBlockFace) const override
Called while the player digs a block using this item.
Definition: ItemShears.h:25
Definition: World.h:53
bool DropBlockAsPickups(Vector3i a_BlockPos, const cEntity *a_Digger=nullptr, const cItem *a_Tool=nullptr)
Digs the specified block, and spawns the appropriate pickups for it.
Definition: World.cpp:2090
bool GetBlockTypeMeta(Vector3i a_BlockPos, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
Retrieves the block type and meta at the specified coords.
Definition: World.cpp:1779