7 #include "../FastRandom.h" 8 #include "../MobSpawner.h" 9 #include "../ClientHandle.h" 10 #include "../Items/ItemSpawnEgg.h" 17 super(a_BlockType, a_BlockMeta, a_Pos, a_World),
135 if (NearbyEntities >= 6)
146 bool HaveSpawnedEntity =
false;
147 for (
size_t i = 0; i < 4; i++)
149 if (NearbyEntities >= 6)
156 static_cast<int>((Random.RandReal<
double>() - Random.RandReal<
double>()) * 4.0),
157 Random.RandInt(-1, 1),
158 static_cast<int>((Random.RandReal<
double>() - Random.RandReal<
double>()) * 4.0)
162 if ((chunk ==
nullptr) || !chunk->IsValid())
166 EMCSBiome Biome = chunk->GetBiomeAt(spawnRelPos.
x, spawnRelPos.
z);
170 auto absPos = chunk->RelativeToAbsolute(spawnRelPos);
172 if (monster ==
nullptr)
176 monster->SetPosition(absPos);
177 monster->SetYaw(Random.RandReal(360.0f));
180 HaveSpawnedEntity =
true;
190 return HaveSpawnedEntity;
209 class cCallback :
public cChunkDataCallback
212 cCallback(
Vector3d a_SpawnerPos,
int & a_NumPlayers) :
213 m_SpawnerPos(a_SpawnerPos),
214 m_NumPlayers(a_NumPlayers)
218 virtual void Entity(
cEntity * a_Entity)
override 225 if ((m_SpawnerPos - a_Entity->
GetPosition()).Length() <= 16)
234 } Callback(SpawnerPos, NumPlayers);
252 class cCallback :
public cChunkDataCallback
256 m_SpawnerPos(a_SpawnerPos),
257 m_EntityType(a_CallbackEntityType),
258 m_NumEntities(a_NumEntities)
262 virtual void Entity(
cEntity * a_Entity)
override 264 if (!a_Entity->
IsMob())
275 if ((
Diff(m_SpawnerPos.x, a_Entity->
GetPosX()) <= 8.0) && (
Diff(m_SpawnerPos.y, a_Entity->
GetPosY()) <= 4.0) && (
Diff(m_SpawnerPos.z, a_Entity->
GetPosZ()) <= 8.0))
285 } Callback(SpawnerPos, a_EntityType, NumEntities);
double GetPosY(void) const
void ResetTimer(void)
Sets the spawn delay to a new random value.
double GetPosX(void) const
int GetNearbyPlayersNum(void)
Returns the amount of the nearby players in a 16-block radius.
eMonsterType GetMobType(void) const
cChunk * GetRelNeighborChunkAdjustCoords(Vector3i &a_RelPos) const
Returns the chunk into which the relatively-specified block belongs.
static std::unique_ptr< cMonster > NewMonsterFromType(eMonsterType a_MobType)
Creates a new object of the specified mob.
virtual void SendTo(cClientHandle &a_Client) override
Sends the packet defining the block entity to the client specified.
unsigned char BLOCKTYPE
The datatype used by blockdata.
bool RemoveOneEquippedItem(void)
Removes one item out of the currently equipped item stack, returns true if successful, false if empty-handed.
MTRand & GetRandomProvider()
Returns the current thread's random number source.
const cItem & GetEquippedItem(void) const
bool DoWithChunk(int a_ChunkX, int a_ChunkZ, cChunkCallback a_Callback)
Calls the callback for the chunk specified, with ChunkMapCS locked.
static bool CanSpawnHere(cChunk *a_Chunk, Vector3i a_RelPos, eMonsterType a_MobType, EMCSBiome a_Biome)
Returns true if specified type of mob can spawn on specified block.
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
eMonsterType
Identifies individual monster type, as well as their network type-ID.
virtual void CopyFrom(const cBlockEntity &a_Src) override
Copies all properties of a_Src into this entity, except for its m_World and location.
static eMonsterType ItemDamageToMonsterType(short a_ItemDamage)
Converts the Spawn egg item damage to the monster type to spawn.
cMobSpawnerEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World)
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...
virtual void BroadcastBlockEntity(Vector3i a_BlockPos, const cClientHandle *a_Exclude=nullptr) override
If there is a block entity at the specified coods, sends it to all clients except a_Exclude...
IntType RandInt(IntType a_Min, IntType a_Max)
Return a random IntType in the range [a_Min, a_Max].
Vector3i GetRelPos() const
virtual void BroadcastSoundParticleEffect(const EffectID a_EffectID, Vector3i a_SrcPos, int a_Data, const cClientHandle *a_Exclude=nullptr) override
virtual bool ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ, cChunkDataCallback &a_Callback) override
Calls the callback for each chunk in the coords specified (all cords are inclusive).
Vector3< double > Vector3d
virtual Int64 GetWorldAge(void) const override
void SendUpdateBlockEntity(cBlockEntity &a_BlockEntity)
Vector3i m_Pos
Position in absolute block coordinates.
virtual void CopyFrom(const cBlockEntity &a_Src)
Copies all properties of a_Src into this entity, except for its m_World and location.
void UpdateActiveState(void)
Upate the active flag from the mob spawner.
static AString MobTypeToString(eMonsterType a_MobType)
Translates MobType enum to a string, empty string if unknown.
bool IsPlayer(void) const
eMonsterType m_Entity
The entity to spawn.
virtual bool UsedBy(cPlayer *a_Player) override
Called when a player uses this entity; should open the UI window.
void SpawnEntity(void)
Spawns the entity.
const Vector3d & GetPosition(void) const
Exported in ManualBindings.
double GetPosZ(void) const
bool IsGameModeCreative(void) const
Returns true if the player is in Creative mode, either explicitly, or by inheriting from current worl...
cInventory & GetInventory(void)
static const UInt32 INVALID_ID
Special ID that is considered an "invalid value", signifying no entity.
T Diff(T a_Val1, T a_Val2)
int GetNearbyMonsterNum(eMonsterType a_EntityType)
Returns the amount of this monster type in a 8-block radius (Y: 4-block radius).