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

#include <MobSpawnerEntity.h>

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

Public Member Functions

 cMobSpawnerEntity (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World)
 
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...
 
eMonsterType GetEntity (void) const
 
short GetMaxNearbyEntities (void) const
 
short GetMaxSpawnDelay (void) const
 
short GetMinSpawnDelay (void) const
 
int GetNearbyMonsterNum (eMonsterType a_EntityType)
 
int GetNearbyPlayersNum (void)
 
short GetRequiredPlayerRange (void) const
 
short GetSpawnCount (void) const
 
short GetSpawnDelay (void) const
 
short GetSpawnRange (void) const
 
void ResetTimer (void)
 Sets the spawn delay to a new random value. More...
 
virtual void SendTo (cClientHandle &a_Client) override
 Sends the packet defining the block entity to the client specified. More...
 
void SetEntity (eMonsterType a_EntityType)
 
void SetMaxNearbyEntities (short a_MaxNearbyEntities)
 
void SetMaxSpawnDelay (short a_Max)
 
void SetMinSpawnDelay (short a_Min)
 
void SetRequiredPlayerRange (short a_RequiredPlayerRange)
 
void SetSpawnCount (short a_SpawnCount)
 
void SetSpawnDelay (short a_Delay)
 
void SetSpawnRange (short a_SpawnRange)
 
void SpawnEntity (void)
 Spawns the entity. More...
 
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...
 
void UpdateActiveState (void)
 Update the active flag from the mob spawner. 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 Attributes

eMonsterType m_Entity
 The entity to spawn. More...
 
bool m_IsActive
 
short m_MaxNearbyEntities = 6
 Maximum amount of the same entity type in proximity. More...
 
short m_MaxSpawnDelay = 800
 
short m_MinSpawnDelay = 200
 
short m_RequiredPlayerRange = 16
 Maximum distance to player for activation. More...
 
short m_SpawnCount = 4
 Number of entities the spawner tries to spawn each activation. More...
 
short m_SpawnDelay
 Time in ticks until the next entity spawns. More...
 
short m_SpawnRange = 8
 Diameter of the square the new monsters are spawned in. 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 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 19 of file MobSpawnerEntity.h.

Member Typedef Documentation

◆ Super

Definition at line 24 of file MobSpawnerEntity.h.

Constructor & Destructor Documentation

◆ cMobSpawnerEntity()

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

Definition at line 16 of file MobSpawnerEntity.cpp.

Member Function Documentation

◆ CopyFrom()

void cMobSpawnerEntity::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 29 of file MobSpawnerEntity.cpp.

◆ GetEntity()

eMonsterType cMobSpawnerEntity::GetEntity ( void  ) const
inline

Definition at line 51 of file MobSpawnerEntity.h.

◆ GetMaxNearbyEntities()

short cMobSpawnerEntity::GetMaxNearbyEntities ( void  ) const
inline

Definition at line 57 of file MobSpawnerEntity.h.

◆ GetMaxSpawnDelay()

short cMobSpawnerEntity::GetMaxSpawnDelay ( void  ) const
inline

Definition at line 56 of file MobSpawnerEntity.h.

◆ GetMinSpawnDelay()

short cMobSpawnerEntity::GetMinSpawnDelay ( void  ) const
inline

Definition at line 55 of file MobSpawnerEntity.h.

◆ GetNearbyMonsterNum()

int cMobSpawnerEntity::GetNearbyMonsterNum ( eMonsterType  a_EntityType)

Definition at line 229 of file MobSpawnerEntity.cpp.

◆ GetNearbyPlayersNum()

int cMobSpawnerEntity::GetNearbyPlayersNum ( void  )

Definition at line 202 of file MobSpawnerEntity.cpp.

◆ GetRequiredPlayerRange()

short cMobSpawnerEntity::GetRequiredPlayerRange ( void  ) const
inline

Definition at line 58 of file MobSpawnerEntity.h.

◆ GetSpawnCount()

short cMobSpawnerEntity::GetSpawnCount ( void  ) const
inline

Definition at line 52 of file MobSpawnerEntity.h.

◆ GetSpawnDelay()

short cMobSpawnerEntity::GetSpawnDelay ( void  ) const
inline

Definition at line 54 of file MobSpawnerEntity.h.

◆ GetSpawnRange()

short cMobSpawnerEntity::GetSpawnRange ( void  ) const
inline

