Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockMobSpawner.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "BlockHandler.h"
5 #include "../Items/ItemHandler.h"
6 
7 
8 
9 
10 
12  public cBlockHandler
13 {
15 
16 public:
17 
18  using Super::Super;
19 
20 private:
21 
22  virtual bool OnUse(
23  cChunkInterface & a_ChunkInterface,
24  cWorldInterface & a_WorldInterface,
25  cPlayer & a_Player,
26  const Vector3i a_BlockPos,
27  eBlockFace a_BlockFace,
28  const Vector3i a_CursorPos
29  ) const override
30  {
31  return a_ChunkInterface.UseBlockEntity(&a_Player, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z);
32  }
33 
34 
35 
36 
37 
38  virtual bool IsUseable() const override
39  {
40  return true;
41  }
42 
43 
44 
45 
46 
47  virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem * const a_Tool) const override
48  {
49  // No pickups
50  return {};
51  }
52 
53 
54 
55 
56 
57  virtual void OnBroken(
58  cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
59  Vector3i a_BlockPos,
60  BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta,
61  const cEntity * a_Digger
62  ) const override
63  {
64  if (a_Digger == nullptr)
65  {
66  return;
67  }
68  if (!a_Digger->IsPlayer())
69  {
70  return;
71  }
72 
73  const auto Player = static_cast<const cPlayer *>(a_Digger);
74  auto & Handler = Player->GetEquippedItem().GetHandler();
75  if (!Player->IsGameModeSurvival() || !Handler.CanHarvestBlock(E_BLOCK_MOB_SPAWNER))
76  {
77  return;
78  }
79 
80  auto & Random = GetRandomProvider();
81  int Reward = 15 + Random.RandInt(14) + Random.RandInt(14);
82  a_WorldInterface.SpawnSplitExperienceOrbs(Vector3d(0.5, 0.5, 0.5) + a_BlockPos, Reward);
83  }
84 } ;
@ E_BLOCK_MOB_SPAWNER
Definition: BlockType.h:62
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
MTRand & GetRandomProvider()
Returns the current thread's random number source.
Definition: FastRandom.cpp:12
Vector3< double > Vector3d
Definition: Vector3.h:485
constexpr cBlockHandler(BLOCKTYPE a_BlockType)
Definition: BlockHandler.h:29
virtual bool IsUseable() const override
Called to check whether this block supports a rclk action.
virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem *const a_Tool) const override
Returns the pickups that would result if the block was mined by a_Digger using a_Tool.
virtual void OnBroken(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, Vector3i a_BlockPos, BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta, const cEntity *a_Digger) const override
Called after a block gets broken (replaced with air), by natural means.
virtual bool OnUse(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, const Vector3i a_BlockPos, eBlockFace a_BlockFace, const Vector3i a_CursorPos) const override
Called when the user right clicks the block and the block is useable.
bool UseBlockEntity(cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ)
Use block entity on coordinate.
virtual std::vector< UInt32 > SpawnSplitExperienceOrbs(Vector3d a_Pos, int a_Reward)=0
Spawns experience orbs of the specified total value at the given location.
Definition: Entity.h:76
bool IsPlayer(void) const
Definition: Entity.h:160
Definition: Player.h:29
const cItem & GetEquippedItem(void) const
Definition: Player.h:162
Definition: Item.h:37
const cItemHandler & GetHandler(void) const
Returns the cItemHandler responsible for this item type.
Definition: Item.cpp:216
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215
T x
Definition: Vector3.h:17
T y
Definition: Vector3.h:17
T z
Definition: Vector3.h:17