Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockEntityWithItems.h
Go to the documentation of this file.
1 
2 // BlockEntityWithItems.h
3 
4 // Declares the cBlockEntityWithItems class representing a common ancestor for all block entities that have an ItemGrid
5 
6 
7 
8 
9 
10 #pragma once
11 
12 #include "BlockEntity.h"
13 #include "../ItemGrid.h"
14 #include "../UI/WindowOwner.h"
15 #include "../World.h"
16 
17 
18 
19 
20 
21 // tolua_begin
23  public cBlockEntity,
24  // tolua_end
25  public cItemGrid::cListener,
26  // tolua_begin
28 {
29  // tolua_end
30 
32 
33 public: // tolua_export
34 
36  BLOCKTYPE a_BlockType, // Type of the block that the entity represents
37  NIBBLETYPE a_BlockMeta, // Meta of the block that the entity represents
38  Vector3i a_Pos, // Abs position of the block entity
39  int a_ItemGridWidth, int a_ItemGridHeight, // Dimensions of the ItemGrid
40  cWorld * a_World // Optional world to assign to the entity
41  );
42 
43  // cBlockEntity overrides:
44  virtual cItems ConvertToPickups() const override;
45  virtual void CopyFrom(const cBlockEntity & a_Src) override;
46 
47  // tolua_begin
48 
49  const cItem & GetSlot(int a_SlotNum) const { return m_Contents.GetSlot(a_SlotNum); }
50  const cItem & GetSlot(int a_X, int a_Y) const { return m_Contents.GetSlot(a_X, a_Y); }
51 
52  void SetSlot(int a_SlotNum, const cItem & a_Item) { m_Contents.SetSlot(a_SlotNum, a_Item); }
53  void SetSlot(int a_X, int a_Y, const cItem & a_Item) { m_Contents.SetSlot(a_X, a_Y, a_Item); }
54 
56  cItemGrid & GetContents(void) { return m_Contents; }
57 
58  // tolua_end
59 
61  const cItemGrid & GetContents(void) const { return m_Contents; }
62 
63 protected:
64 
66 
67  // cItemGrid::cListener overrides:
68  virtual void OnSlotChanged(cItemGrid * a_Grid, int a_SlotNum) override;
69 } ; // tolua_export
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
cBlockEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World)
Definition: BlockEntity.cpp:32
cItemGrid & GetContents(void)
Returns the ItemGrid used for storing the contents.
void SetSlot(int a_X, int a_Y, const cItem &a_Item)
virtual void CopyFrom(const cBlockEntity &a_Src) override
Copies all properties of a_Src into this entity, except for its m_World and location.
virtual cItems ConvertToPickups() const override
Returns the contents of this block entity that it would drop if broken.
const cItemGrid & GetContents(void) const
Const version of the GetContents() function for C++ type-safety.
const cItem & GetSlot(int a_SlotNum) const
const cItem & GetSlot(int a_X, int a_Y) const
cBlockEntityWithItems(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, int a_ItemGridWidth, int a_ItemGridHeight, cWorld *a_World)
virtual void OnSlotChanged(cItemGrid *a_Grid, int a_SlotNum) override
Called whenever a slot changes.
void SetSlot(int a_SlotNum, const cItem &a_Item)
Definition: Item.h:37
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215
void SetSlot(int a_X, int a_Y, const cItem &a_Item)
Definition: ItemGrid.cpp:121
const cItem & GetSlot(int a_X, int a_Y) const
Definition: ItemGrid.cpp:96
This class is used as a callback for when a slot changes.
Definition: ItemGrid.h:26
Window owner that is associated with a block entity (chest, furnace, ...)
Definition: WindowOwner.h:59
Definition: World.h:53