Cuberite
A lightweight, fast and extensible game server for Minecraft
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cBlockEntity Class Referenceabstract

#include <BlockEntity.h>

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

Public Member Functions

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 cItems ConvertToPickups () const
 Returns the contents of this block entity that it would drop if broken. More...
 
virtual void CopyFrom (const cBlockEntity &a_Src)
 Copies all properties of a_Src into this entity, except for its m_World and location. 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
 
virtual void OnAddToWorld (cWorld &a_World, cChunk &a_Chunk)
 Called when the block entity object is added to a world. More...
 
virtual void OnRemoveFromWorld ()
 Called when the block entity object is removed from a world. More...
 
virtual void SendTo (cClientHandle &a_Client)=0
 Sends the packet defining the block entity to the client specified. More...
 
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 bool UsedBy (cPlayer *a_Player)=0
 Called when a player uses this entity; should open the UI window. More...
 
virtual ~cBlockEntity ()=default
 

Static Public Member Functions

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

 cBlockEntity (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World)
 

Protected Attributes

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 24 of file BlockEntity.h.

Constructor & Destructor Documentation

◆ cBlockEntity()

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

Definition at line 32 of file BlockEntity.cpp.

◆ ~cBlockEntity()

virtual cBlockEntity::~cBlockEntity ( )
virtualdefault

Member Function Documentation

◆ Clone()

OwnedBlockEntity cBlockEntity::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.

Uses CopyFrom() to copy the properties.

Definition at line 46 of file BlockEntity.cpp.

◆ ConvertToPickups()

cItems cBlockEntity::ConvertToPickups ( ) const
virtual

Returns the contents of this block entity that it would drop if broken.

Note that the block handler will usually handle pickups for the block itself, in addition to any items returned here.

Reimplemented in cMobHeadEntity, cJukeboxEntity, cFlowerPotEntity, cEnchantingTableEntity, cBlockEntityWithItems, cBedEntity, and cBannerEntity.

Definition at line 57 of file BlockEntity.cpp.

◆ CopyFrom()

void cBlockEntity::CopyFrom ( const cBlockEntity a_Src)
virtual

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 in cSignEntity, cNoteEntity, cMobSpawnerEntity, cMobHeadEntity, cJukeboxEntity, cHopperEntity, cFurnaceEntity, cFlowerPotEntity, cEndPortalEntity, cEnchantingTableEntity, cDropSpenserEntity, cCommandBlockEntity, cChestEntity, cBrewingstandEntity, cBlockEntityWithItems, cBedEntity, cBeaconEntity, and cBannerEntity.

Definition at line 66 of file BlockEntity.cpp.

◆ CreateByBlockType()

OwnedBlockEntity cBlockEntity::CreateByBlockType ( BLOCKTYPE  a_BlockType,
NIBBLETYPE  a_BlockMeta,
Vector3i  a_Pos,
cWorld a_World = nullptr 
)
static

Creates a new block entity for the specified block type at the specified absolute pos.

If a_World is valid, then the entity is created bound to that world Returns nullptr for unknown block types.

Definition at line 77 of file BlockEntity.cpp.

◆ Destroy()

void cBlockEntity::Destroy ( void  )
virtual

Called when this block entity's associated block is destroyed.

It is guaranteed that this function is called before OnRemoveFromWorld.

Reimplemented in cJukeboxEntity.

Definition at line 122 of file BlockEntity.cpp.

◆ GetBlockType()

BLOCKTYPE cBlockEntity::GetBlockType ( ) const
inline

Definition at line 97 of file BlockEntity.h.

◆ GetChunkX()

int cBlockEntity::GetChunkX ( ) const
inline

Definition at line 101 of file BlockEntity.h.

◆ GetChunkZ()

int cBlockEntity::GetChunkZ ( ) const
inline

Definition at line 102 of file BlockEntity.h.

◆ GetPos()

Vector3i cBlockEntity::GetPos ( ) const
inline

Definition at line 90 of file BlockEntity.h.

◆ GetPosX()

int cBlockEntity::GetPosX ( ) const
inline

Definition at line 91 of file BlockEntity.h.

◆ GetPosY()

int cBlockEntity::GetPosY ( ) const
inline

Definition at line 92 of file BlockEntity.h.

◆ GetPosZ()

