Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockEntity.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "BlockHandler.h"
5 #include "ChunkInterface.h"
6 #include "../Item.h"
7 #include "../BlockEntities/BlockEntityWithItems.h"
8 
9 
10 
11 
12 
16  public cBlockHandler
17 {
19 
20 public:
21 
23  super(a_BlockType)
24  {
25  }
26 
27 
28 
29 
30 
31  virtual bool OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
32  {
33  return a_ChunkInterface.UseBlockEntity(&a_Player, a_BlockX, a_BlockY, a_BlockZ);
34  }
35 
36 
37 
38 
39 
40  virtual bool IsUseable() override
41  {
42  return true;
43  }
44 };
45 
46 
47 
48 
49 
52 template <typename Base = cBlockEntityHandler>
54  public Base
55 {
56 public:
57 
59  Base(a_BlockType)
60  {
61  }
62 
63 
64 
65 
66 
67  virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) override
68  {
69  // Reset meta to 0
70  cItems res(cItem(Base::m_BlockType, 1, 0));
71 
72  // Drop the contents:
73  if (a_BlockEntity != nullptr)
74  {
75  auto container = static_cast<cBlockEntityWithItems *>(a_BlockEntity);
76  res.AddItemGrid(container->GetContents());
77  }
78  return res;
79  }
80 };
Wrapper for blocks that have a cBlockEntity descendant attached to them and can be "used" by the play...
Definition: BlockEntity.h:15
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
Definition: Player.h:27
cBlockHandler(BLOCKTYPE a_BlockType)
virtual bool IsUseable() override
Checks if the block can be placed at this point.
Definition: BlockEntity.h:40
virtual bool OnUse(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
Called if the user right clicks the block and the block is useable returns true if the use was succes...
Definition: BlockEntity.h:31
Wrapper for blocks that have a cBlockEntityWithItems descendant attached to them. ...
Definition: BlockEntity.h:53
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:45
cContainerEntityHandler(BLOCKTYPE a_BlockType)
Definition: BlockEntity.h:58
virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity *a_BlockEntity, const cEntity *a_Digger, const cItem *a_Tool) override
Definition: BlockEntity.h:67
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
Definition: Defines.h:29
bool UseBlockEntity(cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ)
Use block entity on coordinate.
Definition: Entity.h:73
cBlockEntityHandler(BLOCKTYPE a_BlockType)
Definition: BlockEntity.h:22
Definition: Item.h:36
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:234
void AddItemGrid(const cItemGrid &a_ItemGrid)
Adds a copy of all items in a_ItemGrid.
Definition: Item.cpp:727