Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockPortal.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "BlockHandler.h"
5 
6 
7 
8 
9 
10 class cBlockPortalHandler final :
11  public cBlockHandler
12 {
14 
15 public:
16 
17  using Super::Super;
18 
19 private:
20 
21  virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem * const a_Tool) const override
22  {
23  // No pickups
24  return {};
25  }
26 
27 
28 
29 
30 
31  virtual void OnUpdate(
32  cChunkInterface & a_ChunkInterface,
33  cWorldInterface & a_WorldInterface,
34  cBlockPluginInterface & a_PluginInterface,
35  cChunk & a_Chunk,
36  const Vector3i a_RelPos
37  ) const override
38  {
39  // Spawn zombie pigmen with a 0.05% chance:
40  if (GetRandomProvider().RandBool(0.9995))
41  {
42  return;
43  }
44  auto WorldPos = a_Chunk.RelativeToAbsolute(a_RelPos);
45  a_WorldInterface.SpawnMob(WorldPos.x, WorldPos.y, WorldPos.z, mtZombiePigman, false);
46  }
47 
48 
49 
50 
51 
52  virtual bool CanBeAt(const cChunk & a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override
53  {
54  if ((a_Position.y <= 0) || (a_Position.y >= cChunkDef::Height - 1))
55  {
56  return false; // In case someone places a portal with meta 1 or 2 at boundaries, and server tries to get invalid coords at Y - 1 or Y + 1.
57  }
58 
59  switch (a_Meta)
60  {
61  case 0x1:
62  {
63  static const std::array<Vector3i, 4> PortalCheck
64  {
65  {
66  { 0, 1, 0 },
67  { 0, -1, 0 },
68  { 1, 0, 0 },
69  { -1, 0, 0 },
70  }
71  };
72 
73  for (const auto & Direction : PortalCheck)
74  {
76  a_Chunk.UnboundedRelGetBlockType(a_Position + Direction, Block);
78  {
79  return false;
80  }
81  }
82  break;
83  }
84  case 0x2:
85  {
86  static const std::array<Vector3i, 4> PortalCheck
87  {
88  {
89  { 0, 1, 0 },
90  { 0, -1, 0 },
91  { 0, 0, -1 },
92  { 0, 0, 1 },
93  }
94  };
95 
96  for (const auto & Direction : PortalCheck)
97  {
99  a_Chunk.UnboundedRelGetBlockType(a_Position + Direction, Block);
101  {
102  return false;
103  }
104  }
105  break;
106  }
107  }
108  return true;
109  }
110 
111 
112 
113 
114 
115  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
116  {
117  UNUSED(a_Meta);
118  return 24;
119  }
120 } ;
121 
122 
123 
124 
@ E_BLOCK_NETHER_PORTAL
Definition: BlockType.h:105
@ E_BLOCK_OBSIDIAN
Definition: BlockType.h:59
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
MTRand & GetRandomProvider()
Returns the current thread's random number source.
Definition: FastRandom.cpp:12
Byte ColourID
Definition: Globals.h:162
#define UNUSED
Definition: Globals.h:72
@ mtZombiePigman
Definition: MonsterTypes.h:85
Direction
constexpr cBlockHandler(BLOCKTYPE a_BlockType)
Definition: BlockHandler.h:29
This interface is used to decouple block handlers from the cPluginManager dependency through cWorld.
virtual bool CanBeAt(const cChunk &a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override
Checks if the block can stay at the specified relative coords in the chunk.
Definition: BlockPortal.h:52
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
Returns the base colour ID of the block, as will be represented on a map, as per documentation: https...
Definition: BlockPortal.h:115
virtual void OnUpdate(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cBlockPluginInterface &a_PluginInterface, cChunk &a_Chunk, const Vector3i a_RelPos) const override
Called when the block gets ticked either by a random tick or by a queued tick.
Definition: BlockPortal.h:31
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.
Definition: BlockPortal.h:21
virtual UInt32 SpawnMob(double a_PosX, double a_PosY, double a_PosZ, eMonsterType a_MonsterType, bool a_Baby)=0
Spawns a mob of the specified type.
Definition: Chunk.h:36
Vector3i RelativeToAbsolute(Vector3i a_RelBlockPosition) const
Converts the coord relative to this chunk into an absolute coord.
Definition: Chunk.h:450
bool UnboundedRelGetBlockType(Vector3i a_RelCoords, BLOCKTYPE &a_BlockType) const
Same as GetBlockType(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap...
Definition: Chunk.cpp:1029
static const int Height
Definition: ChunkDef.h:125
Definition: Item.h:37
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215
T y
Definition: Vector3.h:17