Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockEntityWithItems.cpp
Go to the documentation of this file.
1 // BlockEntityWithItems.cpp
2 
3 #include "Globals.h"
4 #include "BlockEntityWithItems.h"
5 #include "../Simulator/RedstoneSimulator.h"
6 
7 
8 
9 
10 
12  BLOCKTYPE a_BlockType,
13  NIBBLETYPE a_BlockMeta,
14  Vector3i a_Pos,
15  int a_ItemGridWidth, int a_ItemGridHeight,
16  cWorld * a_World
17 ):
18  Super(a_BlockType, a_BlockMeta, a_Pos, a_World),
20  m_Contents(a_ItemGridWidth, a_ItemGridHeight)
21 {
22  m_Contents.AddListener(*this);
23 }
24 
25 
26 
27 
28 
30 {
31  cItems Pickups;
32  Pickups.AddItemGrid(m_Contents);
33  return Pickups;
34 }
35 
36 
37 
38 
39 
41 {
42  Super::CopyFrom(a_Src);
43  auto & src = static_cast<const cBlockEntityWithItems &>(a_Src);
44  m_Contents.CopyFrom(src.m_Contents);
45 }
46 
47 
48 
49 
50 
51 void cBlockEntityWithItems::OnSlotChanged(cItemGrid * a_Grid, int a_SlotNum)
52 {
53  UNUSED(a_SlotNum);
54  ASSERT(a_Grid == &m_Contents);
55 
56  if (m_World == nullptr)
57  {
58  return;
59  }
60 
61  if (GetWindow() != nullptr)
62  {
64  }
65 
67 
68  // Notify comparators:
70 }
void AddListener(cListener &a_Listener)
Adds a callback that gets called whenever a slot changes.
Definition: ItemGrid.cpp:810
void CopyFrom(const cItemGrid &a_Src)
Copies all items from a_Src to this grid.
Definition: ItemGrid.cpp:83
virtual void OnSlotChanged(cItemGrid *a_Grid, int a_SlotNum) override
Called whenever a slot changes.
virtual void CopyFrom(const cBlockEntity &a_Src) override
Copies all properties of a_Src into this entity, except for its m_World and location.
cWindow * GetWindow(void) const
Definition: WindowOwner.h:40
#define ASSERT(x)
Definition: Globals.h:294
Window owner that is associated with a block entity (chest, furnace, ...)
Definition: WindowOwner.h:57
virtual cItems ConvertToPickups() const override
Returns the contents of this block entity that it would drop if broken.
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
Definition: World.h:65
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:213
int GetChunkX() const
Definition: BlockEntity.h:94
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
Vector3i m_Pos
Position in absolute block coordinates.
Definition: BlockEntity.h:106
void BroadcastWholeWindow(void)
Sends the contents of the whole window to all clients of this window.
Definition: Window.cpp:393
virtual void CopyFrom(const cBlockEntity &a_Src)
Copies all properties of a_Src into this entity, except for its m_World and location.
Definition: BlockEntity.cpp:65
int GetChunkZ() const
Definition: BlockEntity.h:95
cWorld * m_World
Definition: BlockEntity.h:119
virtual void WakeUpSimulators(Vector3i a_Block) override
Wakes up the simulators for the specified block.
Definition: World.cpp:1257
void AddItemGrid(const cItemGrid &a_ItemGrid)
Adds a copy of all items in a_ItemGrid.
Definition: Item.cpp:802
void MarkChunkDirty(int a_ChunkX, int a_ChunkZ)
Definition: World.cpp:2212
#define UNUSED
Definition: Globals.h:96
cBlockEntityWithItems(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, int a_ItemGridWidth, int a_ItemGridHeight, cWorld *a_World)