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),
95 using namespace std::chrono_literals;
146 auto EntitySpawnTally = NearbyEntities;
148 bool HaveSpawnedEntity =
false;
158 static_cast<int>((Random.RandReal<
double>() - Random.RandReal<
double>()) *
static_cast<double>(
m_SpawnRange)),
159 Random.RandInt(-1, 1),
160 static_cast<int>((Random.RandReal<
double>() - Random.RandReal<
double>()) *
static_cast<double>(
m_SpawnRange))
164 if ((Chunk ==
nullptr) || !Chunk->IsValid())
172 auto AbsPos = Chunk->RelativeToAbsolute(SpawnRelPos);
174 if (Monster ==
nullptr)
178 Monster->SetPosition(AbsPos);
179 Monster->SetYaw(Random.RandReal(360.0f));
182 HaveSpawnedEntity =
true;
188 return HaveSpawnedEntity;
206 auto Callback = [
this, &NumPlayers](
cEntity & a_Entity)
208 if (!a_Entity.IsPlayer())
233 auto Callback = [
this, &NumEntities](
cEntity & a_Entity)
235 if (!a_Entity.IsMob())
240 auto & Mob =
static_cast<cMonster &
>(a_Entity);
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
unsigned char BLOCKTYPE
The datatype used by blockdata.
MTRand & GetRandomProvider()
Returns the current thread's random number source.
eMonsterType
Identifies individual monster type.
Vector3< double > Vector3d
Vector3i GetRelPos() const
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.
virtual bool UsedBy(cPlayer *a_Player) override
Called when a player uses this entity; should open the UI window.
int GetNearbyPlayersNum(void)
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.
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 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 m_MaxNearbyEntities
Maximum amount of the same entity type in proximity.
cMobSpawnerEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World)
void SpawnEntity(void)
Spawns the entity.
int GetNearbyMonsterNum(eMonsterType a_EntityType)
short m_RequiredPlayerRange
Maximum distance to player for activation.
Represents two sets of coords, minimum and maximum for each direction.
EMCSBiome GetBiomeAt(int a_RelX, int a_RelZ) const
cChunk * GetRelNeighborChunkAdjustCoords(Vector3i &a_RelPos) const
Returns the chunk into which the relatively-specified block belongs.
void SendUpdateBlockEntity(cBlockEntity &a_BlockEntity)
static const UInt32 INVALID_ID
Special ID that is considered an "invalid value", signifying no entity.
const cItem & GetEquippedItem(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)
IntType RandInt(IntType a_Min, IntType a_Max)
Return a random IntType in the range [a_Min, a_Max].
bool RemoveOneEquippedItem(void)
Removes one item out of the currently equipped item stack, returns true if successful,...
static eMonsterType ItemDamageToMonsterType(short a_ItemDamage)
Converts the Spawn egg item damage to the monster type to spawn.
static std::unique_ptr< cMonster > NewMonsterFromType(eMonsterType a_MobType)
Creates a new object of the specified mob.
static AString MobTypeToString(eMonsterType a_MobType)
Translates MobType enum to a string, empty string if unknown.
static bool CanSpawnHere(cChunk *a_Chunk, Vector3i a_RelPos, eMonsterType a_MobType, EMCSBiome a_Biome, bool a_DisableSolidBelowCheck=false)
Returns true if specified type of mob can spawn on specified block.
bool DoWithChunk(int a_ChunkX, int a_ChunkZ, cChunkCallback a_Callback)
Calls the callback for the chunk specified, with ChunkMapCS locked.
virtual bool ForEachEntityInBox(const cBoundingBox &a_Box, cEntityCallback a_Callback) override
Calls the callback for each entity that has a nonempty intersection with the specified boundingbox.
virtual void BroadcastSoundParticleEffect(const EffectID a_EffectID, Vector3i a_SrcPos, int a_Data, const cClientHandle *a_Exclude=nullptr) override
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.
cTickTimeLong GetWorldTickAge() const