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 
11  public cBlockHandler
12 {
13 public:
15  : cBlockHandler(a_BlockType)
16  {
17  }
18 
20  cChunkInterface & a_ChunkInterface, cPlayer & a_Player,
21  int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
22  int a_CursorX, int a_CursorY, int a_CursorZ,
23  BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
24  ) override
25  {
26  // We set to zero so MCS doesn't stop you from building weird portals like vanilla does
27  // CanBeAt doesn't do anything if meta is zero
28  // We set to zero because the client sends meta = 2 to the server (it calculates rotation itself)
29 
30  a_BlockType = m_BlockType;
31  a_BlockMeta = 0;
32  return true;
33  }
34 
35 
36 
37 
38 
39  virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) override
40  {
41  // No pickups
42  return {};
43  }
44 
45 
46 
47 
48 
49  virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
50  {
51  if (GetRandomProvider().RandBool(0.9995))
52  {
53  return;
54  }
55 
56  int PosX = a_Chunk.GetPosX() * cChunkDef::Width + a_RelX;
57  int PosZ = a_Chunk.GetPosZ() * cChunkDef::Width + a_RelZ;
58 
59  a_WorldInterface.SpawnMob(PosX, a_RelY, PosZ, mtZombiePigman, false);
60  }
61 
62  virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
63  {
64  if ((a_RelY <= 0) || (a_RelY >= cChunkDef::Height - 1))
65  {
66  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
67  }
68 
69  switch (a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ))
70  {
71  case 0x1:
72  {
73  static const std::array<Vector3i, 4> PortalCheck
74  {
75  {
76  { 0, 1, 0 },
77  { 0, -1, 0 },
78  { 1, 0, 0 },
79  { -1, 0, 0 },
80  }
81  };
82 
83  for (const auto & Direction : PortalCheck)
84  {
85  BLOCKTYPE Block;
86  a_Chunk.UnboundedRelGetBlockType(a_RelX + Direction.x, a_RelY + Direction.y, a_RelZ + Direction.z, Block);
87 
88  if ((Block != E_BLOCK_NETHER_PORTAL) && (Block != E_BLOCK_OBSIDIAN))
89  {
90  return false;
91  }
92  }
93  break;
94  }
95  case 0x2:
96  {
97  static const std::array<Vector3i, 4> PortalCheck
98  {
99  {
100  { 0, 1, 0 },
101  { 0, -1, 0 },
102  { 0, 0, -1 },
103  { 0, 0, 1 },
104  }
105  };
106 
107  for (const auto & Direction : PortalCheck)
108  {
109  BLOCKTYPE Block;
110  a_Chunk.UnboundedRelGetBlockType(a_RelX + Direction.x, a_RelY + Direction.y, a_RelZ + Direction.z, Block);
111 
112  if ((Block != E_BLOCK_NETHER_PORTAL) && (Block != E_BLOCK_OBSIDIAN))
113  {
114  return false;
115  }
116  }
117  break;
118  }
119  }
120  return true;
121  }
122 
123  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
124  {
125  UNUSED(a_Meta);
126  return 24;
127  }
128 } ;
129 
130 
131 
132 
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
MTRand & GetRandomProvider()
Returns the current thread&#39;s random number source.
Definition: FastRandom.cpp:20
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.
static const int Width
Definition: ChunkDef.h:134
bool UnboundedRelGetBlockType(Vector3i a_RelCoords, BLOCKTYPE &a_BlockType) const
Same as GetBlockType(), but relative coords needn&#39;t be in this chunk (uses m_Neighbor-s or m_ChunkMap...
Definition: Chunk.cpp:1018
Definition: Player.h:27
BLOCKTYPE m_BlockType
Definition: BlockHandler.h:213
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:45
Definition: Chunk.h:49
static const int Height
Definition: ChunkDef.h:135
This interface is used to decouple block handlers from the cPluginManager dependency through cWorld...
Direction
NIBBLETYPE GetMeta(int a_RelX, int a_RelY, int a_RelZ) const
Definition: Chunk.h:380
int GetPosX(void) const
Definition: Chunk.h:150
virtual bool CanBeAt(cChunkInterface &a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk &a_Chunk) override
Checks if the block can stay at the specified relative coords in the chunk.
Definition: BlockPortal.h:62
virtual void OnUpdate(cChunkInterface &cChunkInterface, cWorldInterface &a_WorldInterface, cBlockPluginInterface &a_PluginInterface, cChunk &a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
Called when the block gets ticked either by a random tick or by a queued tick.
Definition: BlockPortal.h:49
#define UNUSED
Definition: Globals.h:152
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
Returns the base colour ID of the block, as will be represented on a map, as per documentation: https...
Definition: BlockPortal.h:123
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
Definition: Defines.h:29
Byte ColourID
Definition: Globals.h:118
int GetPosZ(void) const
Definition: Chunk.h:151
virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity *a_BlockEntity, const cEntity *a_Digger, const cItem *a_Tool) override
Returns the pickups that would result if the block was mined by a_Digger using a_Tool.
Definition: BlockPortal.h:39
Definition: Entity.h:73
cBlockPortalHandler(BLOCKTYPE a_BlockType)
Definition: BlockPortal.h:14
virtual bool GetPlacementBlockTypeMeta(cChunkInterface &a_ChunkInterface, cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) override
Called before a block is placed into a world.
Definition: BlockPortal.h:19
Definition: Item.h:36
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:234