Cuberite
A lightweight, fast and extensible game server for Minecraft
World.h
Go to the documentation of this file.
1 
2 #pragma once
3 
5 #include "ChunkMap.h"
7 #include "ChunkGeneratorThread.h"
8 #include "ChunkSender.h"
9 #include "Defines.h"
10 #include "LightingThread.h"
11 #include "IniFile.h"
12 #include "Item.h"
13 #include "Mobs/Monster.h"
15 #include "Entities/Boat.h"
16 #include "ForEachChunkProvider.h"
17 #include "Scoreboard.h"
18 #include "MapManager.h"
19 #include "Blocks/WorldInterface.h"
21 #include "EffectID.h"
22 
23 
24 
25 
26 
27 class cFireSimulator;
28 class cFluidSimulator;
29 class cSandSimulator;
30 class cRedstoneSimulator;
31 class cItem;
32 class cPlayer;
33 class cClientHandle;
34 class cEntity;
35 class cChunkGenerator; // The thread responsible for generating chunks
36 class cCuboid;
37 class cCompositeChat;
38 class cDeadlockDetect;
39 class cUUID;
40 
41 struct SetChunkData;
42 
43 
44 
45 
46 
47 class cWorld // tolua_export
48  final:
49  public cForEachChunkProvider,
50  public cWorldInterface,
51  public cBroadcastInterface
52 // tolua_begin
53 {
54 public:
55  // tolua_end
56 
58  class cLock:
59  public cCSLock
60  {
61  using Super = cCSLock;
62  public:
63  cLock(const cWorld & a_World);
64  };
65 
70  cWorld(
71  const AString & a_WorldName, const AString & a_DataPath,
72  cDeadlockDetect & a_DeadlockDetect, const AStringVector & a_WorldNames,
73  eDimension a_Dimension = dimOverworld, const AString & a_LinkedOverworldName = {}
74  );
75 
76  virtual ~cWorld() override;
77 
78  // tolua_begin
79 
81  bool IsSavingEnabled(void) const { return m_IsSavingEnabled; }
82 
84  void SetSavingEnabled(bool a_IsSavingEnabled) { m_IsSavingEnabled = a_IsSavingEnabled; }
85 
86  int GetTicksUntilWeatherChange(void) const { return m_WeatherInterval; }
87 
89  virtual bool IsDaylightCycleEnabled(void) const { return m_IsDaylightCycleEnabled; }
90 
92  virtual void SetDaylightCycleEnabled(bool a_IsDaylightCycleEnabled)
93  {
94  m_IsDaylightCycleEnabled = a_IsDaylightCycleEnabled;
96  }
97 
98  void SetTicksUntilWeatherChange(int a_WeatherInterval)
99  {
100  m_WeatherInterval = a_WeatherInterval;
101  }
102 
105  int GetDefaultWeatherInterval(eWeather a_Weather) const;
106 
108  eGameMode GetGameMode(void) const { return m_GameMode; }
109 
111  bool IsGameModeCreative(void) const { return (m_GameMode == gmCreative); }
112 
114  bool IsGameModeSurvival(void) const { return (m_GameMode == gmSurvival); }
115 
117  bool IsGameModeAdventure(void) const { return (m_GameMode == gmAdventure); }
118 
120  bool IsGameModeSpectator(void) const { return (m_GameMode == gmSpectator); }
121 
122  bool IsPVPEnabled(void) const { return m_bEnabledPVP; }
123 
126 
127  bool IsDeepSnowEnabled(void) const { return m_IsDeepSnowEnabled; }
128 
129  bool ShouldLavaSpawnFire(void) const { return m_ShouldLavaSpawnFire; }
130 
132 
133  virtual eDimension GetDimension(void) const override { return m_Dimension; }
134 
136  virtual int GetHeight(int a_BlockX, int a_BlockZ) override;
137 
138  // tolua_end
139 
140  virtual cTickTime GetTimeOfDay(void) const override;
141  virtual cTickTimeLong GetWorldAge(void) const override;
142  cTickTimeLong GetWorldDate() const;
144 
145  virtual void SetTimeOfDay(cTickTime a_TimeOfDay) override;
146 
148  bool TryGetHeight(int a_BlockX, int a_BlockZ, int & a_Height); // Exported in ManualBindings.cpp
149 
150  // Broadcast respective packets to all clients of the chunk where the event is taking place
151  // Implemented in Broadcaster.cpp
152  // (Please keep these alpha-sorted)
153  virtual void BroadcastAttachEntity (const cEntity & a_Entity, const cEntity & a_Vehicle) override;
154  virtual void BroadcastBlockAction (Vector3i a_BlockPos, Byte a_Byte1, Byte a_Byte2, BLOCKTYPE a_BlockType, const cClientHandle * a_Exclude = nullptr) override; // Exported in ManualBindings_World.cpp
155  virtual void BroadcastBlockBreakAnimation(UInt32 a_EntityID, Vector3i a_BlockPos, Int8 a_Stage, const cClientHandle * a_Exclude = nullptr) override;
156  virtual void BroadcastBlockEntity (Vector3i a_BlockPos, const cClientHandle * a_Exclude = nullptr) override;
157  virtual void BroadcastBossBarUpdateHealth(const cEntity & a_Entity, UInt32 a_UniqueID, float a_FractionFilled) override;
158 
159  // tolua_begin
160  virtual void BroadcastChat (const AString & a_Message, const cClientHandle * a_Exclude = nullptr, eMessageType a_ChatPrefix = mtCustom) override;
161  virtual void BroadcastChatInfo (const AString & a_Message, const cClientHandle * a_Exclude = nullptr) override { BroadcastChat(a_Message, a_Exclude, mtInformation); }
162  virtual void BroadcastChatFailure(const AString & a_Message, const cClientHandle * a_Exclude = nullptr) override { BroadcastChat(a_Message, a_Exclude, mtFailure); }
163  virtual void BroadcastChatSuccess(const AString & a_Message, const cClientHandle * a_Exclude = nullptr) override { BroadcastChat(a_Message, a_Exclude, mtSuccess); }
164  virtual void BroadcastChatWarning(const AString & a_Message, const cClientHandle * a_Exclude = nullptr) override { BroadcastChat(a_Message, a_Exclude, mtWarning); }
165  virtual void BroadcastChatFatal (const AString & a_Message, const cClientHandle * a_Exclude = nullptr) override { BroadcastChat(a_Message, a_Exclude, mtFailure); }
166  virtual void BroadcastChatDeath (const AString & a_Message, const cClientHandle * a_Exclude = nullptr) override { BroadcastChat(a_Message, a_Exclude, mtDeath); }
167  virtual void BroadcastChat (const cCompositeChat & a_Message, const cClientHandle * a_Exclude = nullptr) override;
168  // tolua_end
169 
170  virtual void BroadcastCollectEntity (const cEntity & a_Collected, const cEntity & a_Collector, unsigned a_Count, const cClientHandle * a_Exclude = nullptr) override;
171  virtual void BroadcastDestroyEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = nullptr) override;
172  virtual void BroadcastDetachEntity (const cEntity & a_Entity, const cEntity & a_PreviousVehicle) override;
173  virtual void BroadcastEntityEffect (const cEntity & a_Entity, int a_EffectID, int a_Amplifier, int a_Duration, const cClientHandle * a_Exclude = nullptr) override;
174  virtual void BroadcastEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item, const cClientHandle * a_Exclude = nullptr) override;
175  virtual void BroadcastEntityHeadLook (const cEntity & a_Entity, const cClientHandle * a_Exclude = nullptr) override;
176  virtual void BroadcastEntityLook (const cEntity & a_Entity, const cClientHandle * a_Exclude = nullptr) override;
177  virtual void BroadcastEntityMetadata (const cEntity & a_Entity, const cClientHandle * a_Exclude = nullptr) override;
178  virtual void BroadcastEntityPosition (const cEntity & a_Entity, const cClientHandle * a_Exclude = nullptr) override;
179  void BroadcastEntityProperties (const cEntity & a_Entity);
180  virtual void BroadcastEntityVelocity (const cEntity & a_Entity, const cClientHandle * a_Exclude = nullptr) override;
181  virtual void BroadcastEntityAnimation (const cEntity & a_Entity, EntityAnimation a_Animation, const cClientHandle * a_Exclude = nullptr) override; // tolua_export
182  virtual void BroadcastLeashEntity (const cEntity & a_Entity, const cEntity & a_EntityLeashedTo) override;
183  virtual void BroadcastParticleEffect (const AString & a_ParticleName, Vector3f a_Src, Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, const cClientHandle * a_Exclude = nullptr) override; // Exported in ManualBindings_World.cpp
184  virtual void BroadcastParticleEffect (const AString & a_ParticleName, Vector3f a_Src, Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, std::array<int, 2> a_Data, const cClientHandle * a_Exclude = nullptr) override; // Exported in ManualBindings_World.cpp
185  virtual void BroadcastPlayerListAddPlayer (const cPlayer & a_Player, const cClientHandle * a_Exclude = nullptr) override;
186  virtual void BroadcastPlayerListHeaderFooter (const cCompositeChat & a_Header, const cCompositeChat & a_Footer) override; // tolua_export
187  virtual void BroadcastPlayerListRemovePlayer (const cPlayer & a_Player, const cClientHandle * a_Exclude = nullptr) override;
188  virtual void BroadcastPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName, const cClientHandle * a_Exclude = nullptr) override;
189  virtual void BroadcastPlayerListUpdateGameMode (const cPlayer & a_Player, const cClientHandle * a_Exclude = nullptr) override;
190  virtual void BroadcastPlayerListUpdatePing () override;
191  virtual void BroadcastRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID, const cClientHandle * a_Exclude = nullptr) override;
192  virtual void BroadcastScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) override;
193  virtual void BroadcastScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) override;
194  virtual void BroadcastDisplayObjective (const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) override;
195  virtual void BroadcastSoundEffect (const AString & a_SoundName, Vector3d a_Position, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = nullptr) override; // Exported in ManualBindings_World.cpp
196  virtual void BroadcastSoundParticleEffect (const EffectID a_EffectID, Vector3i a_SrcPos, int a_Data, const cClientHandle * a_Exclude = nullptr) override; // Exported in ManualBindings_World.cpp
197  virtual void BroadcastSpawnEntity (cEntity & a_Entity, const cClientHandle * a_Exclude = nullptr) override;
198  virtual void BroadcastThunderbolt (Vector3i a_BlockPos, const cClientHandle * a_Exclude = nullptr) override;
199  virtual void BroadcastTimeUpdate (const cClientHandle * a_Exclude = nullptr) override;
200  virtual void BroadcastUnleashEntity (const cEntity & a_Entity) override;
201  virtual void BroadcastWeather (eWeather a_Weather, const cClientHandle * a_Exclude = nullptr) override;
202 
203  virtual cBroadcastInterface & GetBroadcastManager(void) override
204  {
205  return *this;
206  }
207 
209  void SendBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cClientHandle & a_Client);
210 
211  void MarkChunkDirty (int a_ChunkX, int a_ChunkZ);
212  void MarkChunkSaving(int a_ChunkX, int a_ChunkZ);
213  void MarkChunkSaved (int a_ChunkX, int a_ChunkZ);
214 
217  void QueueSetChunkData(SetChunkData && a_SetChunkData);
218 
219  void ChunkLighted(
220  int a_ChunkX, int a_ChunkZ,
221  const cChunkDef::BlockNibbles & a_BlockLight,
222  const cChunkDef::BlockNibbles & a_SkyLight
223  );
224 
227  bool GetChunkData(cChunkCoords a_Coords, cChunkDataCallback & a_Callback) const;
228 
230  bool IsChunkQueued(int a_ChunkX, int a_ChunkZ) const;
231 
233  bool IsChunkValid(int a_ChunkX, int a_ChunkZ) const;
234 
235  bool HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) const;
236 
238  void QueueUnloadUnusedChunks(void); // tolua_export
239 
240  void CollectPickupsByEntity(cEntity & a_Entity);
241 
243  virtual bool ForEachPlayer(cPlayerListCallback a_Callback) override; // >> EXPORTED IN MANUALBINDINGS <<
244 
247  bool DoWithPlayer(const AString & a_PlayerName, cPlayerListCallback a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
248 
250  bool FindAndDoWithPlayer(const AString & a_PlayerNameHint, cPlayerListCallback a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
251 
253  bool DoWithNearestPlayer(Vector3d a_Pos, double a_RangeLimit, cPlayerListCallback a_Callback, bool a_CheckLineOfSight = true, bool a_IgnoreSpectator = true);
254 
256  bool DoWithPlayerByUUID(const cUUID & a_PlayerUUID, cPlayerListCallback a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
257 
258  void SendPlayerList(cPlayer * a_DestPlayer); // Sends playerlist to the player
259 
263  void AddEntity(OwnedEntity a_Entity, cWorld * a_OldWorld = nullptr);
264 
267  OwnedEntity RemoveEntity(cEntity & a_Entity);
268 
270  bool ForEachEntity(cEntityCallback a_Callback); // Exported in ManualBindings.cpp
271 
273  bool ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback a_Callback); // Exported in ManualBindings.cpp
274 
278  virtual bool ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback a_Callback) override; // Exported in ManualBindings.cpp
279 
281  size_t GetPlayerCount() const;
282 
285  bool DoWithEntityByID(UInt32 a_UniqueID, cEntityCallback a_Callback); // Exported in ManualBindings.cpp
286 
288  void CompareChunkClients(int a_ChunkX1, int a_ChunkZ1, int a_ChunkX2, int a_ChunkZ2, cClientDiffCallback & a_Callback);
289 
291  bool AddChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client);
292 
294  void RemoveChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client);
295 
297  void RemoveClientFromChunks(cClientHandle * a_Client);
298 
301  void SendChunkTo(int a_ChunkX, int a_ChunkZ, cChunkSender::Priority a_Priority, cClientHandle * a_Client);
302 
305  void ForceSendChunkTo(int a_ChunkX, int a_ChunkZ, cChunkSender::Priority a_Priority, cClientHandle * a_Client);
306 
311  void PrepareChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptr<cChunkCoordCallback> a_CallAfter = {});
312 
314  void ChunkLoadFailed(int a_ChunkX, int a_ChunkZ);
315 
317  bool SetSignLines(Vector3i a_BlockPos, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player = nullptr); // Exported in ManualBindings.cpp
318 
320  bool SetCommandBlockCommand(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Command); // tolua_export
321  bool SetCommandBlockCommand(Vector3i a_BlockPos, const AString & a_Command)
322  {
323  return SetCommandBlockCommand(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, a_Command);
324  }
325 
327  bool IsTrapdoorOpen(int a_BlockX, int a_BlockY, int a_BlockZ); // tolua_export
328 
330  bool SetTrapdoorOpen(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_Open); // tolua_export
331 
333  void RegenerateChunk(int a_ChunkX, int a_ChunkZ); // tolua_export
334 
336  void GenerateChunk(int a_ChunkX, int a_ChunkZ); // tolua_export
337 
339  void QueueLightChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptr<cChunkCoordCallback> a_Callback = {});
340 
341  bool IsChunkLighted(int a_ChunkX, int a_ChunkZ);
342 
344  virtual bool ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ, cChunkDataCallback & a_Callback) override;
345 
347  bool ForEachLoadedChunk(cFunctionRef<bool(int, int)> a_Callback);
348 
351  void SetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
352 
356  void FastSetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
357  {
358  m_ChunkMap.FastSetBlock(a_BlockPos, a_BlockType, a_BlockMeta);
359  }
360 
363  BLOCKTYPE GetBlock(Vector3i a_BlockPos) const
364  {
365  return m_ChunkMap.GetBlock(a_BlockPos);
366  }
367 
370  NIBBLETYPE GetBlockMeta(Vector3i a_BlockPos) const
371  {
372  return m_ChunkMap.GetBlockMeta(a_BlockPos);
373  }
374 
377  void SetBlockMeta(Vector3i a_BlockPos, NIBBLETYPE a_MetaData);
378 
382  NIBBLETYPE GetBlockSkyLight(Vector3i a_BlockPos) const;
383 
386  NIBBLETYPE GetBlockBlockLight(Vector3i a_BlockPos) const;
387 
392  bool GetBlockTypeMeta(Vector3i a_BlockPos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const;
393 
397  bool GetBlockInfo(Vector3i a_BlockPos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight) const;
398 
399  // TODO: NIBBLETYPE GetBlockActualLight(int a_BlockX, int a_BlockY, int a_BlockZ);
400 
406  virtual bool WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes) override;
407 
408  // tolua_begin
409 
413  void SpawnItemPickups(const cItems & a_Pickups, Vector3i a_BlockPos, double a_FlyAwaySpeed = 1.0, bool a_IsPlayerCreated = false);
414 
417  void SpawnItemPickups(const cItems & a_Pickups, Vector3d a_Pos, double a_FlyAwaySpeed = 1.0, bool a_IsPlayerCreated = false);
418 
422  virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed = 1.0, bool a_IsPlayerCreated = false) override
423  {
424  return SpawnItemPickups(a_Pickups, Vector3d{a_BlockX, a_BlockY, a_BlockZ}, a_FlyAwaySpeed, a_IsPlayerCreated);
425  }
426 
428  void SpawnItemPickups(const cItems & a_Pickups, Vector3d a_Pos, Vector3d a_Speed, bool a_IsPlayerCreated = false);
429 
432  virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_SpeedX, double a_SpeedY, double a_SpeedZ, bool a_IsPlayerCreated = false) override
433  {
434  return SpawnItemPickups(a_Pickups, {a_BlockX, a_BlockY, a_BlockZ}, {a_SpeedX, a_SpeedY, a_SpeedZ}, a_IsPlayerCreated);
435  }
436 
438  UInt32 SpawnItemPickup(Vector3d a_Pos, const cItem & a_Item, Vector3f a_Speed, int a_LifetimeTicks = 6000, bool a_CanCombine = true);
439 
442  virtual UInt32 SpawnItemPickup(double a_PosX, double a_PosY, double a_PosZ, const cItem & a_Item, float a_SpeedX = 0.f, float a_SpeedY = 0.f, float a_SpeedZ = 0.f, int a_LifetimeTicks = 6000, bool a_CanCombine = true) override
443  {
444  return SpawnItemPickup({a_PosX, a_PosY, a_PosZ}, a_Item, {a_SpeedX, a_SpeedY, a_SpeedZ}, a_LifetimeTicks, a_CanCombine);
445  }
446 
449  UInt32 SpawnFallingBlock(Vector3d a_Pos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
450 
453  UInt32 SpawnFallingBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
454  {
455  // When creating from a block position (Vector3i), move the spawn point to the middle of the block by adding (0.5, 0, 0.5)
456  return SpawnFallingBlock(Vector3d(0.5, 0, 0.5) + a_BlockPos, a_BlockType, a_BlockMeta);
457  }
458 
462  UInt32 SpawnFallingBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
463  {
464  return SpawnFallingBlock(Vector3i{a_X, a_Y, a_Z}, a_BlockType, a_BlockMeta);
465  }
466 
469  UInt32 SpawnMinecart(Vector3d a_Pos, int a_MinecartType, const cItem & a_Content = cItem(), int a_BlockHeight = 1);
470 
474  UInt32 SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartType, const cItem & a_Content = cItem(), int a_BlockHeight = 1)
475  {
476  return SpawnMinecart({a_X, a_Y, a_Z}, a_MinecartType, a_Content, a_BlockHeight);
477  }
478 
479  // DEPRECATED, use the vector-parametered version instead.
480  UInt32 SpawnBoat(double a_X, double a_Y, double a_Z, cBoat::eMaterial a_Material)
481  {
482  LOGWARNING("cWorld::SpawnBoat(double, double, double) is deprecated, use cWorld::SpawnBoat(Vector3d) instead.");
483  return SpawnBoat({a_X, a_Y, a_Z}, a_Material);
484  }
485 
488  UInt32 SpawnBoat(Vector3d a_Pos, cBoat::eMaterial a_Material);
489 
492  UInt32 SpawnExperienceOrb(Vector3d a_Pos, int a_Reward);
493 
497  virtual UInt32 SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward) override
498  {
499  return SpawnExperienceOrb({a_X, a_Y, a_Z}, a_Reward);
500  }
501 
502  // tolua_end
503 
506  virtual std::vector<UInt32> SpawnSplitExperienceOrbs(Vector3d a_Pos, int a_Reward) override; // Exported in ManualBindings_World.cpp
507 
511  std::vector<UInt32> SpawnSplitExperienceOrbs(double a_X, double a_Y, double a_Z, int a_Reward)
512  {
513  return SpawnSplitExperienceOrbs({a_X, a_Y, a_Z}, a_Reward);
514  }
515 
516  // tolua_begin
517 
518  // DEPRECATED, use the vector-parametered version instead.
519  UInt32 SpawnPrimedTNT(double a_X, double a_Y, double a_Z, int a_FuseTimeInSec = 80, double a_InitialVelocityCoeff = 1, bool a_ShouldPlayFuseSound = true)
520  {
521  LOGWARNING("cWorld::SpawnPrimedTNT(double, double, double) is deprecated, use cWorld::SpawnPrimedTNT(Vector3d) instead.");
522  return SpawnPrimedTNT({a_X, a_Y, a_Z}, a_FuseTimeInSec, a_InitialVelocityCoeff, a_ShouldPlayFuseSound);
523  }
524 
528  UInt32 SpawnPrimedTNT(Vector3d a_Pos, int a_FuseTimeInSec = 80, double a_InitialVelocityCoeff = 1, bool a_ShouldPlayFuseSound = true);
529 
532  UInt32 SpawnEnderCrystal(Vector3d a_Pos, bool a_ShowBottom);
533 
534  // tolua_end
535 
539  void PlaceBlock(const Vector3i a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta);
540 
542  bool GetBlocks(sSetBlockVector & a_Blocks, bool a_ContinueOnFailure);
543 
545 
546  // tolua_begin
547 
551  bool DigBlock(Vector3i a_BlockPos, const cEntity * a_Digger = nullptr);
552 
558  bool DigBlock(int a_X, int a_Y, int a_Z, cEntity * a_Digger = nullptr)
559  {
560  return DigBlock({a_X, a_Y, a_Z}, a_Digger);
561  }
562 
568  bool DropBlockAsPickups(Vector3i a_BlockPos, const cEntity * a_Digger = nullptr, const cItem * a_Tool = nullptr);
569 
575  cItems PickupsFromBlock(Vector3i a_BlockPos, const cEntity * a_Digger = nullptr, const cItem * a_Tool = nullptr);
576 
579  virtual void SendBlockTo(int a_X, int a_Y, int a_Z, const cPlayer & a_Player) override;
580 
583  bool SetSpawn(int a_X, int a_Y, int a_Z);
584 
585  int GetSpawnX(void) const { return m_SpawnX; }
586  int GetSpawnY(void) const { return m_SpawnY; }
587  int GetSpawnZ(void) const { return m_SpawnZ; }
588 
590  virtual void WakeUpSimulators(Vector3i a_Block) override;
591 
593  void WakeUpSimulatorsInArea(const cCuboid & a_Area);
594 
595  // tolua_end
596 
598 
602 
604  bool ForEachBlockEntityInChunk(int a_ChunkX, int a_ChunkZ, cBlockEntityCallback a_Callback); // Exported in ManualBindings.cpp
605 
610  virtual void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void * a_SourceData) override;
611 
613  virtual bool DoWithBlockEntityAt(Vector3i a_Position, cBlockEntityCallback a_Callback) override; // Exported in ManualBindings.cpp
614 
616  bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Exported in ManualBindings.cpp
617 
619  void UseBlockEntity(cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) { m_ChunkMap.UseBlockEntity(a_Player, a_BlockX, a_BlockY, a_BlockZ); } // tolua_export
620 
623  bool DoWithChunk(int a_ChunkX, int a_ChunkZ, cChunkCallback a_Callback);
624 
627  bool DoWithChunkAt(Vector3i a_BlockPos, cChunkCallback a_Callback);
628 
632  bool GrowTreeImage(const sSetBlockVector & a_Blocks);
633 
639  bool GrowTree(Vector3i a_BlockPos);
640 
645  bool GrowTreeFromSapling(Vector3i a_BlockPos);
646 
650  bool GrowTreeByBiome(Vector3i a_BlockPos);
651 
652  // tolua_begin
653 
657  int GrowPlantAt(Vector3i a_BlockPos, int a_NumStages = 1);
658 
661  bool GrowRipePlant(Vector3i a_BlockPos);
662 
667  bool GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsByBonemeal = false)
668  {
669  UNUSED(a_IsByBonemeal);
670  LOGWARNING("Warning: cWorld:GrowRipePlant function expects Vector3i-based coords rather than int-based coords. Emulating old-style call.");
671  return GrowRipePlant({ a_BlockX, a_BlockY, a_BlockZ });
672  }
673 
675  EMCSBiome GetBiomeAt(int a_BlockX, int a_BlockZ);
676 
679  bool SetBiomeAt(int a_BlockX, int a_BlockZ, EMCSBiome a_Biome);
680 
683  bool SetAreaBiome(int a_MinX, int a_MaxX, int a_MinZ, int a_MaxZ, EMCSBiome a_Biome);
684 
688  bool SetAreaBiome(const cCuboid & a_Area, EMCSBiome a_Biome);
689 
691  const AString & GetName(void) const { return m_WorldName; }
692 
694  const AString & GetDataPath(void) const { return m_DataPath; }
695 
697  const AString & GetIniFileName(void) const {return m_IniFileName; }
698 
701 
704 
706  void SetCommandBlocksEnabled(bool a_Flag) { m_bCommandBlocksEnabled = a_Flag; }
707 
710 
711  int GetMaxViewDistance(void) const { return m_MaxViewDistance; }
712  void SetMaxViewDistance(int a_MaxViewDistance);
713 
714  bool ShouldUseChatPrefixes(void) const { return m_bUseChatPrefixes; }
715  void SetShouldUseChatPrefixes(bool a_Flag) { m_bUseChatPrefixes = a_Flag; }
716 
719 
720 
722  void SetLinkedNetherWorldName(const AString & a_Name) { m_LinkedNetherWorldName = a_Name; }
723 
725  void SetLinkedEndWorldName(const AString & a_Name) { m_LinkedEndWorldName = a_Name; }
726 
728  void SetLinkedOverworldName(const AString & a_Name) { m_LinkedOverworldName = a_Name; }
729 
731  virtual int GetMinNetherPortalWidth(void) const override { return m_MinNetherPortalWidth; }
732  virtual int GetMaxNetherPortalWidth(void) const override { return m_MaxNetherPortalWidth; }
733  virtual void SetMinNetherPortalWidth(int a_NewMinWidth) override { m_MinNetherPortalWidth = a_NewMinWidth; }
734  virtual void SetMaxNetherPortalWidth(int a_NewMaxWidth) override { m_MaxNetherPortalWidth = a_NewMaxWidth; }
735 
737  virtual int GetMinNetherPortalHeight(void) const override { return m_MinNetherPortalHeight; }
738  virtual int GetMaxNetherPortalHeight(void) const override { return m_MaxNetherPortalHeight; }
739  virtual void SetMinNetherPortalHeight(int a_NewMinHeight) override { m_MinNetherPortalHeight = a_NewMinHeight; }
740  virtual void SetMaxNetherPortalHeight(int a_NewMaxHeight) override { m_MaxNetherPortalHeight = a_NewMaxHeight; }
741 
742  // tolua_end
743 
745  void SaveAllChunks(void);
746 
748  void QueueSaveAllChunks(void); // tolua_export
749 
751  void QueueTask(std::function<void(cWorld &)> a_Task); // Exported in ManualBindings.cpp
752 
754  void ScheduleTask(cTickTime a_DelayTicks, std::function<void(cWorld &)> a_Task);
755 
757  size_t GetNumChunks() const; // tolua_export
758 
760  size_t GetNumUnusedDirtyChunks(void) const; // tolua_export
761 
763  void GetChunkStats(int & a_NumValid, int & a_NumDirty, int & a_NumInLightingQueue);
764 
765  // Various queues length queries (cannot be const, they lock their CS):
766  inline size_t GetGeneratorQueueLength (void) { return m_Generator.GetQueueLength(); } // tolua_export
767  inline size_t GetLightingQueueLength (void) { return m_Lighting.GetQueueLength(); } // tolua_export
768  inline size_t GetStorageLoadQueueLength(void) { return m_Storage.GetLoadQueueLength(); } // tolua_export
769  inline size_t GetStorageSaveQueueLength(void) { return m_Storage.GetSaveQueueLength(); } // tolua_export
770 
772 
773  void InitializeSpawn(void);
774 
776  void Start();
777 
780  void Stop(cDeadlockDetect & a_DeadlockDetect);
781 
783  void TickQueuedBlocks(void);
784 
786  {
787  int X;
788  int Y;
789  int Z;
791  };
792 
794  void QueueBlockForTick(int a_BlockX, int a_BlockY, int a_BlockZ, int a_TicksToWait); // tolua_export
795 
796  // tolua_begin
798  void CastThunderbolt(Vector3i a_Block);
799  void CastThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ); // DEPRECATED, use vector-parametered version instead
800 
802  void SetWeather(eWeather a_NewWeather);
803 
805  void ChangeWeather(void);
806 
808  eWeather GetWeather(void) const { return m_Weather; }
809 
811  bool IsWeatherSunny(void) const { return (m_Weather == wSunny); }
812 
814  bool IsWeatherSunnyAt(int a_BlockX, int a_BlockZ) const;
815 
817  bool IsWeatherRain(void) const { return (m_Weather == wRain); }
818 
820  bool IsWeatherRainAt(int a_BlockX, int a_BlockZ)
821  {
822  return (IsWeatherRain() && !IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ)));
823  }
824 
826  bool IsWeatherStorm(void) const { return (m_Weather == wStorm); }
827 
829  bool IsWeatherStormAt(int a_BlockX, int a_BlockZ)
830  {
831  return (IsWeatherStorm() && !IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ)));
832  }
833 
835  bool IsWeatherWet(void) const { return !IsWeatherSunny(); }
836 
839  virtual bool IsWeatherWetAt(int a_BlockX, int a_BlockZ) override;
840 
843  virtual bool IsWeatherWetAtXYZ(Vector3i a_Position) override;
844 
846  int GetSeed(void) const { return m_Generator.GetSeed(); }
847 
848  // tolua_end
849 
851  cWorldStorage & GetStorage (void) { return m_Storage; }
852  cChunkMap * GetChunkMap (void) { return &m_ChunkMap; }
853 
856  void SetNextBlockToTick(const Vector3i a_BlockPos); // tolua_export
857 
858  int GetMaxSugarcaneHeight(void) const { return m_MaxSugarcaneHeight; } // tolua_export
859  int GetMaxCactusHeight (void) const { return m_MaxCactusHeight; } // tolua_export
860 
861  bool IsBlockDirectlyWatered(int a_BlockX, int a_BlockY, int a_BlockZ); // tolua_export
862 
864  virtual UInt32 SpawnMob(double a_PosX, double a_PosY, double a_PosZ, eMonsterType a_MonsterType, bool a_Baby = false) override; // tolua_export
865 
868  UInt32 SpawnMobFinalize(std::unique_ptr<cMonster> a_Monster);
869 
872  UInt32 CreateProjectile(Vector3d a_Pos, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const cItem * a_Item, const Vector3d * a_Speed = nullptr); // tolua_export
873 
877  UInt32 CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const cItem * a_Item, const Vector3d * a_Speed = nullptr); // tolua_export
878 
880  int GetTickRandomNumber(int a_Range);
881 
883  void TabCompleteUserName(const AString & a_Text, AStringVector & a_Results);
884 
887 
893  void SetChunkAlwaysTicked(int a_ChunkX, int a_ChunkZ, bool a_AlwaysTicked = true); // tolua_export
894 
896  bool IsSlimeChunk(int a_ChunkX, int a_ChunkZ) const; // tolua_export
897 private:
898 
899  class cTickThread:
900  public cIsThread
901  {
902  using Super = cIsThread;
903 
904  public:
905 
906  cTickThread(cWorld & a_World);
907 
908  protected:
910 
911  // cIsThread overrides:
912  virtual void Execute(void) override;
913  } ;
914 
915 
916 
921  {
923 
924  // cChunkSink overrides:
925  virtual void OnChunkGenerated (cChunkDesc & a_ChunkDesc) override;
926  virtual bool IsChunkValid (cChunkCoords a_Coords) override;
927  virtual bool HasChunkAnyClients(cChunkCoords a_Coords) override;
928  virtual bool IsChunkQueued (cChunkCoords a_Coords) override;
929 
930  // cPluginInterface overrides:
931  virtual void CallHookChunkGenerating(cChunkDesc & a_ChunkDesc) override;
932  virtual void CallHookChunkGenerated (cChunkDesc & a_ChunkDesc) override;
933 
934  public:
935  cChunkGeneratorCallbacks(cWorld & a_World);
936  } ;
937 
938 
943 
945 
948 
952 
954 
957 
959 
961  std::atomic<bool> m_IsSavingEnabled;
962 
965 
967  int m_SpawnX;
968  int m_SpawnY;
969  int m_SpawnZ;
970 
971  // Variables defining the minimum and maximum size for a nether portal
976 
979 
981 
985  std::chrono::milliseconds m_WorldAge;
986 
990  std::chrono::milliseconds m_WorldDate;
991 
996 
997  std::chrono::milliseconds m_LastChunkCheck; // The last WorldAge in which unloading and possibly saving was triggered.
998  std::chrono::milliseconds m_LastSave; // The last WorldAge in which save-all was triggerred.
999  std::map<cMonster::eFamily, cTickTimeLong> m_LastSpawnMonster; // The last WorldAge (in ticks) in which a monster was spawned (for each megatype of monster) // MG TODO : find a way to optimize without creating unmaintenability (if mob IDs are becoming unrowed)
1000 
1002 
1009 
1010  std::vector<BlockTickQueueItem *> m_BlockTickQueue;
1011  std::vector<BlockTickQueueItem *> m_BlockTickQueueCopy; // Second is for safely removing the objects from the queue
1012 
1013  std::unique_ptr<cSimulatorManager> m_SimulatorManager;
1014  std::unique_ptr<cSandSimulator> m_SandSimulator;
1017  std::unique_ptr<cFireSimulator> m_FireSimulator;
1019 
1020  // Protect with chunk map CS
1021  std::vector<cPlayer *> m_Players;
1022 
1024 
1025  unsigned int m_MaxPlayers;
1026 
1028 
1030  std::set<eMonsterType> m_AllowedMobs;
1031 
1037 
1040  /* TODO: Enable when functionality exists again
1041  bool m_IsBeetrootsBonemealable;
1042  bool m_IsCactusBonemealable;
1043  bool m_IsCarrotsBonemealable;
1044  bool m_IsCropsBonemealable;
1045  bool m_IsGrassBonemealable;
1046  bool m_IsMelonStemBonemealable;
1047  bool m_IsMelonBonemealable;
1048  bool m_IsPotatoesBonemealable;
1049  bool m_IsPumpkinStemBonemealable;
1050  bool m_IsPumpkinBonemealable;
1051  bool m_IsSaplingBonemealable;
1052  bool m_IsSugarcaneBonemealable;
1053  bool m_IsBigFlowerBonemealable;
1054  bool m_IsTallGrassBonemealable;
1055  */
1056 
1059 
1062 
1067 
1070 
1074 
1078 
1081 
1084 
1087 
1091 
1094 
1096  std::vector<std::pair<std::chrono::milliseconds, std::function<void(cWorld &)>>> m_Tasks;
1097 
1100 
1102  std::vector<std::pair<OwnedEntity, cWorld *>> m_EntitiesToAdd;
1103 
1106 
1108  std::vector<SetChunkData> m_SetChunkDataQueue;
1109 
1110  void Tick(std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_LastTickDurationMSec);
1111 
1113  void TickClients(std::chrono::milliseconds a_Dt);
1114 
1116  void TickWeather(float a_Dt);
1117 
1119  void TickMobs(std::chrono::milliseconds a_Dt);
1120 
1122  void TickQueuedChunkDataSets();
1123 
1126  void TickQueuedEntityAdditions(void);
1127 
1129  void TickQueuedTasks(void);
1130 
1132  void UnloadUnusedChunks(void);
1133 
1134  void UpdateSkyDarkness(void);
1135 
1137  void GenerateRandomSpawn(int a_MaxSpawnRadius);
1138 
1141  bool CanSpawnAt(int a_X, int & a_Y, int a_Z);
1142 
1144  bool CheckPlayerSpawnPoint(int a_PosX, int a_PosY, int a_PosZ)
1145  {
1146  return CheckPlayerSpawnPoint({a_PosX, a_PosY, a_PosZ});
1147  }
1148  bool CheckPlayerSpawnPoint(Vector3i a_Pos);
1149 
1151  eWeather ChooseNewWeather(void);
1152 
1154  cFluidSimulator * InitializeFluidSimulator(cIniFile & a_IniFile, const char * a_FluidName, BLOCKTYPE a_SimulateBlock, BLOCKTYPE a_StationaryBlock);
1155 
1158 
1160  void InitializeAndLoadMobSpawningValues(cIniFile & a_IniFile);
1161 
1165  bool GetLargeTreeAdjustment(Vector3i & a_BlockPos, NIBBLETYPE a_SaplingMeta);
1166 }; // tolua_export
bool IsBiomeNoDownfall(EMCSBiome a_Biome)
Returns true if the biome has no downfall - deserts and savannas.
Definition: BiomeDef.cpp:142
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
Definition: BiomeDef.h:18
std::vector< sSetBlock > sSetBlockVector
Definition: ChunkDef.h:441
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
std::unique_ptr< cEntity > OwnedEntity
Definition: ChunkDef.h:32
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
eWeather
Definition: Defines.h:160
@ wRain
Definition: Defines.h:167
@ wStorm
Definition: Defines.h:169
@ wSunny
Definition: Defines.h:166
EntityAnimation
Definition: Defines.h:458
eDimension
Dimension of a world.
Definition: Defines.h:231
@ dimOverworld
Definition: Defines.h:233
eGameMode
Definition: Defines.h:125
@ gmCreative
Definition: Defines.h:135
@ gmAdventure
Definition: Defines.h:136
@ gmSurvival
Definition: Defines.h:134
@ gmSpectator
Definition: Defines.h:137
eExplosionSource
The source of an explosion.
Definition: Defines.h:309
eMessageType
Definition: Defines.h:352
@ mtWarning
Definition: Defines.h:360
@ mtSuccess
Definition: Defines.h:359
@ mtCustom
Definition: Defines.h:356
@ mtInformation
Definition: Defines.h:358
@ mtDeath
Definition: Defines.h:362
@ mtFailure
Definition: Defines.h:357
eShrapnelLevel
Definition: Defines.h:328
EffectID
Definition: EffectID.h:6
std::chrono::duration< signed long long int, cTickTime::period > cTickTimeLong
Definition: Globals.h:367
unsigned int UInt32
Definition: Globals.h:157
signed char Int8
Definition: Globals.h:154
std::chrono::duration< signed int, std::ratio_multiply< std::chrono::milliseconds::period, std::ratio< 50 > >> cTickTime
Definition: Globals.h:364
#define UNUSED
Definition: Globals.h:72
unsigned char Byte
Definition: Globals.h:161
void LOGWARNING(std::string_view a_Format, const Args &... args)
Definition: LoggerSimple.h:67
eMonsterType
Identifies individual monster type.
Definition: MonsterTypes.h:11
std::vector< AString > AStringVector
Definition: StringUtils.h:12
std::string AString
Definition: StringUtils.h:11
Vector3< double > Vector3d
Definition: Vector3.h:485
virtual void SendBlockTo(int a_BlockX, int a_BlockY, int a_BlockZ, const cPlayer &a_Player)=0
Sends the block on those coords to the player.
Represents two sets of coords, minimum and maximum for each direction.
Definition: BoundingBox.h:24
Wraps the chunk coords into a single structure.
Definition: ChunkDef.h:57
NIBBLETYPE BlockNibbles[NumBlocks/2]
The type used for block data in nibble format, AXIS_ORDER ordering.
Definition: ChunkDef.h:143
Interface class used for comparing clients of two chunks.
Definition: ChunkDef.h:370
Takes requests for generating chunks and processes them in a separate thread one by one.
The interface through which the plugins are called for their OnChunkGenerating / OnChunkGenerated hoo...
The interface through which the generated chunks are handed to the cWorld or whoever created us.
BLOCKTYPE GetBlock(Vector3i a_BlockPos) const
Definition: ChunkMap.cpp:475
NIBBLETYPE GetBlockMeta(Vector3i a_BlockPos) const
Definition: ChunkMap.cpp:494
bool UseBlockEntity(cPlayer *a_Player, int a_X, int a_Y, int a_Z)
a_Player rclked block entity at the coords specified, handle it returns true if the use was successfu...
Definition: ChunkMap.cpp:110
void FastSetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Sets the block at the specified coords to the specified value.
Definition: ChunkMap.cpp:425
Priority
Tag indicating urgency of chunk to be sent.
Definition: ChunkSender.h:64
Container for a single chat message composed of multiple functional parts.
Definition: CompositeChat.h:34
Definition: Cuboid.h:10
eMaterial
Definition: Boat.h:29
Definition: Entity.h:76
Definition: Player.h:29
eKind
The kind of the projectile.
The interface that all chunk generators must implement to provide the generated chunks.
Definition: Item.h:37
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215
size_t GetQueueLength(void)
Manages the in-game maps of a single world - Thread safe.
Definition: MapManager.h:29
RAII for cCriticalSection - locks the CS on creation, unlocks on destruction.
cCSLock(cCriticalSection *a_CS)
cIsThread(AString &&a_ThreadName)
Definition: IsThread.cpp:16
Contains the data for a loaded / generated chunk, ready to be set into a cWorld.
Definition: SetChunkData.h:12
The fire simulator takes care of the fire blocks.
Definition: FireSimulator.h:20
Despite the class name, this simulator takes care of all blocks that fall when suspended in the air.
Definition: SandSimulator.h:28
Definition: UUID.h:11
T x
Definition: Vector3.h:17
T y
Definition: Vector3.h:17
T z
Definition: Vector3.h:17
Definition: World.h:53
bool TryGetHeight(int a_BlockX, int a_BlockZ, int &a_Height)
Retrieves the world height at the specified coords; returns false if chunk not loaded / generated.
Definition: World.cpp:2132
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).
Definition: World.cpp:2694
bool ShouldUseChatPrefixes(void) const
Definition: World.h:714
cRedstoneSimulator * InitializeRedstoneSimulator(cIniFile &a_IniFile)
Creates a new redstone simulator.
Definition: World.cpp:3046
bool IsSlimeChunk(int a_ChunkX, int a_ChunkZ) const
Returns true if slimes should spawn in the chunk.
Definition: World.cpp:3235
virtual void BroadcastUnleashEntity(const cEntity &a_Entity) override
bool IsWeatherSunny(void) const
Returns true if the current weather is sunny.
Definition: World.h:811
cChunkGeneratorThread & GetGenerator(void)
Definition: World.h:850
virtual void BroadcastScoreboardObjective(const AString &a_Name, const AString &a_DisplayName, Byte a_Mode) override
void ScheduleTask(cTickTime a_DelayTicks, std::function< void(cWorld &)> a_Task)
Queues a lambda task onto the tick thread, with the specified delay.
Definition: World.cpp:2744
cWorldStorage m_Storage
Definition: World.h:1023
int GetSeed(void) const
Returns the seed of the world.
Definition: World.h:846
std::vector< std::pair< std::chrono::milliseconds, std::function< void(cWorld &)> > > m_Tasks
Tasks that have been queued onto the tick thread, possibly to be executed at target tick in the futur...
Definition: World.h:1096
void MarkChunkDirty(int a_ChunkX, int a_ChunkZ)
Definition: World.cpp:2150
bool DropBlockAsPickups(Vector3i a_BlockPos, const cEntity *a_Digger=nullptr, const cItem *a_Tool=nullptr)
Digs the specified block, and spawns the appropriate pickups for it.
Definition: World.cpp:2090
virtual void BroadcastThunderbolt(Vector3i a_BlockPos, const cClientHandle *a_Exclude=nullptr) override
bool m_bCommandBlocksEnabled
Whether command blocks are enabled or not.
Definition: World.h:1058
UInt32 SpawnMobFinalize(std::unique_ptr< cMonster > a_Monster)
Wraps cEntity::Initialize, doing Monster-specific things before spawning the monster.
Definition: World.cpp:2918
void ChunkLoadFailed(int a_ChunkX, int a_ChunkZ)
Marks the chunk as failed-to-load:
Definition: World.cpp:2551
void TickMobs(std::chrono::milliseconds a_Dt)
Handles the mob spawning / moving / destroying each tick.
Definition: World.cpp:1122
cScoreboard & GetScoreBoard(void)
Returns the associated scoreboard instance.
Definition: World.h:700
UInt32 SpawnItemPickup(Vector3d a_Pos, const cItem &a_Item, Vector3f a_Speed, int a_LifetimeTicks=6000, bool a_CanCombine=true)
Spawns a single pickup containing the specified item.
Definition: World.cpp:1863
cChunkSender m_ChunkSender
Definition: World.h:1088
virtual void BroadcastPlayerListUpdateGameMode(const cPlayer &a_Player, const cClientHandle *a_Exclude=nullptr) override
bool ShouldLavaSpawnFire(void) const
Definition: World.h:129
void BroadcastEntityProperties(const cEntity &a_Entity)
UInt32 SpawnPrimedTNT(double a_X, double a_Y, double a_Z, int a_FuseTimeInSec=80, double a_InitialVelocityCoeff=1, bool a_ShouldPlayFuseSound=true)
Definition: World.h:519
int GetTicksUntilWeatherChange(void) const
Definition: World.h:86
bool IsGameModeSpectator(void) const
Returns true if the world is in Spectator mode.
Definition: World.h:120
bool IsSavingEnabled(void) const
Get whether saving chunks is enabled.
Definition: World.h:81
virtual ~cWorld() override
Definition: World.cpp:449
void RemoveClientFromChunks(cClientHandle *a_Client)
Removes the client from all chunks it is present in.
Definition: World.cpp:2514
bool CheckPlayerSpawnPoint(int a_PosX, int a_PosY, int a_PosZ)
Check if player starting point is acceptable.
Definition: World.h:1144
eShrapnelLevel m_TNTShrapnelLevel
The level of DoExplosionAt() projecting random affected blocks as FallingBlock entities See the eShra...
Definition: World.h:1066
bool DoWithPlayerByUUID(const cUUID &a_PlayerUUID, cPlayerListCallback a_Callback)
Finds the player over his uuid and calls the callback.
Definition: World.cpp:2339
virtual void BroadcastChatDeath(const AString &a_Message, const cClientHandle *a_Exclude=nullptr) override
Definition: World.h:166
cFluidSimulator * GetWaterSimulator(void)
Definition: World.h:599
void AddEntity(OwnedEntity a_Entity, cWorld *a_OldWorld=nullptr)
Adds the entity into its appropriate chunk; takes ownership of the entity ptr.
Definition: World.cpp:2759
UInt32 SpawnExperienceOrb(Vector3d a_Pos, int a_Reward)
Spawns an experience orb at the given location with the given reward.
Definition: World.cpp:1894
const AString & GetDataPath(void) const
Returns the data path to the world data.
Definition: World.h:694
std::chrono::milliseconds m_WorldDate
The fully controllable age of the world.
Definition: World.h:990
int m_WeatherInterval
Definition: World.h:1033
int GetSpawnX(void) const
Definition: World.h:585
bool IsWeatherRain(void) const
Returns true if the current weather is rainy.
Definition: World.h:817
void UseBlockEntity(cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ)
a_Player is using block entity at [x, y, z], handle that:
Definition: World.h:619
int m_MaxSunnyTicks
Definition: World.h:1034
int m_MinRainTicks
Definition: World.h:1035
std::unique_ptr< cSandSimulator > m_SandSimulator
Definition: World.h:1014
virtual void BroadcastPlayerListUpdatePing() override
bool DoWithChunkAt(Vector3i a_BlockPos, cChunkCallback a_Callback)
Calls the callback for the chunk at the block position specified, with ChunkMapCS locked.
Definition: World.cpp:1460
size_t GetPlayerCount() const
Returns the number of players currently in this world.
Definition: World.cpp:2454
cLightingThread m_Lighting
Definition: World.h:1089
int m_SpawnY
Definition: World.h:968
bool IsGameModeSurvival(void) const
Returns true if the world is in Survival mode.
Definition: World.h:114
virtual void BroadcastTimeUpdate(const cClientHandle *a_Exclude=nullptr) override
void QueueLightChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptr< cChunkCoordCallback > a_Callback={})
Queues a chunk for lighting; a_Callback is called after the chunk is lighted.
Definition: World.cpp:2676
virtual void BroadcastDetachEntity(const cEntity &a_Entity, const cEntity &a_PreviousVehicle) override
int m_MinThunderStormTicks
Definition: World.h:1036
virtual UInt32 SpawnMob(double a_PosX, double a_PosY, double a_PosZ, eMonsterType a_MonsterType, bool a_Baby=false) override
Spawns a mob of the specified type.
Definition: World.cpp:2897
void SetLinkedEndWorldName(const AString &a_Name)
Definition: World.h:725
void RegenerateChunk(int a_ChunkX, int a_ChunkZ)
Regenerate the given chunk.
Definition: World.cpp:2657
void UnloadUnusedChunks(void)
Unloads all chunks immediately.
Definition: World.cpp:2238
virtual void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void *a_SourceData) override
Does an explosion with the specified strength at the specified coordinates.
Definition: World.cpp:1384
std::chrono::milliseconds m_WorldAge
The age of the world.
Definition: World.h:985
std::vector< BlockTickQueueItem * > m_BlockTickQueueCopy
Definition: World.h:1011
bool GetBlockInfo(Vector3i a_BlockPos, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_Meta, NIBBLETYPE &a_SkyLight, NIBBLETYPE &a_BlockLight) const
Queries the whole block specification from the world.
Definition: World.cpp:1788
void QueueSetChunkData(SetChunkData &&a_SetChunkData)
Puts the chunk data into a queue to be set into the chunkmap in the tick thread.
Definition: World.cpp:2177
virtual cBroadcastInterface & GetBroadcastManager(void) override
Definition: World.h:203
void SetLinkedNetherWorldName(const AString &a_Name)
Definition: World.h:722
virtual void BroadcastAttachEntity(const cEntity &a_Entity, const cEntity &a_Vehicle) override
cRedstoneSimulator * m_RedstoneSimulator
Definition: World.h:1018
virtual void BroadcastEntityMetadata(const cEntity &a_Entity, const cClientHandle *a_Exclude=nullptr) override
void TabCompleteUserName(const AString &a_Text, AStringVector &a_Results)
Appends all usernames starting with a_Text (case-insensitive) into Results.
Definition: World.cpp:2987
UInt32 SpawnBoat(double a_X, double a_Y, double a_Z, cBoat::eMaterial a_Material)
Definition: World.h:480
void SetChunkAlwaysTicked(int a_ChunkX, int a_ChunkZ, bool a_AlwaysTicked=true)
Increments (a_AlwaysTicked == true) or decrements (false) the m_AlwaysTicked counter for the specifie...
Definition: World.cpp:3037
bool m_bEnabledPVP
Definition: World.h:1004
virtual void BroadcastChatFailure(const AString &a_Message, const cClientHandle *a_Exclude=nullptr) override
Definition: World.h:162
NIBBLETYPE GetBlockSkyLight(Vector3i a_BlockPos) const
Returns the sky light value at the specified block position.
Definition: World.cpp:1761
virtual void BroadcastChatWarning(const AString &a_Message, const cClientHandle *a_Exclude=nullptr) override
Definition: World.h:164
virtual void BroadcastPlayerListAddPlayer(const cPlayer &a_Player, const cClientHandle *a_Exclude=nullptr) override
bool CanSpawnAt(int a_X, int &a_Y, int a_Z)
Can the specified coordinates be used as a spawn point? Returns true if spawn position is valid and s...
Definition: World.cpp:782
bool IsPVPEnabled(void) const
Definition: World.h:122
virtual void BroadcastEntityAnimation(const cEntity &a_Entity, EntityAnimation a_Animation, const cClientHandle *a_Exclude=nullptr) override
int GrowPlantAt(Vector3i a_BlockPos, int a_NumStages=1)
Grows the plant at the specified position by at most a_NumStages.
Definition: World.cpp:1676
bool GrowRipePlant(Vector3i a_BlockPos)
Grows the plant at the specified block to its ripe stage.
Definition: World.cpp:1685
int GetDefaultWeatherInterval(eWeather a_Weather) const
Returns the default weather interval for the specific weather type.
Definition: World.cpp:531
bool DoWithChunk(int a_ChunkX, int a_ChunkZ, cChunkCallback a_Callback)
Calls the callback for the chunk specified, with ChunkMapCS locked.
Definition: World.cpp:1451
void PrepareChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptr< cChunkCoordCallback > a_CallAfter={})
Queues the chunk for preparing - making sure that it's generated and lit.
Definition: World.cpp:2542
BLOCKTYPE GetBlock(Vector3i a_BlockPos) const
Returns the block type at the specified position.
Definition: World.h:363
bool GetLargeTreeAdjustment(Vector3i &a_BlockPos, NIBBLETYPE a_SaplingMeta)
Checks if the sapling at the specified block coord is a part of a large-tree sapling (2x2).
Definition: World.cpp:1530
bool SetAreaBiome(int a_MinX, int a_MaxX, int a_MinZ, int a_MaxZ, EMCSBiome a_Biome)
Sets the biome at the area.
Definition: World.cpp:1712
eShrapnelLevel GetTNTShrapnelLevel(void) const
Definition: World.h:708
virtual void BroadcastCollectEntity(const cEntity &a_Collected, const cEntity &a_Collector, unsigned a_Count, const cClientHandle *a_Exclude=nullptr) override
void SetSavingEnabled(bool a_IsSavingEnabled)
Set whether saving chunks is enabled.
Definition: World.h:84
virtual void SpawnItemPickups(const cItems &a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed=1.0, bool a_IsPlayerCreated=false) override
OBSOLETE, use the Vector3d-based overload instead.
Definition: World.h:422
int GetTickRandomNumber(int a_Range)
Returns a random number in range [0 .
Definition: World.cpp:2978
void QueueUnloadUnusedChunks(void)
Queues a task to unload unused chunks onto the tick thread.
Definition: World.cpp:2248
int m_MaxNetherPortalHeight
Definition: World.h:975
cCriticalSection m_CSTasks
Guards the m_Tasks.
Definition: World.h:1093
bool IsDeepSnowEnabled(void) const
Definition: World.h:127
virtual cTickTimeLong GetWorldAge(void) const override
Definition: World.cpp:491
virtual UInt32 SpawnItemPickup(double a_PosX, double a_PosY, double a_PosZ, const cItem &a_Item, float a_SpeedX=0.f, float a_SpeedY=0.f, float a_SpeedZ=0.f, int a_LifetimeTicks=6000, bool a_CanCombine=true) override
OBSOLETE, use the Vector3d-based overload instead.
Definition: World.h:442
bool GetChunkData(cChunkCoords a_Coords, cChunkDataCallback &a_Callback) const
Calls the callback with the chunk's data, if available (with ChunkCS locked).
Definition: World.cpp:2202
bool IsGameModeAdventure(void) const
Returns true if the world is in Adventure mode.
Definition: World.h:117
void TickQueuedChunkDataSets()
Sets the chunk data queued in the m_SetChunkDataQueue queue into their chunk.
Definition: World.cpp:1208
AString GetLinkedNetherWorldName(void) const
Definition: World.h:721
bool DoWithEntityByID(UInt32 a_UniqueID, cEntityCallback a_Callback)
Calls the callback if the entity with the specified ID is found, with the entity object as the callba...
Definition: World.cpp:2464
void MarkChunkSaved(int a_ChunkX, int a_ChunkZ)
Definition: World.cpp:2168
NIBBLETYPE GetBlockBlockLight(Vector3i a_BlockPos) const
Returns the block-light value at the specified block position.
Definition: World.cpp:1770
void RemoveChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle *a_Client)
Removes client from the chunk specified.
Definition: World.cpp:2505
std::vector< cPlayer * > m_Players
Definition: World.h:1021
cChunkMap m_ChunkMap
Definition: World.h:1027
UInt32 SpawnEnderCrystal(Vector3d a_Pos, bool a_ShowBottom)
Spawns a new ender crystal at the specified block coords.
Definition: World.cpp:2028
const AString & GetName(void) const
Returns the name of the world.
Definition: World.h:691
void SendBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cClientHandle &a_Client)
If there is a block entity at the specified coords, sends it to the client specified.
Definition: World.cpp:2141
virtual void BroadcastPlayerListHeaderFooter(const cCompositeChat &a_Header, const cCompositeChat &a_Footer) override
bool GetBlockTypeMeta(Vector3i a_BlockPos, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
Retrieves the block type and meta at the specified coords.
Definition: World.cpp:1779
bool m_BroadcastAchievementMessages
Definition: World.h:978
bool m_bUseChatPrefixes
Whether prefixes such as [INFO] are prepended to SendMessageXXX() / BroadcastChatXXX() functions.
Definition: World.h:1061
int m_StorageCompressionFactor
Definition: World.h:958
void TickWeather(float a_Dt)
Handles the weather in each tick.
Definition: World.cpp:1088
void GetChunkStats(int &a_NumValid, int &a_NumDirty, int &a_NumInLightingQueue)
Returns the number of chunks loaded and dirty, and in the lighting queue.
Definition: World.cpp:2828
int m_MaxViewDistance
The maximum view distance that a player can have in this world.
Definition: World.h:1069
virtual void SetMinNetherPortalWidth(int a_NewMinWidth) override
Definition: World.h:733
virtual void BroadcastEntityHeadLook(const cEntity &a_Entity, const cClientHandle *a_Exclude=nullptr) override
std::atomic< bool > m_IsSavingEnabled
Whether or not writing chunks to disk is currently enabled.
Definition: World.h:961
bool IsChunkValid(int a_ChunkX, int a_ChunkZ) const
Returns true iff the chunk is present and valid.
Definition: World.cpp:2220
int GetMaxCactusHeight(void) const
Definition: World.h:859
void QueueTask(std::function< void(cWorld &)> a_Task)
Queues a task onto the tick thread.
Definition: World.cpp:2734
AString GetLinkedOverworldName(void) const
Definition: World.h:727
bool SetCommandBlockCommand(Vector3i a_BlockPos, const AString &a_Command)
Definition: World.h:321
UInt32 SpawnFallingBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Spawns an falling block entity at the given position.
Definition: World.h:453
virtual void SetMinNetherPortalHeight(int a_NewMinHeight) override
Definition: World.h:739
virtual void BroadcastParticleEffect(const AString &a_ParticleName, Vector3f a_Src, Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, const cClientHandle *a_Exclude=nullptr) override
bool m_bAnimals
Definition: World.h:1029
bool ShouldBroadcastDeathMessages(void) const
Definition: World.h:717
NIBBLETYPE m_SkyDarkness
Definition: World.h:1001
eGameMode m_GameMode
Definition: World.h:1003
AString GetLinkedEndWorldName(void) const
Definition: World.h:724
bool m_IsDaylightCycleEnabled
Definition: World.h:980
bool IsTrapdoorOpen(int a_BlockX, int a_BlockY, int a_BlockZ)
Is the trapdoor open? Returns false if there is no trapdoor at the specified coords.
Definition: World.cpp:2616
int m_MaxRainTicks
Definition: World.h:1035
UInt32 SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartType, const cItem &a_Content=cItem(), int a_BlockHeight=1)
OBSOLETE, use the Vector3d-based overload instead.
Definition: World.h:474
bool IsWeatherSunnyAt(int a_BlockX, int a_BlockZ) const
Returns true if it is sunny at the specified location.
Definition: World.cpp:595
bool ForEachBlockEntityInChunk(int a_ChunkX, int a_ChunkZ, cBlockEntityCallback a_Callback)
Calls the callback for each block entity in the specified chunk; returns true if all block entities p...
Definition: World.cpp:1375
bool ShouldBroadcastAchievementMessages(void) const
Definition: World.h:718
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.
Definition: World.cpp:2445
void GenerateRandomSpawn(int a_MaxSpawnRadius)
Generates a random spawnpoint on solid land by walking chunks and finding their biomes.
Definition: World.cpp:700
virtual void SetMaxNetherPortalWidth(int a_NewMaxWidth) override
Definition: World.h:734
bool IsWeatherRainAt(int a_BlockX, int a_BlockZ)
Returns true if it is raining at the specified location.
Definition: World.h:820
int GetSpawnZ(void) const
Definition: World.h:587
cLightingThread & GetLightingThread(void)
Definition: World.h:771
void CompareChunkClients(int a_ChunkX1, int a_ChunkZ1, int a_ChunkX2, int a_ChunkZ2, cClientDiffCallback &a_Callback)
Compares clients of two chunks, calls the callback accordingly.
Definition: World.cpp:2487
virtual void BroadcastBossBarUpdateHealth(const cEntity &a_Entity, UInt32 a_UniqueID, float a_FractionFilled) override
virtual void BroadcastSoundParticleEffect(const EffectID a_EffectID, Vector3i a_SrcPos, int a_Data, const cClientHandle *a_Exclude=nullptr) override
bool VillagersShouldHarvestCrops(void) const
Definition: World.h:131
void TickClients(std::chrono::milliseconds a_Dt)
Ticks all clients that are in this world.
Definition: World.cpp:1076
virtual void BroadcastChatSuccess(const AString &a_Message, const cClientHandle *a_Exclude=nullptr) override
Definition: World.h:163
int m_MinSunnyTicks
Definition: World.h:1034
int GetMaxViewDistance(void) const
Definition: World.h:711
void SetTicksUntilWeatherChange(int a_WeatherInterval)
Definition: World.h:98
virtual eDimension GetDimension(void) const override
Definition: World.h:133
void SaveAllChunks(void)
Saves all chunks immediately.
Definition: World.cpp:2712
int m_MaxSugarcaneHeight
Definition: World.h:1039
void SendPlayerList(cPlayer *a_DestPlayer)
Definition: World.cpp:2410
virtual void SetDaylightCycleEnabled(bool a_IsDaylightCycleEnabled)
Sets the daylight cycle to true / false.
Definition: World.h:92
eGameMode GetGameMode(void) const
Returns the current game mode.
Definition: World.h:108
eWeather m_Weather
Definition: World.h:1032
void TickQueuedTasks(void)
Executes all tasks queued onto the tick thread.
Definition: World.cpp:1289
int m_SpawnX
Definition: World.h:967
std::unique_ptr< cFireSimulator > m_FireSimulator
Definition: World.h:1017
UInt32 SpawnFallingBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
OBSOLETE, use the Vector3-based overload instead.
Definition: World.h:462
int m_SpawnZ
Definition: World.h:969
cItems PickupsFromBlock(Vector3i a_BlockPos, const cEntity *a_Digger=nullptr, const cItem *a_Tool=nullptr)
Returns all the pickups that would result if the a_Digger dug up the block at a_BlockPos using a_Tool...
Definition: World.cpp:2105
void SetNextBlockToTick(const Vector3i a_BlockPos)
Causes the specified block to be ticked on the next Tick() call.
Definition: World.cpp:622
virtual void BroadcastEntityEquipment(const cEntity &a_Entity, short a_SlotNum, const cItem &a_Item, const cClientHandle *a_Exclude=nullptr) override
int m_MaxNetherPortalWidth
Definition: World.h:973
void InitializeSpawn(void)
Definition: World.cpp:658
bool DigBlock(Vector3i a_BlockPos, const cEntity *a_Digger=nullptr)
Replaces the specified block with air, and calls the OnBroken block handler.
Definition: World.cpp:2069
void SetShouldUseChatPrefixes(bool a_Flag)
Definition: World.h:715
void GenerateChunk(int a_ChunkX, int a_ChunkZ)
Generates the given chunk.
Definition: World.cpp:2667
std::vector< UInt32 > SpawnSplitExperienceOrbs(double a_X, double a_Y, double a_Z, int a_Reward)
OBSOLETE, use the Vector3d-based overload instead.
Definition: World.h:511
void InitializeAndLoadMobSpawningValues(cIniFile &a_IniFile)
Sets mob spawning values if nonexistant to their dimension specific defaults.
Definition: World.cpp:917
void ForceSendChunkTo(int a_ChunkX, int a_ChunkZ, cChunkSender::Priority a_Priority, cClientHandle *a_Client)
Sends the chunk to the client specified, even if the client already has the chunk.
Definition: World.cpp:2532
bool IsBlockDirectlyWatered(int a_BlockX, int a_BlockY, int a_BlockZ)
Definition: World.cpp:2883
bool IsChunkQueued(int a_ChunkX, int a_ChunkZ) const
Returns true iff the chunk is in the loader / generator queue.
Definition: World.cpp:2211
size_t m_UnusedDirtyChunksCap
The maximum number of allowed unused dirty chunks for this world.
Definition: World.h:942
cFluidSimulator * m_LavaSimulator
Definition: World.h:1016
cChunkGeneratorThread m_Generator
The thread responsible for generating chunks.
Definition: World.h:1080
virtual void BroadcastSpawnEntity(cEntity &a_Entity, const cClientHandle *a_Exclude=nullptr) override
NIBBLETYPE GetBlockMeta(Vector3i a_BlockPos) const
Returns the block meta at the specified position.
Definition: World.h:370
virtual void BroadcastPlayerListUpdateDisplayName(const cPlayer &a_Player, const AString &a_CustomName, const cClientHandle *a_Exclude=nullptr) override
virtual bool IsDaylightCycleEnabled(void) const
Is the daylight cycle enabled?
Definition: World.h:89
AString m_LinkedOverworldName
The name of the overworld that portals in this world should link to.
Definition: World.h:951
bool GrowTreeFromSapling(Vector3i a_BlockPos)
Grows a tree from the sapling at the specified coords.
Definition: World.cpp:1487
bool SetSignLines(Vector3i a_BlockPos, const AString &a_Line1, const AString &a_Line2, const AString &a_Line3, const AString &a_Line4, cPlayer *a_Player=nullptr)
Sets the sign text, asking plugins for permission first.
Definition: World.cpp:2560
void CollectPickupsByEntity(cEntity &a_Entity)
Definition: World.cpp:2257
bool m_BroadcastDeathMessages
Definition: World.h:977
bool m_ShouldLavaSpawnFire
Definition: World.h:1007
std::set< eMonsterType > m_AllowedMobs
Definition: World.h:1030
void SendChunkTo(int a_ChunkX, int a_ChunkZ, cChunkSender::Priority a_Priority, cClientHandle *a_Client)
Sends the chunk to the client specified, if the client doesn't have the chunk yet.
Definition: World.cpp:2523
virtual bool WriteBlockArea(cBlockArea &a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes) override
Writes the block area into the specified coords.
Definition: World.cpp:1797
virtual int GetMinNetherPortalWidth(void) const override
Returns or sets the minumim or maximum netherportal width.
Definition: World.h:731
virtual void WakeUpSimulators(Vector3i a_Block) override
Wakes up the simulators for the specified block.
Definition: World.cpp:1357
bool SetCommandBlockCommand(int a_BlockX, int a_BlockY, int a_BlockZ, const AString &a_Command)
Sets the command block command.
Definition: World.cpp:2598
virtual void BroadcastEntityLook(const cEntity &a_Entity, const cClientHandle *a_Exclude=nullptr) override
virtual void BroadcastEntityVelocity(const cEntity &a_Entity, const cClientHandle *a_Exclude=nullptr) override
bool SetTrapdoorOpen(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_Open)
Set the state of a trapdoor.
Definition: World.cpp:2633
size_t GetGeneratorQueueLength(void)
Definition: World.h:766
void Start()
Starts threads that belong to this world.
Definition: World.cpp:687
void TickQueuedBlocks(void)
Processes the blocks queued for ticking with a delay (m_BlockTickQueue[])
Definition: World.cpp:2838
eWeather GetWeather(void) const
Returns the current weather.
Definition: World.h:808
eDimension m_Dimension
The dimension of the world, used by the client to provide correct lighting scheme.
Definition: World.h:964
virtual void BroadcastWeather(eWeather a_Weather, const cClientHandle *a_Exclude=nullptr) override
void ChunkLighted(int a_ChunkX, int a_ChunkZ, const cChunkDef::BlockNibbles &a_BlockLight, const cChunkDef::BlockNibbles &a_SkyLight)
Definition: World.cpp:2189
bool HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) const
Definition: World.cpp:2229
void ChangeWeather(void)
Forces a weather change in the next game tick.
Definition: World.cpp:585
std::unique_ptr< cSimulatorManager > m_SimulatorManager
Definition: World.h:1013
bool IsWeatherStormAt(int a_BlockX, int a_BlockZ)
Returns true if the weather is stormy at the specified location.
Definition: World.h:829
bool FindAndDoWithPlayer(const AString &a_PlayerNameHint, cPlayerListCallback a_Callback)
Finds a player from a partial or complete player name and calls the callback - case-insensitive.
Definition: World.cpp:2303
AString m_LinkedNetherWorldName
Name of the nether world - where Nether portals should teleport.
Definition: World.h:1073
void SetCommandBlocksEnabled(bool a_Flag)
Definition: World.h:706
NIBBLETYPE GetSkyDarkness()
Get the current darkness level based on the time.
Definition: World.h:886
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.
bool GrowTreeImage(const sSetBlockVector &a_Blocks)
Imprints the specified blocks into the world, as long as each log block replaces only allowed blocks.
Definition: World.cpp:1631
bool ForEachEntity(cEntityCallback a_Callback)
Calls the callback for each entity in the entire world; returns true if all entities processed,...
Definition: World.cpp:2427
bool SetSpawn(int a_X, int a_Y, int a_Z)
Set default spawn at the given coordinates.
Definition: World.cpp:631
void TickQueuedEntityAdditions(void)
Adds the entities queued in the m_EntitiesToAdd queue into their chunk.
Definition: World.cpp:1250
std::map< cMonster::eFamily, cTickTimeLong > m_LastSpawnMonster
Definition: World.h:999
size_t GetNumUnusedDirtyChunks(void) const
Returns the number of unused dirty chunks.
Definition: World.cpp:2819
cTickTimeLong m_WorldTickAge
The time since this world began, in ticks.
Definition: World.h:995
AString m_WorldName
Definition: World.h:944
size_t GetStorageSaveQueueLength(void)
Definition: World.h:769
void MarkChunkSaving(int a_ChunkX, int a_ChunkZ)
Definition: World.cpp:2159
void PlaceBlock(const Vector3i a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta)
Replaces the specified block with another, and calls the OnPlaced block handler.
Definition: World.cpp:2043
virtual void BroadcastLeashEntity(const cEntity &a_Entity, const cEntity &a_EntityLeashedTo) override
virtual void BroadcastBlockBreakAnimation(UInt32 a_EntityID, Vector3i a_BlockPos, Int8 a_Stage, const cClientHandle *a_Exclude=nullptr) override
virtual bool IsWeatherWetAt(int a_BlockX, int a_BlockZ) override
Returns true if it is raining or storming at the specified location.
Definition: World.cpp:604
cChunkGeneratorCallbacks m_GeneratorCallbacks
The callbacks that the ChunkGenerator uses to store new chunks and interface to plugins.
Definition: World.h:1086
cCriticalSection m_CSEntitiesToAdd
Guards m_EntitiesToAdd.
Definition: World.h:1099
virtual void BroadcastChat(const AString &a_Message, const cClientHandle *a_Exclude=nullptr, eMessageType a_ChatPrefix=mtCustom) override
cMapManager m_MapManager
Definition: World.h:1083
cWorld(const AString &a_WorldName, const AString &a_DataPath, cDeadlockDetect &a_DeadlockDetect, const AStringVector &a_WorldNames, eDimension a_Dimension=dimOverworld, const AString &a_LinkedOverworldName={})
Construct the world and read settings from its ini file.
Definition: World.cpp:137
unsigned int m_MaxPlayers
Definition: World.h:1025
bool GrowTreeByBiome(Vector3i a_BlockPos)
Grows a tree at the specified coords, based on the biome in the place.
Definition: World.cpp:1616
bool GrowTree(Vector3i a_BlockPos)
Grows a tree at the specified coords.
Definition: World.cpp:1469
void SpawnItemPickups(const cItems &a_Pickups, Vector3i a_BlockPos, double a_FlyAwaySpeed=1.0, bool a_IsPlayerCreated=false)
Spawns item pickups for each item in the list.
Definition: World.cpp:1806
void QueueSaveAllChunks(void)
Queues a task to save all chunks onto the tick thread.
Definition: World.cpp:2725
bool m_IsDeepSnowEnabled
Definition: World.h:1006
virtual void SetMaxNetherPortalHeight(int a_NewMaxHeight) override
Definition: World.h:740
std::vector< SetChunkData > m_SetChunkDataQueue
Queue for the chunk data to be set into m_ChunkMap by the tick thread.
Definition: World.h:1108
virtual int GetMaxNetherPortalWidth(void) const override
Definition: World.h:732
std::chrono::milliseconds m_LastChunkCheck
Definition: World.h:997
EMCSBiome GetBiomeAt(int a_BlockX, int a_BlockZ)
Returns the biome at the specified coords.
Definition: World.cpp:1694
cRedstoneSimulator * GetRedstoneSimulator(void)
Definition: World.h:601
AString m_StorageSchema
Name of the storage schema used to load and save chunks.
Definition: World.h:956
bool DoWithPlayer(const AString &a_PlayerName, cPlayerListCallback a_Callback)
Calls the callback for the player of the given name; returns true if the player was found and the cal...
Definition: World.cpp:2284
bool m_bFarmlandTramplingEnabled
Definition: World.h:1005
UInt32 SpawnMinecart(Vector3d a_Pos, int a_MinecartType, const cItem &a_Content=cItem(), int a_BlockHeight=1)
Spawns an minecart at the given coordinates.
Definition: World.cpp:1958
bool IsFarmlandTramplingEnabled(void) const
Returns true if farmland trampling is enabled.
Definition: World.h:125
virtual void BroadcastBlockAction(Vector3i a_BlockPos, Byte a_Byte1, Byte a_Byte2, BLOCKTYPE a_BlockType, const cClientHandle *a_Exclude=nullptr) override
const AString & GetIniFileName(void) const
Returns the name of the world.ini file used by this world.
Definition: World.h:697
bool GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString &a_Line1, AString &a_Line2, AString &a_Line3, AString &a_Line4)
Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coo...
Definition: World.cpp:1429
int m_MaxThunderStormTicks
Definition: World.h:1036
bool GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsByBonemeal=false)
OBSOLETE, use the Vector3-based overload instead.
Definition: World.h:667
virtual cTickTime GetTimeOfDay(void) const override
Definition: World.cpp:480
bool SetBiomeAt(int a_BlockX, int a_BlockZ, EMCSBiome a_Biome)
Sets the biome at the specified coords.
Definition: World.cpp:1703
cFluidSimulator * GetLavaSimulator(void)
Definition: World.h:600
AString m_IniFileName
Definition: World.h:953
virtual bool DoWithBlockEntityAt(Vector3i a_Position, cBlockEntityCallback a_Callback) override
Calls the callback for the block entity at the specified coords; returns false if there's no block en...
Definition: World.cpp:1420
virtual bool IsWeatherWetAtXYZ(Vector3i a_Position) override
Returns true if it is raining or storming at the specified location, and the rain reaches (the bottom...
Definition: World.cpp:613
virtual UInt32 SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward) override
OBSOLETE, use the Vector3d-based overload instead.
Definition: World.h:497
std::vector< std::pair< OwnedEntity, cWorld * > > m_EntitiesToAdd
List of entities that are scheduled for adding, waiting for the Tick thread to add them.
Definition: World.h:1102
int m_MinNetherPortalWidth
Definition: World.h:972
cMapManager & GetMapManager(void)
Returns the associated map manager instance.
Definition: World.h:703
virtual void BroadcastChatFatal(const AString &a_Message, const cClientHandle *a_Exclude=nullptr) override
Definition: World.h:165
cTickTimeLong GetWorldTickAge() const
Definition: World.cpp:509
virtual std::vector< UInt32 > SpawnSplitExperienceOrbs(Vector3d a_Pos, int a_Reward) override
Spawns experience orbs of the specified total value at the given location.
Definition: World.cpp:1915
void QueueBlockForTick(int a_BlockX, int a_BlockY, int a_BlockZ, int a_TicksToWait)
Queues the block to be ticked after the specified number of game ticks.
Definition: World.cpp:2868
virtual int GetMaxNetherPortalHeight(void) const override
Definition: World.h:738
cFluidSimulator * InitializeFluidSimulator(cIniFile &a_IniFile, const char *a_FluidName, BLOCKTYPE a_SimulateBlock, BLOCKTYPE a_StationaryBlock)
Creates a new fluid simulator, loads its settings from the inifile (a_FluidName section)
Definition: World.cpp:3081
virtual void BroadcastEntityPosition(const cEntity &a_Entity, const cClientHandle *a_Exclude=nullptr) override
bool DigBlock(int a_X, int a_Y, int a_Z, cEntity *a_Digger=nullptr)
OBSOLETE, use the Vector3-based overload instead.
Definition: World.h:558
virtual void BroadcastChatInfo(const AString &a_Message, const cClientHandle *a_Exclude=nullptr) override
Definition: World.h:161
AString m_DataPath
The path to the root directory for the world files.
Definition: World.h:947
std::vector< BlockTickQueueItem * > m_BlockTickQueue
Definition: World.h:1010
std::chrono::milliseconds m_LastSave
Definition: World.h:998
virtual void BroadcastEntityEffect(const cEntity &a_Entity, int a_EffectID, int a_Amplifier, int a_Duration, const cClientHandle *a_Exclude=nullptr) override
eWeather ChooseNewWeather(void)
Chooses a reasonable transition from the current weather to a new weather.
Definition: World.cpp:894
cWorldStorage & GetStorage(void)
Definition: World.h:851
void CastThunderbolt(Vector3i a_Block)
Casts a thunderbolt at the specified coords.
Definition: World.cpp:470
UInt32 SpawnFallingBlock(Vector3d a_Pos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Spawns an falling block entity at the given position.
Definition: World.cpp:1878
UInt32 CreateProjectile(Vector3d a_Pos, cProjectileEntity::eKind a_Kind, cEntity *a_Creator, const cItem *a_Item, const Vector3d *a_Speed=nullptr)
Creates a projectile of the specified type.
Definition: World.cpp:2948
cScoreboard m_Scoreboard
Definition: World.h:1082
void SetLinkedOverworldName(const AString &a_Name)
Definition: World.h:728
int m_MaxCactusHeight
Definition: World.h:1038
void SetMaxViewDistance(int a_MaxViewDistance)
Definition: World.cpp:1734
size_t GetLightingQueueLength(void)
Definition: World.h:767
size_t GetStorageLoadQueueLength(void)
Definition: World.h:768
size_t GetNumChunks() const
Returns the number of chunks loaded
Definition: World.cpp:2810
AString m_LinkedEndWorldName
Name of the End world - where End portals should teleport.
Definition: World.h:1077
virtual void BroadcastDestroyEntity(const cEntity &a_Entity, const cClientHandle *a_Exclude=nullptr) override
cCriticalSection m_CSSetChunkDataQueue
CS protecting m_SetChunkDataQueue.
Definition: World.h:1105
virtual void BroadcastScoreUpdate(const AString &a_Objective, const AString &a_Player, cObjective::Score a_Score, Byte a_Mode) override
void FastSetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Sets the block at the specified coords to the specified value.
Definition: World.h:356
virtual void BroadcastSoundEffect(const AString &a_SoundName, Vector3d a_Position, float a_Volume, float a_Pitch, const cClientHandle *a_Exclude=nullptr) override
virtual void SendBlockTo(int a_BlockX, int a_BlockY, int a_BlockZ, const cPlayer &a_Player)=0
Sends the block on those coords to the player.
bool GetBlocks(sSetBlockVector &a_Blocks, bool a_ContinueOnFailure)
Retrieves block types of the specified blocks.
Definition: World.cpp:2060
bool DoWithNearestPlayer(Vector3d a_Pos, double a_RangeLimit, cPlayerListCallback a_Callback, bool a_CheckLineOfSight=true, bool a_IgnoreSpectator=true)
Calls the callback for nearest player for given position, Returns false if player not found,...
Definition: World.cpp:2356
bool ForEachLoadedChunk(cFunctionRef< bool(int, int)> a_Callback)
Calls the callback for each loaded chunk.
Definition: World.cpp:2703
int GetMaxSugarcaneHeight(void) const
Definition: World.h:858
virtual void SpawnItemPickups(const cItems &a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_SpeedX, double a_SpeedY, double a_SpeedZ, bool a_IsPlayerCreated=false) override
OBSOLETE, use the Vector3d-based overload instead.
Definition: World.h:432
int GetSpawnY(void) const
Definition: World.h:586
void WakeUpSimulatorsInArea(const cCuboid &a_Area)
Wakes up the simulators for the specified area of blocks.
Definition: World.cpp:1366
cTickTimeLong GetWorldDate() const
Definition: World.cpp:500
void SetBlockMeta(Vector3i a_BlockPos, NIBBLETYPE a_MetaData)
Sets the meta for the specified block, while keeping the blocktype.
Definition: World.cpp:1752
cChunkMap * GetChunkMap(void)
Definition: World.h:852
bool ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback a_Callback)
Calls the callback for each entity in the specified chunk; returns true if all entities processed,...
Definition: World.cpp:2436
void UpdateSkyDarkness(void)
Definition: World.cpp:1326
bool IsWeatherWet(void) const
Returns true if the world currently has any precipitation - rain, storm or snow.
Definition: World.h:835
virtual void BroadcastPlayerListRemovePlayer(const cPlayer &a_Player, const cClientHandle *a_Exclude=nullptr) override
cSimulatorManager * GetSimulatorManager(void)
Definition: World.h:597
virtual void BroadcastDisplayObjective(const AString &a_Objective, cScoreboard::eDisplaySlot a_Display) override
bool AreCommandBlocksEnabled(void) const
Definition: World.h:705
bool IsChunkLighted(int a_ChunkX, int a_ChunkZ)
Definition: World.cpp:2685
int m_MinNetherPortalHeight
Definition: World.h:974
OwnedEntity RemoveEntity(cEntity &a_Entity)
Removes the entity from the world.
Definition: World.cpp:2769
bool m_VillagersShouldHarvestCrops
Definition: World.h:1008
void Tick(std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_LastTickDurationMSec)
Definition: World.cpp:1002
virtual bool ForEachPlayer(cPlayerListCallback a_Callback) override
Calls the callback for each player in the list; returns true if all players processed,...
Definition: World.cpp:2266
virtual void BroadcastRemoveEntityEffect(const cEntity &a_Entity, int a_EffectID, const cClientHandle *a_Exclude=nullptr) override
void SetTNTShrapnelLevel(eShrapnelLevel a_Flag)
Definition: World.h:709
cTickThread m_TickThread
Definition: World.h:1090
virtual void SetTimeOfDay(cTickTime a_TimeOfDay) override
Definition: World.cpp:518
bool IsWeatherStorm(void) const
Returns true if the current weather is stormy.
Definition: World.h:826
void SetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Sets the block at the specified coords to the specified value.
Definition: World.cpp:1743
void SetWeather(eWeather a_NewWeather)
Sets the specified weather; resets weather interval; asks and notifies plugins of the change.
Definition: World.cpp:556
bool IsGameModeCreative(void) const
Returns true if the world is in Creative mode.
Definition: World.h:111
virtual int GetHeight(int a_BlockX, int a_BlockZ) override
Returns the world height at the specified coords; waits for the chunk to get loaded / generated.
Definition: World.cpp:2123
virtual int GetMinNetherPortalHeight(void) const override
Returns or sets the minumim or maximum netherportal height.
Definition: World.h:737
void Stop(cDeadlockDetect &a_DeadlockDetect)
Stops threads that belong to this world (part of deinit).
Definition: World.cpp:956
bool AddChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle *a_Client)
Adds client to a chunk, if not already present; returns true if added, false if present.
Definition: World.cpp:2496
bool m_IsSpawnExplicitlySet
Definition: World.h:966
cFluidSimulator * m_WaterSimulator
Definition: World.h:1015
A simple RAII locker for the chunkmap - locks the chunkmap in its constructor, unlocks it in the dest...
Definition: World.h:60
cLock(const cWorld &a_World)
Definition: World.cpp:86
cWorld & m_World
Definition: World.h:909
cTickThread(cWorld &a_World)
Definition: World.cpp:98
virtual void Execute(void) override
This function, overloaded by the descendants, is called in the new thread.
Definition: World.cpp:108
Implementation of the callbacks that the ChunkGenerator uses to store new chunks and interface to plu...
Definition: World.h:921
virtual bool IsChunkValid(cChunkCoords a_Coords) override
Called just before the chunk generation is started, to verify that it hasn't been generated in the me...
Definition: World.cpp:3186
cChunkGeneratorCallbacks(cWorld &a_World)
Definition: World.cpp:3152
virtual void CallHookChunkGenerated(cChunkDesc &a_ChunkDesc) override
Called after the chunk is generated, before it is handed to the chunk sink.
Definition: World.cpp:3224
virtual void CallHookChunkGenerating(cChunkDesc &a_ChunkDesc) override
Called when the chunk is about to be generated.
Definition: World.cpp:3213
virtual bool HasChunkAnyClients(cChunkCoords a_Coords) override
Called when the generator is overloaded to skip chunks that are no longer needed.
Definition: World.cpp:3204
virtual void OnChunkGenerated(cChunkDesc &a_ChunkDesc) override
Called after the chunk has been generated The interface may store the chunk, send it over network,...
Definition: World.cpp:3161
virtual bool IsChunkQueued(cChunkCoords a_Coords) override
Called to check whether the specified chunk is in the queued state.
Definition: World.cpp:3195
The actual world storage class.
Definition: WorldStorage.h:54
size_t GetSaveQueueLength(void)
size_t GetLoadQueueLength(void)