Cuberite
A lightweight, fast and extensible game server for Minecraft
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
cChestEntity Class Reference

#include <ChestEntity.h>

Inheritance diagram for cChestEntity:
Inheritance graph
[legend]
Collaboration diagram for cChestEntity:
Collaboration graph
[legend]

Public Types

enum  { ContentsHeight = 3 , ContentsWidth = 9 }
 

Public Member Functions

 cChestEntity (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World)
 
int GetNumberOfPlayers (void) const
 Gets the number of players who currently have this chest open. More...
 
cChestEntityGetPrimaryChest ()
 Returns the associated primary chest. More...
 
cChestEntityGetSecondaryChest ()
 Returns the associated secondary chest, if any. More...
 
bool ScanNeighbour (cChunk &a_Chunk, Vector3i a_Position)
 Search the given horizontally adjacent relative position for a neighbouring chest of the same type. More...
 
void SetNumberOfPlayers (int a_NumActivePlayers)
 Sets the number of players who currently have this chest open. More...
 
- Public Member Functions inherited from cBlockEntityWithItems
 cBlockEntityWithItems (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, int a_ItemGridWidth, int a_ItemGridHeight, cWorld *a_World)
 
virtual cItems ConvertToPickups () const override
 Returns the contents of this block entity that it would drop if broken. More...
 
cItemGridGetContents (void)
 Returns the ItemGrid used for storing the contents. More...
 
const cItemGridGetContents (void) const
 Const version of the GetContents() function for C++ type-safety. More...
 
const cItemGetSlot (int a_SlotNum) const
 
const cItemGetSlot (int a_X, int a_Y) const
 
void SetSlot (int a_SlotNum, const cItem &a_Item)
 
void SetSlot (int a_X, int a_Y, const cItem &a_Item)
 
- Public Member Functions inherited from cBlockEntity
OwnedBlockEntity Clone (Vector3i a_Pos)
 Makes an exact copy of this block entity, except for its m_World (set to nullptr), and at a new position. More...
 
virtual void Destroy ()
 Called when this block entity's associated block is destroyed. More...
 
BLOCKTYPE GetBlockType () const
 
int GetChunkX () const
 
int GetChunkZ () const
 
Vector3i GetPos () const
 
int GetPosX () const
 
int GetPosY () const
 
int GetPosZ () const
 
Vector3i GetRelPos () const
 
int GetRelX () const
 
int GetRelZ () const
 
cWorldGetWorld () const
 
void SetPos (Vector3i a_NewPos)
 Updates the internally stored position. More...
 
void SetWorld (cWorld *a_World)
 
virtual bool Tick (std::chrono::milliseconds a_Dt, cChunk &a_Chunk)
 Ticks the entity; returns true if the chunk should be marked as dirty as a result of this ticking. More...
 
virtual ~cBlockEntity ()=default
 
- Public Member Functions inherited from cItemGrid::cListener
virtual ~cListener ()
 
- Public Member Functions inherited from cBlockEntityWindowOwner
 cBlockEntityWindowOwner (cBlockEntity *a_BlockEntity)
 
virtual Vector3i GetBlockPos (void) override
 Returns the block position at which the element owning the window is. More...
 
- Public Member Functions inherited from cWindowOwner
void CloseWindow (void)
 
 cWindowOwner ()
 
cWindowGetWindow (void) const
 
void OpenWindow (cWindow *a_Window)
 
virtual ~cWindowOwner ()
 

Private Types

using Super = cBlockEntityWithItems
 

Private Member Functions

virtual void CopyFrom (const cBlockEntity &a_Src) override
 Copies all properties of a_Src into this entity, except for its m_World and location. More...
 
void DestroyWindow ()
 Forces any players to close the owned window. More...
 
bool IsBlocked ()
 Returns true if the chest should not be accessible by players. More...
 
virtual void OnAddToWorld (cWorld &a_World, cChunk &a_Chunk) override
 Called when the block entity object is added to a world. More...
 
virtual void OnRemoveFromWorld () override
 Called when the block entity object is removed from a world. More...
 
virtual void OnSlotChanged (cItemGrid *a_Grid, int a_SlotNum) override
 cItemGrid::cListener overrides: More...
 
void OpenNewWindow ()
 Opens a new chest window where this is the primary chest and any neighbour is the secondary. More...
 
virtual void SendTo (cClientHandle &a_Client) override
 Sends the packet defining the block entity to the client specified. More...
 
virtual bool UsedBy (cPlayer *a_Player) override
 Called when a player uses this entity; should open the UI window. More...
 

Private Attributes

cChestEntitym_Neighbour
 Neighbouring chest that links to form a double chest. More...
 
int m_NumActivePlayers
 Number of players who currently have this chest open. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from cBlockEntity
static OwnedBlockEntity CreateByBlockType (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World=nullptr)
 Creates a new block entity for the specified block type at the specified absolute pos. More...
 
static bool IsBlockEntityBlockType (BLOCKTYPE a_BlockType)
 Returns true if the specified blocktype is supposed to have an associated block entity. More...
 
- Protected Member Functions inherited from cBlockEntity
 cBlockEntity (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World)
 
- Protected Attributes inherited from cBlockEntityWithItems
cItemGrid m_Contents
 
