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

#include <CommandBlockEntity.h>

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

Public Member Functions

void Activate (void)
 Sets the command block to execute a command in the next tick. More...
 
 cCommandBlockEntity (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World)
 Creates a new empty command block entity. More...
 
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...
 
const AStringGetCommand (void) const
 Retrieves stored command. More...
 
const AStringGetLastOutput (void) const
 Retrieves the last line of output generated by the command block. More...
 
NIBBLETYPE GetResult (void) const
 Retrieves the result (signal strength) of the last operation. More...
 
virtual void SendTo (cClientHandle &a_Client) override
 Sends the packet defining the block entity to the client specified. More...
 
void SetCommand (const AString &a_Cmd)
 Sets the command. More...
 
void SetLastOutput (const AString &a_LastOut)
 
void SetResult (const NIBBLETYPE a_Result)
 
virtual bool Tick (std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
 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) override
 Called when a player uses this entity; should open the UI window. More...
 
- 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 cItems ConvertToPickups () const
 Returns the contents of this block entity that it would drop if broken. 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...
 
void SetPos (Vector3i a_NewPos)
 Updates the internally stored position. More...
 
void SetWorld (cWorld *a_World)
 
virtual ~cBlockEntity ()=default
 

Private Types

using Super = cBlockEntity
 

Private Member Functions

void Execute ()
 Executes the associated command. More...
 

Private Attributes

AString m_Command
 
AString m_LastOutput
 
NIBBLETYPE m_Result
 
bool m_ShouldExecute
 

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 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 20 of file CommandBlockEntity.h.

Member Typedef Documentation

◆ Super

Definition at line 25 of file CommandBlockEntity.h.

Constructor & Destructor Documentation

◆ cCommandBlockEntity()

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

Creates a new empty command block entity.

Definition at line 20 of file CommandBlockEntity.cpp.

Member Function Documentation

◆ Activate()

void cCommandBlockEntity::Activate ( void  )

Sets the command block to execute a command in the next tick.

Definition at line 97 of file CommandBlockEntity.cpp.

◆ CopyFrom()

void cCommandBlockEntity::CopyFrom ( const cBlockEntity a_Src)
overridevirtual

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

Definition at line 106 of file CommandBlockEntity.cpp.

◆ Execute()

void cCommandBlockEntity::Execute ( )
private

Executes the associated command.

Definition at line 147 of file CommandBlockEntity.cpp.

◆ GetCommand()

const AString & cCommandBlockEntity::GetCommand ( void  ) const

Retrieves stored command.

Definition at line 70 of file CommandBlockEntity.cpp.

◆ GetLastOutput()

const AString & cCommandBlockEntity::GetLastOutput ( void  ) const

Retrieves the last line of output generated by the command block.

Definition at line 79 of file CommandBlockEntity.cpp.

◆ GetResult()

NIBBLETYPE cCommandBlockEntity::GetResult ( void  ) const

Retrieves the result (signal strength) of the last operation.

Definition at line 88 of file CommandBlockEntity.cpp.

◆ SendTo()

void cCommandBlockEntity::SendTo ( cClientHandle a_Client)
overridevirtual

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 138 of file CommandBlockEntity.cpp.

◆ SetCommand()

void cCommandBlockEntity::SetCommand ( const AString a_Cmd)

Sets the command.

Definition at line 43 of file CommandBlockEntity.cpp.

◆ SetLastOutput()

void cCommandBlockEntity::SetLastOutput ( const AString a_LastOut)

Definition at line 52 of file CommandBlockEntity.cpp.

◆ SetResult()

void cCommandBlockEntity::SetResult ( const NIBBLETYPE  a_Result)

Definition at line 61 of file CommandBlockEntity.cpp.

◆ Tick()

bool cCommandBlockEntity::Tick ( std::chrono::milliseconds  a_Dt,
cChunk a_Chunk 
)
overridevirtual

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

By default does nothing.

Reimplemented from cBlockEntity.

Definition at line 120 of file CommandBlockEntity.cpp.

◆ UsedBy()

bool cCommandBlockEntity::UsedBy ( cPlayer a_Player)
overridevirtual

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 32 of file CommandBlockEntity.cpp.

Member Data Documentation

◆ m_Command

AString cCommandBlockEntity::m_Command
private

Definition at line 68 of file CommandBlockEntity.h.

◆ m_LastOutput

AString cCommandBlockEntity::m_LastOutput
private

Definition at line 70 of file CommandBlockEntity.h.

◆ m_Result

NIBBLETYPE cCommandBlockEntity::m_Result
private

Definition at line 72 of file CommandBlockEntity.h.

◆ m_ShouldExecute

bool cCommandBlockEntity::m_ShouldExecute
private

Definition at line 66 of file CommandBlockEntity.h.


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