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 }
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
#define ASSERT(x)
Definition: Globals.h:276
#define UNUSED
Definition: Globals.h:72
int GetChunkX() const
Definition: BlockEntity.h:101
int GetChunkZ() const
Definition: BlockEntity.h:102
Vector3i m_Pos
Position in absolute block coordinates.
Definition: BlockEntity.h:113
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:66
cWorld * m_World
Definition: BlockEntity.h:126
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.
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.
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215
void AddItemGrid(const cItemGrid &a_ItemGrid)
Adds a copy of all items in a_ItemGrid.
Definition: Item.cpp:803
void CopyFrom(const cItemGrid &a_Src)
Copies all items from a_Src to this grid.
Definition: ItemGrid.cpp:83
void AddListener(cListener &a_Listener)
Adds a callback that gets called whenever a slot changes.
Definition: ItemGrid.cpp:809
void BroadcastWholeWindow(void)
Sends the contents of the whole window to all clients of this window.
Definition: Window.cpp:393
cWindow * GetWindow(void) const
Definition: WindowOwner.h:40
Window owner that is associated with a block entity (chest, furnace, ...)
Definition: WindowOwner.h:59
Definition: World.h:53
void MarkChunkDirty(int a_ChunkX, int a_ChunkZ)
Definition: World.cpp:2150
virtual void WakeUpSimulators(Vector3i a_Block) override
Wakes up the simulators for the specified block.
Definition: World.cpp:1357