- Protected Attributes inherited from cBlockEntity
NIBBLETYPE m_BlockMeta
 The block meta representing this particular instance in the world Mainly used for directional entities, such as dispensers. More...
 
BLOCKTYPE m_BlockType
 The blocktype representing this particular instance in the world. More...
 
Vector3i m_Pos
 Position in absolute block coordinates. More...
 
int m_RelX
 Position relative to the chunk, used to speed up ticking. More...
 
int m_RelZ
 
cWorldm_World
 

Detailed Description

Definition at line 18 of file ChestEntity.h.

Member Typedef Documentation

◆ Super

Definition at line 23 of file ChestEntity.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
ContentsHeight 
ContentsWidth 

Definition at line 29 of file ChestEntity.h.

Constructor & Destructor Documentation

◆ cChestEntity()

cChestEntity::cChestEntity ( BLOCKTYPE  a_BlockType,
NIBBLETYPE  a_BlockMeta,
Vector3i  a_Pos,
cWorld a_World 
)

Definition at line 17 of file ChestEntity.cpp.

Member Function Documentation

◆ CopyFrom()

void cChestEntity::CopyFrom ( const cBlockEntity a_Src)
overrideprivatevirtual

Copies all properties of a_Src into this entity, except for its m_World and location.

Each non-abstract descendant should override to copy its specific properties, and call Super::CopyFrom(a_Src) to copy the common ones.

Reimplemented from cBlockEntityWithItems.

Definition at line 129 of file ChestEntity.cpp.

◆ DestroyWindow()

void cChestEntity::DestroyWindow ( )
private

Forces any players to close the owned window.

Definition at line 82 of file ChestEntity.cpp.

◆ GetNumberOfPlayers()

int cChestEntity::GetNumberOfPlayers ( void  ) const
inline

Gets the number of players who currently have this chest open.

Definition at line 40 of file ChestEntity.h.

◆ GetPrimaryChest()

cChestEntity & cChestEntity::GetPrimaryChest ( )

Returns the associated primary chest.

Definition at line 28 of file ChestEntity.cpp.

◆ GetSecondaryChest()

cChestEntity * cChestEntity::GetSecondaryChest ( )

Returns the associated secondary chest, if any.

Definition at line 46 of file ChestEntity.cpp.

◆ IsBlocked()

bool cChestEntity::IsBlocked ( )
private

Returns true if the chest should not be accessible by players.

Definition at line 95 of file ChestEntity.cpp.

◆ OnAddToWorld()

void cChestEntity::OnAddToWorld ( cWorld a_World,
cChunk a_Chunk 
)
overrideprivatevirtual

Called when the block entity object is added to a world.

Reimplemented from cBlockEntity.

Definition at line 144 of file ChestEntity.cpp.

◆ OnRemoveFromWorld()

void cChestEntity::OnRemoveFromWorld ( )
overrideprivatevirtual

Called when the block entity object is removed from a world.

This occurs when the chunk it resides in is unloaded, or when the associated block is destroyed. If it is the latter, Destroy() is guaranteed to be called first.

Reimplemented from cBlockEntity.

Definition at line 167 of file ChestEntity.cpp.

◆ OnSlotChanged()

void cChestEntity::OnSlotChanged ( cItemGrid a_Grid,
int  a_SlotNum 
)
overrideprivatevirtual

cItemGrid::cListener overrides:

Reimplemented from cBlockEntityWithItems.

Definition at line 240 of file ChestEntity.cpp.

◆ OpenNewWindow()

void cChestEntity::OpenNewWindow ( void  )
private

Opens a new chest window where this is the primary chest and any neighbour is the secondary.

Definition at line 110 of file ChestEntity.cpp.

◆ ScanNeighbour()

bool cChestEntity::ScanNeighbour ( cChunk a_Chunk,
Vector3i  a_Position 
)

Search the given horizontally adjacent relative position for a neighbouring chest of the same type.

If found, links them together with ourselves and returns true.

Definition at line 56 of file ChestEntity.cpp.

◆ SendTo()

void cChestEntity::SendTo ( cClientHandle a_Client)
overrideprivatevirtual

Sends the packet defining the block entity to the client specified.

To send to all eligible clients, use cWorld::BroadcastBlockEntity()

Implements cBlockEntity.

Definition at line 183 of file ChestEntity.cpp.

◆ SetNumberOfPlayers()

void cChestEntity::SetNumberOfPlayers ( int  a_NumActivePlayers)
inline

Sets the number of players who currently have this chest open.

Definition at line 53 of file ChestEntity.h.

◆ UsedBy()

bool cChestEntity::UsedBy ( cPlayer a_Player)
overrideprivatevirtual

Called when a player uses this entity; should open the UI window.

returns true if the use was successful, return false to use the block as a "normal" block

Implements cBlockEntity.

Definition at line 192 of file ChestEntity.cpp.

Member Data Documentation

◆ m_Neighbour

cChestEntity* cChestEntity::m_Neighbour
private

Neighbouring chest that links to form a double chest.

Definition at line 61 of file ChestEntity.h.

◆ m_NumActivePlayers

int cChestEntity::m_NumActivePlayers
private

Number of players who currently have this chest open.

Definition at line 58 of file ChestEntity.h.


The documentation for this class was generated from the following files: