Cuberite
A lightweight, fast and extensible game server for Minecraft
MobSpawnerEntity.h
Go to the documentation of this file.
1 // MobSpawnerEntity.h
2 
3 // Declares the cMobSpawnerEntity class representing a single mob spawner in the world
4 
5 
6 
7 
8 
9 #pragma once
10 
11 #include "BlockEntity.h"
12 #include "../Entities/Player.h"
13 
14 
15 
16 
17 
18 // tolua_begin
20  public cBlockEntity
21 {
22  // tolua_end
23 
25 
26 public: // tolua_export
27 
28  cMobSpawnerEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld * a_World);
29 
30  // cBlockEntity overrides:
31  virtual void CopyFrom(const cBlockEntity & a_Src) override;
32  virtual void SendTo(cClientHandle & a_Client) override;
33  virtual bool UsedBy(cPlayer * a_Player) override;
34  virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
35 
36  // tolua_begin
37 
39  void UpdateActiveState(void);
40 
42  void ResetTimer(void);
43 
45  void SpawnEntity(void);
46 
47  // Getters
48  int GetNearbyMonsterNum(eMonsterType a_EntityType);
49  int GetNearbyPlayersNum(void);
50 
51  eMonsterType GetEntity(void) const { return m_Entity; }
52  short GetSpawnCount(void) const { return m_SpawnCount; }
53  short GetSpawnRange(void) const { return m_SpawnRange; }
54  short GetSpawnDelay(void) const { return m_SpawnDelay; }
55  short GetMinSpawnDelay(void) const { return m_MinSpawnDelay; }
56  short GetMaxSpawnDelay(void) const { return m_MaxSpawnDelay; }
57  short GetMaxNearbyEntities(void) const { return m_MaxNearbyEntities; }
58  short GetRequiredPlayerRange(void) const { return m_RequiredPlayerRange; }
59 
60  // Setters
61  void SetEntity(eMonsterType a_EntityType) { m_Entity = a_EntityType; }
62  void SetSpawnDelay(short a_Delay) { m_SpawnDelay = a_Delay; }
63  void SetSpawnCount(short a_SpawnCount) { m_SpawnCount = a_SpawnCount; }
64  void SetSpawnRange(short a_SpawnRange) { m_SpawnRange = a_SpawnRange; }
65  void SetMinSpawnDelay(short a_Min) { m_MinSpawnDelay = a_Min; }
66  void SetMaxSpawnDelay(short a_Max) { m_MaxSpawnDelay = a_Max; }
67  void SetMaxNearbyEntities(short a_MaxNearbyEntities) { m_MaxNearbyEntities = a_MaxNearbyEntities; }
68  void SetRequiredPlayerRange(short a_RequiredPlayerRange) { m_RequiredPlayerRange = a_RequiredPlayerRange; }
69 
70  // tolua_end
71 
72 private:
73 
76 
78  short m_SpawnDelay;
79 
80  bool m_IsActive;
81 
83  short m_SpawnCount = 4;
84 
86  short m_SpawnRange = 8;
87 
88  short m_MinSpawnDelay = 200;
89 
90  short m_MaxSpawnDelay = 800;
91 
94 
97 
98 } ; // tolua_end
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
eMonsterType
Identifies individual monster type.
Definition: MonsterTypes.h:11
cBlockEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World)
Definition: BlockEntity.cpp:32
void SetSpawnDelay(short a_Delay)
void SetSpawnRange(short a_SpawnRange)
virtual bool UsedBy(cPlayer *a_Player) override
Called when a player uses this entity; should open the UI window.
short GetSpawnDelay(void) const
short m_SpawnDelay
Time in ticks until the next entity spawns.
void UpdateActiveState(void)
Update the active flag from the mob spawner.
short m_SpawnRange
Diameter of the square the new monsters are spawned in.
virtual void SendTo(cClientHandle &a_Client) override
Sends the packet defining the block entity to the client specified.
short GetRequiredPlayerRange(void) const
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.
void SetMaxSpawnDelay(short a_Max)
void SetMinSpawnDelay(short a_Min)
void ResetTimer(void)
Sets the spawn delay to a new random value.
virtual void CopyFrom(const cBlockEntity &a_Src) override
Copies all properties of a_Src into this entity, except for its m_World and location.
eMonsterType m_Entity
The entity to spawn.
short m_SpawnCount
Number of entities the spawner tries to spawn each activation.
short GetMaxSpawnDelay(void) const
short GetSpawnRange(void) const
short m_MaxNearbyEntities
Maximum amount of the same entity type in proximity.
cMobSpawnerEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World)
short GetMinSpawnDelay(void) const
void SpawnEntity(void)
Spawns the entity.
int GetNearbyMonsterNum(eMonsterType a_EntityType)
short m_RequiredPlayerRange
Maximum distance to player for activation.
void SetRequiredPlayerRange(short a_RequiredPlayerRange)
void SetEntity(eMonsterType a_EntityType)
void SetMaxNearbyEntities(short a_MaxNearbyEntities)
short GetSpawnCount(void) const
eMonsterType GetEntity(void) const
void SetSpawnCount(short a_SpawnCount)
short GetMaxNearbyEntities(void) const
Definition: Chunk.h:36
Definition: Player.h:29
Definition: World.h:53