Definition at line 53 of file MobSpawnerEntity.h.

◆ ResetTimer()

void cMobSpawnerEntity::ResetTimer ( void  )

Sets the spawn delay to a new random value.

Definition at line 125 of file MobSpawnerEntity.cpp.

◆ SendTo()

void cMobSpawnerEntity::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 48 of file MobSpawnerEntity.cpp.

◆ SetEntity()

void cMobSpawnerEntity::SetEntity ( eMonsterType  a_EntityType)
inline

Definition at line 61 of file MobSpawnerEntity.h.

◆ SetMaxNearbyEntities()

void cMobSpawnerEntity::SetMaxNearbyEntities ( short  a_MaxNearbyEntities)
inline

Definition at line 67 of file MobSpawnerEntity.h.

◆ SetMaxSpawnDelay()

void cMobSpawnerEntity::SetMaxSpawnDelay ( short  a_Max)
inline

Definition at line 66 of file MobSpawnerEntity.h.

◆ SetMinSpawnDelay()

void cMobSpawnerEntity::SetMinSpawnDelay ( short  a_Min)
inline

Definition at line 65 of file MobSpawnerEntity.h.

◆ SetRequiredPlayerRange()

void cMobSpawnerEntity::SetRequiredPlayerRange ( short  a_RequiredPlayerRange)
inline

Definition at line 68 of file MobSpawnerEntity.h.

◆ SetSpawnCount()

void cMobSpawnerEntity::SetSpawnCount ( short  a_SpawnCount)
inline

Definition at line 63 of file MobSpawnerEntity.h.

◆ SetSpawnDelay()

void cMobSpawnerEntity::SetSpawnDelay ( short  a_Delay)
inline

Definition at line 62 of file MobSpawnerEntity.h.

◆ SetSpawnRange()

void cMobSpawnerEntity::SetSpawnRange ( short  a_SpawnRange)
inline

Definition at line 64 of file MobSpawnerEntity.h.

◆ SpawnEntity()

void cMobSpawnerEntity::SpawnEntity ( void  )

Spawns the entity.

This function automatically change the spawn delay!

Definition at line 134 of file MobSpawnerEntity.cpp.

◆ Tick()

bool cMobSpawnerEntity::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 93 of file MobSpawnerEntity.cpp.

◆ UpdateActiveState()

void cMobSpawnerEntity::UpdateActiveState ( void  )

Update the active flag from the mob spawner.

This function will called every 5 seconds from the Tick() function.

Definition at line 84 of file MobSpawnerEntity.cpp.

◆ UsedBy()

bool cMobSpawnerEntity::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 57 of file MobSpawnerEntity.cpp.

Member Data Documentation

◆ m_Entity

eMonsterType cMobSpawnerEntity::m_Entity
private

The entity to spawn.

Definition at line 75 of file MobSpawnerEntity.h.

◆ m_IsActive

bool cMobSpawnerEntity::m_IsActive
private

Definition at line 80 of file MobSpawnerEntity.h.

◆ m_MaxNearbyEntities

short cMobSpawnerEntity::m_MaxNearbyEntities = 6
private

Maximum amount of the same entity type in proximity.

Definition at line 93 of file MobSpawnerEntity.h.

◆ m_MaxSpawnDelay

short cMobSpawnerEntity::m_MaxSpawnDelay = 800
private

Definition at line 90 of file MobSpawnerEntity.h.

◆ m_MinSpawnDelay

short cMobSpawnerEntity::m_MinSpawnDelay = 200
private

Definition at line 88 of file MobSpawnerEntity.h.

◆ m_RequiredPlayerRange

short cMobSpawnerEntity::m_RequiredPlayerRange = 16
private

Maximum distance to player for activation.

Definition at line 96 of file MobSpawnerEntity.h.

◆ m_SpawnCount

short cMobSpawnerEntity::m_SpawnCount = 4
private

Number of entities the spawner tries to spawn each activation.

Definition at line 83 of file MobSpawnerEntity.h.

◆ m_SpawnDelay

short cMobSpawnerEntity::m_SpawnDelay
private

Time in ticks until the next entity spawns.

Definition at line 78 of file MobSpawnerEntity.h.

◆ m_SpawnRange

short cMobSpawnerEntity::m_SpawnRange = 8
private

Diameter of the square the new monsters are spawned in.

Definition at line 86 of file MobSpawnerEntity.h.


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