int cBlockEntity::GetPosZ ( ) const
inline

Definition at line 93 of file BlockEntity.h.

◆ GetRelPos()

Vector3i cBlockEntity::GetRelPos ( ) const
inline

Definition at line 95 of file BlockEntity.h.

◆ GetRelX()

int cBlockEntity::GetRelX ( ) const
inline

Definition at line 104 of file BlockEntity.h.

◆ GetRelZ()

int cBlockEntity::GetRelZ ( ) const
inline

Definition at line 105 of file BlockEntity.h.

◆ GetWorld()

cWorld* cBlockEntity::GetWorld ( ) const
inline

Definition at line 99 of file BlockEntity.h.

◆ IsBlockEntityBlockType()

bool cBlockEntity::IsBlockEntityBlockType ( BLOCKTYPE  a_BlockType)
static

Returns true if the specified blocktype is supposed to have an associated block entity.

Definition at line 130 of file BlockEntity.cpp.

◆ OnAddToWorld()

void cBlockEntity::OnAddToWorld ( cWorld a_World,
cChunk a_Chunk 
)
virtual

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

Reimplemented in cChestEntity.

Definition at line 171 of file BlockEntity.cpp.

◆ OnRemoveFromWorld()

void cBlockEntity::OnRemoveFromWorld ( )
virtual

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 in cFurnaceEntity, cEnderChestEntity, cDropSpenserEntity, cChestEntity, cBrewingstandEntity, and cBeaconEntity.

Definition at line 180 of file BlockEntity.cpp.

◆ SendTo()

virtual void cBlockEntity::SendTo ( cClientHandle a_Client)
pure virtual

◆ SetPos()

void cBlockEntity::SetPos ( Vector3i  a_NewPos)

Updates the internally stored position.

Note that this should not ever be used for world-contained block entities, it is meant only for when BEs in a cBlockArea are manipulated. Asserts that the block entity is not assigned to a world.

Definition at line 188 of file BlockEntity.cpp.

◆ SetWorld()

void cBlockEntity::SetWorld ( cWorld a_World)

Definition at line 198 of file BlockEntity.cpp.

◆ Tick()

bool cBlockEntity::Tick ( std::chrono::milliseconds  a_Dt,
cChunk a_Chunk 
)
virtual

Ticks the entity; returns true if the chunk should be marked as dirty as a result of this ticking.

By default does nothing.

Reimplemented in cMobSpawnerEntity, cHopperEntity, cFurnaceEntity, cDropSpenserEntity, cCommandBlockEntity, cBrewingstandEntity, and cBeaconEntity.

Definition at line 207 of file BlockEntity.cpp.

◆ UsedBy()

virtual bool cBlockEntity::UsedBy ( cPlayer a_Player)
pure virtual

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

Implemented in cSignEntity, cNoteEntity, cMobSpawnerEntity, cMobHeadEntity, cJukeboxEntity, cHopperEntity, cFurnaceEntity, cFlowerPotEntity, cEndPortalEntity, cEnderChestEntity, cEnchantingTableEntity, cDropSpenserEntity, cCommandBlockEntity, cChestEntity, cBrewingstandEntity, cBedEntity, cBeaconEntity, and cBannerEntity.

Member Data Documentation

◆ m_BlockMeta

NIBBLETYPE cBlockEntity::m_BlockMeta
protected

The block meta representing this particular instance in the world Mainly used for directional entities, such as dispensers.

Definition at line 124 of file BlockEntity.h.

◆ m_BlockType

BLOCKTYPE cBlockEntity::m_BlockType
protected

The blocktype representing this particular instance in the world.

Mainly used for multi-block-type entities, such as furnaces / lit furnaces.

Definition at line 120 of file BlockEntity.h.

◆ m_Pos

Vector3i cBlockEntity::m_Pos
protected

Position in absolute block coordinates.

Definition at line 113 of file BlockEntity.h.

◆ m_RelX

int cBlockEntity::m_RelX
protected

Position relative to the chunk, used to speed up ticking.

Definition at line 116 of file BlockEntity.h.

◆ m_RelZ

int cBlockEntity::m_RelZ
protected

Definition at line 116 of file BlockEntity.h.

◆ m_World

cWorld* cBlockEntity::m_World
protected

Definition at line 126 of file BlockEntity.h.


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