summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorpeterbell10 <peterbell10@live.co.uk>2018-09-24 22:33:39 +0200
committerAlexander Harkness <me@bearbin.net>2018-09-24 22:33:39 +0200
commit4727ed20846bb3d1a9eabb27aaaa9c5524129556 (patch)
treed6206a51db95a15fd3dfadb9691c868fc6bd8bd1 /src
parentAdd BurnsInDaylight to Lua API and Monsters.ini (#4295) (diff)
downloadcuberite-4727ed20846bb3d1a9eabb27aaaa9c5524129556.tar
cuberite-4727ed20846bb3d1a9eabb27aaaa9c5524129556.tar.gz
cuberite-4727ed20846bb3d1a9eabb27aaaa9c5524129556.tar.bz2
cuberite-4727ed20846bb3d1a9eabb27aaaa9c5524129556.tar.lz
cuberite-4727ed20846bb3d1a9eabb27aaaa9c5524129556.tar.xz
cuberite-4727ed20846bb3d1a9eabb27aaaa9c5524129556.tar.zst
cuberite-4727ed20846bb3d1a9eabb27aaaa9c5524129556.zip
Diffstat (limited to '')
-rw-r--r--src/Bindings/LuaState.cpp5
-rw-r--r--src/Bindings/LuaState.h24
-rw-r--r--src/Bindings/ManualBindings.h10
-rw-r--r--src/Bindings/ManualBindings_BlockArea.cpp62
-rw-r--r--src/BlockEntities/HopperEntity.cpp12
-rw-r--r--src/BlockEntities/MobSpawnerEntity.cpp2
-rw-r--r--src/Chunk.cpp10
-rw-r--r--src/ChunkDef.h2
-rw-r--r--src/ClientHandle.cpp18
-rw-r--r--src/Entities/ArrowEntity.cpp5
-rw-r--r--src/Entities/Entity.cpp18
-rw-r--r--src/Entities/FallingBlock.cpp10
-rw-r--r--src/Entities/Player.cpp8
-rw-r--r--src/Entities/ProjectileEntity.cpp23
-rw-r--r--src/Entities/TNTEntity.cpp2
-rw-r--r--src/Generating/FinishGen.cpp4
-rw-r--r--src/Generating/PieceGeneratorBFSTree.cpp14
-rw-r--r--src/Generating/PrefabPiecePool.cpp9
-rw-r--r--src/Items/ItemDoor.h8
-rw-r--r--src/NetherPortalScanner.cpp4
-rw-r--r--src/SetChunkData.cpp8
-rw-r--r--src/Simulator/FireSimulator.cpp24
-rw-r--r--src/Simulator/FloodyFluidSimulator.cpp47
-rw-r--r--src/Simulator/SandSimulator.cpp6
-rw-r--r--src/Vector3.h16
-rw-r--r--src/World.cpp8
-rwxr-xr-xsrc/WorldStorage/WSSAnvil.cpp14
27 files changed, 192 insertions, 181 deletions
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp
index 7ec099982..c1e71bd5c 100644
--- a/src/Bindings/LuaState.cpp
+++ b/src/Bindings/LuaState.cpp
@@ -2004,7 +2004,7 @@ void cLuaState::LogStackTrace(lua_State * a_LuaState, int a_StartingDepth)
-int cLuaState::ApiParamError(const char * a_MsgFormat, fmt::ArgList argp)
+int cLuaState::ApiParamError(fmt::StringRef a_Msg)
{
// Retrieve current function name
lua_Debug entry;
@@ -2012,8 +2012,7 @@ int cLuaState::ApiParamError(const char * a_MsgFormat, fmt::ArgList argp)
VERIFY(lua_getinfo(m_LuaState, "n", &entry));
// Compose the error message:
- AString msg = Printf(a_MsgFormat, argp);
- AString errorMsg = fmt::format("{0}: {1}", (entry.name != nullptr) ? entry.name : "<unknown function>", msg);
+ AString errorMsg = fmt::format("{0}: {1}", (entry.name != nullptr) ? entry.name : "<unknown function>", a_Msg);
// Log everything into the console:
LOGWARNING("%s", errorMsg.c_str());
diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h
index 2510c6f0b..362f16e21 100644
--- a/src/Bindings/LuaState.h
+++ b/src/Bindings/LuaState.h
@@ -820,11 +820,29 @@ public:
/** Logs all items in the current stack trace to the server console */
static void LogStackTrace(lua_State * a_LuaState, int a_StartingDepth = 0);
- /** Formats and prints the message, prefixed with the current function name, then logs the stack contents and raises a Lua error.
+ /** Prints the message, prefixed with the current function name, then logs the stack contents and raises a Lua error.
To be used for bindings when they detect bad parameters.
Doesn't return, but a dummy return type is provided so that Lua API functions may do "return ApiParamError(...)". */
- int ApiParamError(const char * a_MsgFormat, fmt::ArgList);
- FMT_VARIADIC(int, ApiParamError, const char *)
+ int ApiParamError(fmt::StringRef a_Msg);
+
+ /** Formats and prints the message using printf-style format specifiers, but prefixed with the current function name, then logs the stack contents and raises a Lua error.
+ To be used for bindings when they detect bad parameters.
+ Doesn't return, but a dummy return type is provided so that Lua API functions may do "return ApiParamError(...)". */
+ template <typename... Args>
+ int ApiParamError(const char * a_MsgFormat, const Args & ... a_Args)
+ {
+ return ApiParamError(Printf(a_MsgFormat, a_Args...));
+ }
+
+ /** Formats and prints the message using python-style format specifiers, but prefixed with the current function name, then logs the stack contents and raises a Lua error.
+ To be used for bindings when they detect bad parameters.
+ Doesn't return, but a dummy return type is provided so that Lua API functions may do "return ApiParamError(...)". */
+ template <typename... Args>
+ int FApiParamError(const char * a_MsgFormat, const Args & ... a_Args)
+ {
+ return ApiParamError(fmt::format(a_MsgFormat, a_Args...));
+ }
+
/** Returns the type of the item on the specified position in the stack */
AString GetTypeText(int a_StackPos);
diff --git a/src/Bindings/ManualBindings.h b/src/Bindings/ManualBindings.h
index fb19d5a61..42e34eda2 100644
--- a/src/Bindings/ManualBindings.h
+++ b/src/Bindings/ManualBindings.h
@@ -288,17 +288,17 @@ public:
L.GetStackValues(1, Self, BlockX, BlockY, BlockZ, FnRef);
if (Self == nullptr)
{
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Invalid 'self'");
+ return L.ApiParamError("Invalid 'self'");
}
if (!FnRef.IsValid())
{
- return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a valid callback function for parameter #5");
+ return L.ApiParamError("Expected a valid callback function for parameter #5");
}
if (!(Self->*CoordCheckFn)(BlockX, BlockY, BlockZ))
{
- return lua_do_error(tolua_S, Printf("Error in function call '#funcname#': The provided coordinates ({%d, %d, %d}) are not valid",
- BlockX, BlockY, BlockZ
- ).c_str());
+ return L.FApiParamError("The provided coordinates ({0}) are not valid",
+ Vector3i{BlockX, BlockY, BlockZ}
+ );
}
// Call the DoWith function:
diff --git a/src/Bindings/ManualBindings_BlockArea.cpp b/src/Bindings/ManualBindings_BlockArea.cpp
index 72d9f7497..b2c634b33 100644
--- a/src/Bindings/ManualBindings_BlockArea.cpp
+++ b/src/Bindings/ManualBindings_BlockArea.cpp
@@ -129,7 +129,7 @@ static int tolua_cBlockArea_Create(lua_State * a_LuaState)
// Create the area:
if ((size.x <= 0) || (size.y <= 0) || (size.z <= 0))
{
- return L.ApiParamError("Invalid sizes, must be greater than zero, got {%d, %d, %d}", size.x, size.y, size.z);
+ return L.FApiParamError("Invalid sizes, must be greater than zero, got {0}", size);
}
ASSERT(self != nullptr);
self->Create(size, dataTypes);
@@ -216,10 +216,8 @@ static int tolua_cBlockArea_GetBlockTypeMeta(lua_State * a_LuaState)
readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidCoords(coords))
{
- return L.ApiParamError("Coords ({%d, %d, %d}) out of range ({%d, %d, %d} - {%d, %d, %d}).",
- coords.x, coords.y, coords.z,
- self->GetOriginX(), self->GetOriginY(), self->GetOriginZ(),
- self->GetOriginX() + self->GetSizeX() - 1, self->GetOriginY() + self->GetSizeY() - 1, self->GetOriginZ() + self->GetSizeZ() - 1
+ return L.FApiParamError("Coords ({0}) out of range ({1} - {2).",
+ coords, self->GetOrigin(), self->GetOrigin() + self->GetSize() - Vector3i{1, 1, 1}
);
}
BLOCKTYPE blockType;
@@ -368,9 +366,8 @@ static int tolua_cBlockArea_GetRelBlockTypeMeta(lua_State * a_LuaState)
readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidRelCoords(coords))
{
- return L.ApiParamError("The coords ({%d, %d, %d}) are out of range (max {%d, %d, %d}).",
- coords.x, coords.y, coords.z,
- self->GetSizeX() - 1, self->GetSizeY() - 1, self->GetSizeZ() - 1
+ return L.FApiParamError("The coords ({0}) are out of range (max {1}).",
+ coords, self->GetSize() - Vector3i{1, 1, 1}
);
}
BLOCKTYPE blockType;
@@ -518,32 +515,32 @@ static int tolua_cBlockArea_Read(lua_State * a_LuaState)
bounds.Sort();
if (bounds.p1.y < 0)
{
- LOGWARNING("cBlockArea:Read(): MinBlockY less than zero, adjusting to zero. Coords: {%d, %d, %d} - {%d, %d, %d}",
- bounds.p1.x, bounds.p1.y, bounds.p1.z, bounds.p2.x, bounds.p2.y, bounds.p2.z
+ FLOGWARNING("cBlockArea:Read(): MinBlockY less than zero, adjusting to zero. Coords: {0} - {1}",
+ bounds.p1, bounds.p2
);
L.LogStackTrace();
bounds.p1.y = 0;
}
else if (bounds.p1.y >= cChunkDef::Height)
{
- LOGWARNING("cBlockArea:Read(): MinBlockY more than chunk height, adjusting to chunk height. Coords: {%d, %d, %d} - {%d, %d, %d}",
- bounds.p1.x, bounds.p1.y, bounds.p1.z, bounds.p2.x, bounds.p2.y, bounds.p2.z
+ FLOGWARNING("cBlockArea:Read(): MinBlockY more than chunk height, adjusting to chunk height. Coords: {0} - {1}",
+ bounds.p1, bounds.p2
);
L.LogStackTrace();
bounds.p1.y = cChunkDef::Height - 1;
}
if (bounds.p2.y < 0)
{
- LOGWARNING("cBlockArea:Read(): MaxBlockY less than zero, adjusting to zero. Coords: {%d, %d, %d} - {%d, %d, %d}",
- bounds.p1.x, bounds.p1.y, bounds.p1.z, bounds.p2.x, bounds.p2.y, bounds.p2.z
+ FLOGWARNING("cBlockArea:Read(): MaxBlockY less than zero, adjusting to zero. Coords: {0} - {1}",
+ bounds.p1, bounds.p2
);
L.LogStackTrace();
bounds.p2.y = 0;
}
else if (bounds.p2.y > cChunkDef::Height)
{
- LOGWARNING("cBlockArea:Read(): MaxBlockY more than chunk height, adjusting to chunk height. Coords: {%d, %d, %d} - {%d, %d, %d}",
- bounds.p1.x, bounds.p1.y, bounds.p1.z, bounds.p2.x, bounds.p2.y, bounds.p2.z
+ FLOGWARNING("cBlockArea:Read(): MaxBlockY more than chunk height, adjusting to chunk height. Coords: {0} - {1}",
+ bounds.p1, bounds.p2
);
L.LogStackTrace();
bounds.p2.y = cChunkDef::Height;
@@ -789,10 +786,8 @@ static int GetBlock(lua_State * a_LuaState)
readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidCoords(coords))
{
- return L.ApiParamError("The coords ({%d, %d, %d}) are out of range ({%d, %d, %d} - {%d, %d, %d}).",
- coords.x, coords.y, coords.z,
- self->GetOriginX(), self->GetOriginY(), self->GetOriginZ(),
- self->GetOriginX() + self->GetSizeX() - 1, self->GetOriginY() + self->GetSizeY() - 1, self->GetOriginZ() + self->GetSizeZ() - 1
+ return L.FApiParamError("The coords ({0}) are out of range ({1} - {2}).",
+ coords, self->GetOrigin(), self->GetOrigin() + self->GetSize() - Vector3i{1, 1, 1}
);
}
@@ -842,9 +837,8 @@ static int GetRelBlock(lua_State * a_LuaState)
readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidRelCoords(coords))
{
- return L.ApiParamError("The coords ({%d, %d, %d}) are out of range ({%d, %d, %d}).",
- coords.x, coords.y, coords.z,
- self->GetSizeX(), self->GetSizeY(), self->GetSizeZ()
+ return L.ApiParamError("The coords ({0}) are out of range ({1}).",
+ coords, self->GetSize()
);
}
@@ -894,10 +888,8 @@ static int SetBlock(lua_State * a_LuaState)
auto idx = readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidCoords(coords))
{
- return L.ApiParamError("The coords ({%d, %d, %d}) are out of range ({%d, %d, %d} - {%d, %d, %d}).",
- coords.x, coords.y, coords.z,
- self->GetOriginX(), self->GetOriginY(), self->GetOriginZ(),
- self->GetOriginX() + self->GetSizeX() - 1, self->GetOriginY() + self->GetSizeY() - 1, self->GetOriginZ() + self->GetSizeZ() - 1
+ return L.FApiParamError("The coords ({0}) are out of range ({1} - {2}).",
+ coords, self->GetOrigin(), self->GetOrigin() + self->GetSize() - Vector3i{1, 1, 1}
);
}
DataType data;
@@ -949,9 +941,8 @@ static int SetRelBlock(lua_State * a_LuaState)
auto idx = readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidRelCoords(coords))
{
- return L.ApiParamError("The coords ({%d, %d, %d}) are out of range ({%d, %d, %d}).",
- coords.x, coords.y, coords.z,
- self->GetSizeX(), self->GetSizeY(), self->GetSizeZ()
+ return L.FApiParamError("The coords ({0}) are out of range ({1}).",
+ coords, self->GetSize()
);
}
DataType data;
@@ -993,10 +984,8 @@ static int tolua_cBlockArea_SetBlockTypeMeta(lua_State * a_LuaState)
auto idx = readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidCoords(coords))
{
- return L.ApiParamError("The coords ({%d, %d, %d}) are out of range ({%d, %d, %d} - {%d, %d, %d}).",
- coords.x, coords.y, coords.z,
- self->GetOriginX(), self->GetOriginY(), self->GetOriginZ(),
- self->GetOriginX() + self->GetSizeX() - 1, self->GetOriginY() + self->GetSizeY() - 1, self->GetOriginZ() + self->GetSizeZ() - 1
+ return L.FApiParamError("The coords ({0}) are out of range ({1} - {2}).",
+ coords, self->GetOrigin(), self->GetOrigin() + self->GetSize() - Vector3i{1, 1, 1}
);
}
@@ -1043,9 +1032,8 @@ static int tolua_cBlockArea_SetRelBlockTypeMeta(lua_State * a_LuaState)
auto idx = readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidRelCoords(coords))
{
- return L.ApiParamError("The coords ({%d, %d, %d}) are out of range ({%d, %d, %d}).",
- coords.x, coords.y, coords.z,
- self->GetSizeX(), self->GetSizeY(), self->GetSizeZ()
+ return L.FApiParamError("The coords ({0}) are out of range ({1}).",
+ coords, self->GetSize()
);
}
diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp
index 91340f35b..6eb5f961d 100644
--- a/src/BlockEntities/HopperEntity.cpp
+++ b/src/BlockEntities/HopperEntity.cpp
@@ -334,7 +334,7 @@ bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick)
cBlockEntityWithItems * BlockEntity = static_cast<cBlockEntityWithItems *>(DestChunk->GetBlockEntity(OutX, OutY, OutZ));
if (BlockEntity == nullptr)
{
- LOGWARNING("%s: A block entity was not found where expected at {%d, %d, %d}", __FUNCTION__, OutX, OutY, OutZ);
+ FLOGWARNING("{0}: A block entity was not found where expected at {1}", __FUNCTION__, Vector3i{OutX, OutY, OutZ});
return false;
}
res = MoveItemsToGrid(*BlockEntity);
@@ -360,7 +360,7 @@ bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk)
cChestEntity * MainChest = static_cast<cChestEntity *>(a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ));
if (MainChest == nullptr)
{
- LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, m_PosX, m_PosY + 1, m_PosZ);
+ FLOGWARNING("{0}: A chest entity was not found where expected, at {1}", __FUNCTION__, GetPos() + Vector3i{0, 1, 0});
return false;
}
if (MoveItemsFromGrid(*MainChest))
@@ -401,7 +401,7 @@ bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk)
cChestEntity * SideChest = static_cast<cChestEntity *>(Neighbor->GetBlockEntity(m_PosX + Coords[i].x, m_PosY + 1, m_PosZ + Coords[i].z));
if (SideChest == nullptr)
{
- LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, m_PosX + Coords[i].x, m_PosY + 1, m_PosZ + Coords[i].z);
+ FLOGWARNING("{0}: A chest entity was not found where expected, at {1}", __FUNCTION__, GetPos() + Vector3i{Coords[i].x, 1, Coords[i].z});
}
else
{
@@ -426,7 +426,7 @@ bool cHopperEntity::MoveItemsFromFurnace(cChunk & a_Chunk)
cFurnaceEntity * Furnace = static_cast<cFurnaceEntity *>(a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ));
if (Furnace == nullptr)
{
- LOGWARNING("%s: A furnace entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, m_PosX, m_PosY + 1, m_PosZ);
+ FLOGWARNING("{0}: A furnace entity was not found where expected, at {1}", __FUNCTION__, GetPos() + Vector3i{0, 1, 0});
return false;
}
@@ -527,7 +527,7 @@ bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_Block
cChestEntity * ConnectedChest = static_cast<cChestEntity *>(a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ));
if (ConnectedChest == nullptr)
{
- LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, a_BlockX, a_BlockY, a_BlockZ);
+ FLOGWARNING("{0}: A chest entity was not found where expected, at {1}", __FUNCTION__, Vector3i{a_BlockX, a_BlockY, a_BlockZ});
return false;
}
if (MoveItemsToGrid(*ConnectedChest))
@@ -570,7 +570,7 @@ bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_Block
cChestEntity * Chest = static_cast<cChestEntity *>(Neighbor->GetBlockEntity(a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z));
if (Chest == nullptr)
{
- LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d} (%d, %d)", __FUNCTION__, a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z, x, z);
+ FLOGWARNING("{0}: A chest entity was not found where expected, at {1} ({2}, {3}})", __FUNCTION__, Vector3i{a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z}, x, z);
continue;
}
if (MoveItemsToGrid(*Chest))
diff --git a/src/BlockEntities/MobSpawnerEntity.cpp b/src/BlockEntities/MobSpawnerEntity.cpp
index b92139025..595f433b7 100644
--- a/src/BlockEntities/MobSpawnerEntity.cpp
+++ b/src/BlockEntities/MobSpawnerEntity.cpp
@@ -64,7 +64,7 @@ bool cMobSpawnerEntity::UsedBy(cPlayer * a_Player)
{
a_Player->GetInventory().RemoveOneEquippedItem();
}
- LOGD("Changed monster spawner at {%d, %d, %d} to type %s.", GetPosX(), GetPosY(), GetPosZ(), cMonster::MobTypeToString(MonsterType).c_str());
+ FLOGD("Changed monster spawner at {0} to type {1}.", GetPos(), cMonster::MobTypeToString(MonsterType));
return true;
}
return false;
diff --git a/src/Chunk.cpp b/src/Chunk.cpp
index f4af65b60..41a59c103 100644
--- a/src/Chunk.cpp
+++ b/src/Chunk.cpp
@@ -638,7 +638,7 @@ void cChunk::SpawnMobs(cMobSpawner & a_MobSpawner)
double ActualX = WorldX + 0.5;
double ActualZ = WorldZ + 0.5;
newMob->SetPosition(ActualX, WorldY, ActualZ);
- LOGD("Spawning %s #%i at {%d, %d, %d}", newMob->GetClass(), newMob->GetUniqueID(), WorldX, WorldY, WorldZ);
+ FLOGD("Spawning {0} #{1} at {2}", newMob->GetClass(), newMob->GetUniqueID(), Vector3i{WorldX, WorldY, WorldZ});
NumberOfSuccess++;
} // while (retry)
}
@@ -1056,11 +1056,11 @@ bool cChunk::GrowMelonPumpkin(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_Bl
{
// Place a randomly-facing produce:
NIBBLETYPE Meta = (ProduceType == E_BLOCK_MELON) ? 0 : static_cast<NIBBLETYPE>(Random.RandInt(4) % 4);
- LOGD("Growing melon / pumpkin at {%d, %d, %d} (<%d, %d> from stem), overwriting %s, growing on top of %s, meta %d",
- a_RelX + x + m_PosX * cChunkDef::Width, a_RelY, a_RelZ + z + m_PosZ * cChunkDef::Width,
+ FLOGD("Growing melon / pumpkin at {0} (<{1}, {2}> from stem), overwriting {3}, growing on top of {4}, meta {5}",
+ PositionToWorldPosition(a_RelX + x, a_RelY, a_RelZ + z),
x, z,
- ItemTypeToString(BlockType[CheckType]).c_str(),
- ItemTypeToString(Soil).c_str(),
+ ItemTypeToString(BlockType[CheckType]),
+ ItemTypeToString(Soil),
Meta
);
VERIFY(UnboundedRelFastSetBlock(a_RelX + x, a_RelY, a_RelZ + z, ProduceType, Meta));
diff --git a/src/ChunkDef.h b/src/ChunkDef.h
index d73bd4198..bfed62aae 100644
--- a/src/ChunkDef.h
+++ b/src/ChunkDef.h
@@ -217,7 +217,7 @@ public:
{
return MakeIndexNoCheck(x, y, z);
}
- LOGERROR("cChunkDef::MakeIndex(): coords out of range: {%d, %d, %d}; returning fake index 0", x, y, z);
+ FLOGERROR("cChunkDef::MakeIndex(): coords out of range: {0}; returning fake index 0", Vector3i{x, y, z});
ASSERT(!"cChunkDef::MakeIndex(): coords out of chunk range!");
return 0;
}
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 027623151..f80b5c5af 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -1059,8 +1059,8 @@ void cClientHandle::HandleAnvilItemName(const AString & a_ItemName)
void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, UInt8 a_Status)
{
- LOGD("HandleLeftClick: {%i, %i, %i}; Face: %i; Stat: %i",
- a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Status
+ FLOGD("HandleLeftClick: {0}; Face: {1}; Stat: {2}",
+ Vector3i{a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace, a_Status
);
m_NumBlockChangeInteractionsThisTick++;
@@ -1298,9 +1298,9 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo
(m_LastDigBlockZ != a_BlockZ)
)
{
- LOGD("Prevented a dig / aim bug in the client (finish {%d, %d, %d} vs start {%d, %d, %d}, HSD: %s)",
- a_BlockX, a_BlockY, a_BlockZ,
- m_LastDigBlockX, m_LastDigBlockY, m_LastDigBlockZ,
+ FLOGD("Prevented a dig / aim bug in the client (finish {0} vs start {1}, HSD: {2})",
+ Vector3i{a_BlockX, a_BlockY, a_BlockZ},
+ Vector3i{m_LastDigBlockX, m_LastDigBlockY, m_LastDigBlockZ},
(m_HasStartedDigging ? "True" : "False")
);
return;
@@ -1424,8 +1424,8 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
// TODO: This distance should be calculated from the point that the cursor pointing at, instead of the center of the block
// Distance from the block's center to the player's eye height
double Dist = (Vector3d(a_BlockX, a_BlockY, a_BlockZ) + Vector3d(0.5, 0.5, 0.5) - m_Player->GetEyePosition()).Length();
- LOGD("HandleRightClick: {%d, %d, %d}, face %d, Hand: %d, HeldItem: %s; Dist: %.02f",
- a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Hand, ItemToFullString(HeldItem).c_str(), Dist
+ FLOGD("HandleRightClick: {0}, face {1}, Hand: {2}, HeldItem: {3}; Dist: {4:.02f}",
+ Vector3i{a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace, a_Hand, ItemToFullString(HeldItem), Dist
);
// Check the reach distance:
@@ -2789,8 +2789,8 @@ void cClientHandle::SendPlayerMaxSpeed(void)
void cClientHandle::SendPlayerMoveLook(void)
{
/*
- LOGD("Sending PlayerMoveLook: {%0.2f, %0.2f, %0.2f}, stance %0.2f, OnGround: %d",
- m_Player->GetPosX(), m_Player->GetPosY(), m_Player->GetPosZ(), m_Player->GetStance(), m_Player->IsOnGround() ? 1 : 0
+ FLOGD("Sending PlayerMoveLook: {0:0.2f}, stance {1:0.2f}, OnGround: {2}",
+ m_Player->GetPosition(), m_Player->GetStance(), m_Player->IsOnGround()
);
*/
m_Protocol->SendPlayerMoveLook();
diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp
index 2db0baad6..0fc0f095d 100644
--- a/src/Entities/ArrowEntity.cpp
+++ b/src/Entities/ArrowEntity.cpp
@@ -25,9 +25,8 @@ cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a
SetAirDrag(0.2f);
SetYawFromSpeed();
SetPitchFromSpeed();
- LOGD("Created arrow %d with speed {%.02f, %.02f, %.02f} and rot {%.02f, %.02f}",
- m_UniqueID, GetSpeedX(), GetSpeedY(), GetSpeedZ(),
- GetYaw(), GetPitch()
+ FLOGD("Created arrow {0} with speed {1:.02f} and rot {{{2:.02f}, {3:.02f}}}",
+ m_UniqueID, GetSpeed(), GetYaw(), GetPitch()
);
}
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 4c9900aa9..c0c381d41 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -88,12 +88,12 @@ cEntity::~cEntity()
/*
// DEBUG:
- LOGD("Deleting entity %d at pos {%.2f, %.2f, %.2f} ~ [%d, %d]; ptr %p",
+ FLOGD("Deleting entity {0} at pos {1:.2f} ~ [{2}, {3}]; ptr {4}",
m_UniqueID,
- m_Pos.x, m_Pos.y, m_Pos.z,
- (int)(m_Pos.x / cChunkDef::Width), (int)(m_Pos.z / cChunkDef::Width),
- this
- );
+ m_Pos,
+ GetChunkX(), GetChunkZ(),
+ static_cast<void *>(this)
+ );
*/
if (m_AttachedTo != nullptr)
@@ -146,8 +146,8 @@ bool cEntity::Initialize(OwnedEntity a_Self, cWorld & a_EntityWorld)
/*
// DEBUG:
- LOGD("Initializing entity #%d (%s) at {%.02f, %.02f, %.02f}",
- m_UniqueID, GetClass(), m_Pos.x, m_Pos.y, m_Pos.z
+ FLOGD("Initializing entity #{0} ({1}) at {2:.02f}",
+ m_UniqueID, GetClass(), m_Pos
);
*/
@@ -992,8 +992,8 @@ void cEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
/*
// DEBUG:
- LOGD("Entity #%d (%s) is inside a block at {%d, %d, %d}",
- m_UniqueID, GetClass(), BlockX, BlockY, BlockZ
+ FLOGD("Entity #{0} ({1}) is inside a block at {{2}}",
+ m_UniqueID, GetClass(), Vector3i{BlockX, BlockY, BlockZ}
);
*/
}
diff --git a/src/Entities/FallingBlock.cpp b/src/Entities/FallingBlock.cpp
index cbbb97202..0e03d50ce 100644
--- a/src/Entities/FallingBlock.cpp
+++ b/src/Entities/FallingBlock.cpp
@@ -71,11 +71,11 @@ void cFallingBlock::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
// Fallen onto a solid block
/*
- LOGD(
- "Sand: Checked below at {%d, %d, %d} (rel {%d, %d, %d}), it's %s, finishing the fall.",
- BlockX, BlockY, BlockZ,
- BlockX - a_Chunk.GetPosX() * cChunkDef::Width, BlockY, BlockZ - a_Chunk.GetPosZ() * cChunkDef::Width,
- ItemTypeToString(BlockBelow).c_str()
+ FLOGD(
+ "Sand: Checked below at {0} (rel {1}), it's {2}, finishing the fall.",
+ Vector3i{BlockX, BlockY, BlockZ},
+ cChunkDef::AbsoluteToRelative({BlockX, BlockY, BlockZ}, {a_Chunk.GetPosX(), a_Chunk.GetPosZ()}),
+ ItemTypeToString(BlockBelow)
);
*/
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index cd1414adb..044b802b7 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -150,8 +150,8 @@ cPlayer::cPlayer(cClientHandlePtr a_Client, const AString & a_PlayerName) :
SetWorld(World); // Use default world
- LOGD("Player \"%s\" is connecting for the first time, spawning at default world spawn {%.2f, %.2f, %.2f}",
- a_PlayerName.c_str(), GetPosX(), GetPosY(), GetPosZ()
+ FLOGD("Player \"{0}\" is connecting for the first time, spawning at default world spawn {1:.2f}",
+ a_PlayerName, GetPosition()
);
}
@@ -2256,8 +2256,8 @@ bool cPlayer::LoadFromFile(const AString & a_FileName, cWorldPtr & a_World)
cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetDataPath(), GetName(), GetUUID().ToLongString(), &m_Stats);
StatSerializer.Load();
- LOGD("Player %s was read from file \"%s\", spawning at {%.2f, %.2f, %.2f} in world \"%s\"",
- GetName().c_str(), a_FileName.c_str(), GetPosX(), GetPosY(), GetPosZ(), a_World->GetName().c_str()
+ FLOGD("Player {0} was read from file \"{1}\", spawning at {2:.2f} in world \"{3}\"",
+ GetName(), a_FileName, GetPosition(), a_World->GetName()
);
return true;
diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp
index 915475f2a..4a5da0874 100644
--- a/src/Entities/ProjectileEntity.cpp
+++ b/src/Entities/ProjectileEntity.cpp
@@ -60,11 +60,11 @@ protected:
{
/*
// DEBUG:
- LOGD("Hit block %d:%d at {%d, %d, %d} face %d, %s (%s)",
+ FLOGD("Hit block {0}:{1} at {2} face {3}, {4} ({5})",
a_BlockType, a_BlockMeta,
- a_BlockX, a_BlockY, a_BlockZ, a_EntryFace,
+ Vector3i{a_BlockX, a_BlockY, a_BlockZ}, a_EntryFace,
cBlockInfo::IsSolid(a_BlockType) ? "solid" : "non-solid",
- ItemToString(cItem(a_BlockType, 1, a_BlockMeta)).c_str()
+ ItemToString(cItem(a_BlockType, 1, a_BlockMeta))
);
*/
@@ -306,10 +306,8 @@ void cProjectileEntity::OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace)
SetSpeed(0, 0, 0);
// DEBUG:
- LOGD("Projectile %d: pos {%.02f, %.02f, %.02f}, hit solid block at face %d",
- m_UniqueID,
- a_HitPos.x, a_HitPos.y, a_HitPos.z,
- a_HitFace
+ FLOGD("Projectile {0}: pos {1:.02f}, hit solid block at face {2}",
+ m_UniqueID, a_HitPos, a_HitFace
);
m_IsInGround = true;
@@ -401,11 +399,11 @@ void cProjectileEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a
Vector3d HitPos = Pos + (NextPos - Pos) * EntityCollisionCallback.GetMinCoeff();
// DEBUG:
- LOGD("Projectile %d has hit an entity %d (%s) at {%.02f, %.02f, %.02f} (coeff %.03f)",
+ FLOGD("Projectile {0} has hit an entity {1} ({2}) at {3:.02f} (coeff {4:.03f})",
m_UniqueID,
EntityCollisionCallback.GetHitEntity()->GetUniqueID(),
EntityCollisionCallback.GetHitEntity()->GetClass(),
- HitPos.x, HitPos.y, HitPos.z,
+ HitPos,
EntityCollisionCallback.GetMinCoeff()
);
@@ -438,11 +436,8 @@ void cProjectileEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a
SetPitchFromSpeed();
/*
- LOGD("Projectile %d: pos {%.02f, %.02f, %.02f}, speed {%.02f, %.02f, %.02f}, rot {%.02f, %.02f}",
- m_UniqueID,
- GetPosX(), GetPosY(), GetPosZ(),
- GetSpeedX(), GetSpeedY(), GetSpeedZ(),
- GetYaw(), GetPitch()
+ FLOGD("Projectile {0}: pos {1:.02f}, speed {2:.02f}, rot {{{3:.02f}, {4:.02f}}}",
+ m_UniqueID, GetPos(), GetSpeed(), GetYaw(), GetPitch()
);
*/
}
diff --git a/src/Entities/TNTEntity.cpp b/src/Entities/TNTEntity.cpp
index f83384649..640684ace 100644
--- a/src/Entities/TNTEntity.cpp
+++ b/src/Entities/TNTEntity.cpp
@@ -35,7 +35,7 @@ void cTNTEntity::Explode(void)
{
m_FuseTicks = 0;
Destroy(true);
- LOGD("BOOM at {%f, %f, %f}", GetPosX(), GetPosY(), GetPosZ());
+ FLOGD("BOOM at {0}", GetPosition());
m_World->DoExplosionAt(4.0, GetPosX() + 0.49, GetPosY() + 0.49, GetPosZ() + 0.49, true, esPrimedTNT, this);
}
diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp
index ec5c0c144..3c608e026 100644
--- a/src/Generating/FinishGen.cpp
+++ b/src/Generating/FinishGen.cpp
@@ -1548,7 +1548,7 @@ bool cFinishGenPassiveMobs::TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int a_RelX
auto NewMob = cMonster::NewMonsterFromType(AnimalToSpawn);
NewMob->SetHealth(NewMob->GetMaxHealth());
NewMob->SetPosition(AnimalX, AnimalY, AnimalZ);
- LOGD("Spawning %s #%i at {%.02f, %.02f, %.02f}", NewMob->GetClass(), NewMob->GetUniqueID(), AnimalX, AnimalY, AnimalZ);
+ FLOGD("Spawning {0} #{1} at {2:.02f}", NewMob->GetClass(), NewMob->GetUniqueID(), NewMob->GetPosition());
a_ChunkDesc.GetEntities().emplace_back(std::move(NewMob));
return true;
@@ -1988,7 +1988,7 @@ void cFinishGenOrePockets::imprintSphere(
(blockZ >= baseZ) && (blockZ < baseZ + cChunkDef::Width)
)
{
- // LOGD("Imprinting a sphere center at {%d, %d, %d}", blockX, blockY, blockZ);
+ // FLOGD("Imprinting a sphere center at {0}", Vector3i{blockX, blockY, blockZ});
a_ChunkDesc.SetBlockTypeMeta(blockX - baseX, blockY, blockZ - baseZ, a_OreType, a_OreMeta);
}
return;
diff --git a/src/Generating/PieceGeneratorBFSTree.cpp b/src/Generating/PieceGeneratorBFSTree.cpp
index 1d0be3482..b6929d4b0 100644
--- a/src/Generating/PieceGeneratorBFSTree.cpp
+++ b/src/Generating/PieceGeneratorBFSTree.cpp
@@ -235,12 +235,11 @@ void cPieceGeneratorBFSTree::PlacePieces(int a_BlockX, int a_BlockZ, int a_MaxDe
/*
// DEBUG:
- printf("Placed the starting piece at {%d, %d, %d}\n", a_BlockX, a_BlockY, a_BlockZ);
+ FLOGD("Placed the starting piece at {0}", Vector3i{a_BlockX, a_BlockY, a_BlockZ});
cCuboid Hitbox = a_OutPieces[0]->GetHitBox();
Hitbox.Sort();
- printf(" Hitbox: {%d, %d, %d} - {%d, %d, %d} (%d * %d * %d)\n",
- Hitbox.p1.x, Hitbox.p1.y, Hitbox.p1.z,
- Hitbox.p2.x, Hitbox.p2.y, Hitbox.p2.z,
+ FLOGD(" Hitbox: {0} - {1} ({2} * {3} * {4})\n",
+ Hitbox.p1, Hitbox.p2,
Hitbox.DifX() + 1, Hitbox.DifY() + 1, Hitbox.DifZ() + 1
);
DebugConnectorPool(ConnectorPool, 0);
@@ -264,12 +263,11 @@ void cPieceGeneratorBFSTree::PlacePieces(int a_BlockX, int a_BlockZ, int a_MaxDe
// DEBUG:
const cPlacedPiece * NewPiece = a_OutPieces.back();
const Vector3i & Coords = NewPiece->GetCoords();
- printf("Placed a new piece at {%d, %d, %d}, rotation %d\n", Coords.x, Coords.y, Coords.z, NewPiece->GetNumCCWRotations());
+ FLOGD("Placed a new piece at {0}, rotation {1}\n", Coords, NewPiece->GetNumCCWRotations());
cCuboid Hitbox = NewPiece->GetHitBox();
Hitbox.Sort();
- printf(" Hitbox: {%d, %d, %d} - {%d, %d, %d} (%d * %d * %d)\n",
- Hitbox.p1.x, Hitbox.p1.y, Hitbox.p1.z,
- Hitbox.p2.x, Hitbox.p2.y, Hitbox.p2.z,
+ FLOGD(" Hitbox: {0} - {1} ({2} * {3} * {4})\n",
+ Hitbox.p1, Hitbox.p2,
Hitbox.DifX() + 1, Hitbox.DifY() + 1, Hitbox.DifZ() + 1
);
DebugConnectorPool(ConnectorPool, NumProcessed + 1);
diff --git a/src/Generating/PrefabPiecePool.cpp b/src/Generating/PrefabPiecePool.cpp
index 16d1f3440..ed5283dec 100644
--- a/src/Generating/PrefabPiecePool.cpp
+++ b/src/Generating/PrefabPiecePool.cpp
@@ -498,9 +498,12 @@ bool cPrefabPiecePool::ReadConnectorsCubesetVer1(
!cPiece::cConnector::StringToDirection(DirectionStr, Direction)
)
{
- CONDWARNING(a_LogWarnings, "Piece %s in file %s has a malformed Connector at index %d ({%d, %d, %d}, type %d, direction %s). Skipping the connector.",
- a_PieceName.c_str(), a_FileName.c_str(), idx, RelX, RelY, RelZ, Type, DirectionStr.c_str()
- );
+ if (a_LogWarnings)
+ {
+ FLOGWARNING("Piece {0} in file {1} has a malformed Connector at index {2} ({3}, type {4}, direction {5}). Skipping the connector.",
+ a_PieceName, a_FileName, idx, Vector3i{RelX, RelY, RelZ}, Type, DirectionStr
+ );
+ }
res = false;
lua_pop(a_LuaState, 1); // stk: [Connectors]
idx += 1;
diff --git a/src/Items/ItemDoor.h b/src/Items/ItemDoor.h
index 9cf67dd0e..7c2f81ef9 100644
--- a/src/Items/ItemDoor.h
+++ b/src/Items/ItemDoor.h
@@ -89,10 +89,10 @@ public:
BLOCKTYPE RightNeighborBlock = a_World.GetBlock(RightNeighborPos);
/*
// DEBUG:
- LOGD("Door being placed at {%d, %d, %d}", a_BlockX, a_BlockY, a_BlockZ);
- LOGD("RelDirToOutside: {%d, %d, %d}", RelDirToOutside.x, RelDirToOutside.y, RelDirToOutside.z);
- LOGD("Left neighbor at {%d, %d, %d}: %d (%s)", LeftNeighborPos.x, LeftNeighborPos.y, LeftNeighborPos.z, LeftNeighborBlock, ItemTypeToString(LeftNeighborBlock).c_str());
- LOGD("Right neighbor at {%d, %d, %d}: %d (%s)", RightNeighborPos.x, RightNeighborPos.y, RightNeighborPos.z, RightNeighborBlock, ItemTypeToString(RightNeighborBlock).c_str());
+ FLOGD("Door being placed at {0}", Vector3i{a_BlockX, a_BlockY, a_BlockZ});
+ FLOGD("RelDirToOutside: {0}", RelDirToOutside);
+ FLOGD("Left neighbor at {0}: {1} ({2})", LeftNeighborPos, LeftNeighborBlock, ItemTypeToString(LeftNeighborBlock));
+ FLOGD("Right neighbor at {0}: {1} ({2})", RightNeighborPos, RightNeighborBlock, ItemTypeToString(RightNeighborBlock));
*/
if (
cBlockDoorHandler::IsDoorBlockType(LeftNeighborBlock) || // The block to the left is a door block
diff --git a/src/NetherPortalScanner.cpp b/src/NetherPortalScanner.cpp
index cd1a0a62c..4b457de17 100644
--- a/src/NetherPortalScanner.cpp
+++ b/src/NetherPortalScanner.cpp
@@ -275,7 +275,7 @@ void cNetherPortalScanner::OnDisabled(void)
if (!m_FoundPortal)
{
// Build a new nether portal.
- LOGD("Building nether portal at {%d, %d, %d}", m_PortalLoc.x, m_PortalLoc.y, m_PortalLoc.z);
+ FLOGD("Building nether portal at {0}", m_PortalLoc);
BuildNetherPortal(m_PortalLoc, m_Dir, m_BuildPlatform);
m_PortalLoc.x += 1;
m_PortalLoc.y += 2;
@@ -295,7 +295,7 @@ void cNetherPortalScanner::OnDisabled(void)
Position.z += OutOffset;
}
- LOGD("Placing player at {%f, %f, %f}", Position.x, Position.y, Position.z);
+ FLOGD("Placing player at {0}", Position);
m_Entity->ScheduleMoveToWorld(m_World, Position, true);
delete this;
}
diff --git a/src/SetChunkData.cpp b/src/SetChunkData.cpp
index fad61ef1a..60a27d43a 100644
--- a/src/SetChunkData.cpp
+++ b/src/SetChunkData.cpp
@@ -137,10 +137,10 @@ void cSetChunkData::RemoveInvalidBlockEntities(void)
if (EntityBlockType != WorldBlockType)
{
// Bad blocktype, remove the block entity:
- LOGD("Block entity blocktype mismatch at {%d, %d, %d}: entity for blocktype %s(%d) in block %s(%d). Deleting the block entity.",
- BlockEntity->GetPosX(), BlockEntity->GetPosY(), BlockEntity->GetPosZ(),
- ItemTypeToString(EntityBlockType).c_str(), EntityBlockType,
- ItemTypeToString(WorldBlockType).c_str(), WorldBlockType
+ FLOGD("Block entity blocktype mismatch at {0}: entity for blocktype {1}({2}) in block {3}({4}). Deleting the block entity.",
+ BlockEntity->GetPos(),
+ ItemTypeToString(EntityBlockType), EntityBlockType,
+ ItemTypeToString(WorldBlockType), WorldBlockType
);
delete BlockEntity;
itr = m_BlockEntities.erase(itr);
diff --git a/src/Simulator/FireSimulator.cpp b/src/Simulator/FireSimulator.cpp
index df2456455..9a00d00a8 100644
--- a/src/Simulator/FireSimulator.cpp
+++ b/src/Simulator/FireSimulator.cpp
@@ -14,9 +14,9 @@
// Easy switch for turning on debugging logging:
#if 0
- #define FIRE_LOG LOGD
+ #define FIRE_FLOG FLOGD
#else
- #define FIRE_LOG(...)
+ #define FIRE_FLOG(...)
#endif
@@ -111,9 +111,7 @@ void cFireSimulator::SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX,
if (!IsAllowedBlock(BlockType))
{
// The block is no longer eligible (not a fire block anymore; a player probably placed a block over the fire)
- FIRE_LOG("FS: Removing block {%d, %d, %d}",
- AbsPos.x, AbsPos.y, AbsPos.z
- );
+ FIRE_FLOG("FS: Removing block {0}", AbsPos);
itr = Data.erase(itr);
continue;
}
@@ -148,16 +146,16 @@ void cFireSimulator::SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX,
}
/*
- FIRE_LOG("FS: Fire at {%d, %d, %d} is stepping",
- itr->x + a_ChunkX * cChunkDef::Width, itr->y, itr->z + a_ChunkZ * cChunkDef::Width
+ FIRE_FLOG("FS: Fire at {0} is stepping",
+ a_Chunk->PositionToWorldPosition(itr->x, itr->y, itr->z)
);
*/
// Has the fire burnt out?
if (BlockMeta == 0x0f)
{
// The fire burnt out completely
- FIRE_LOG("FS: Fire at {%d, %d, %d} burnt out, removing the fire block",
- itr->x + a_ChunkX * cChunkDef::Width, itr->y, itr->z + a_ChunkZ * cChunkDef::Width
+ FIRE_FLOG("FS: Fire at {0} burnt out, removing the fire block",
+ a_Chunk->PositionToWorldPosition({itr->x, itr->y, itr->z})
);
a_Chunk->SetBlock(x, y, z, E_BLOCK_AIR, 0);
RemoveFuelNeighbors(a_Chunk, x, y, z);
@@ -272,7 +270,7 @@ void cFireSimulator::AddBlock(Vector3i a_Block, cChunk * a_Chunk)
}
} // for itr - ChunkData[]
- FIRE_LOG("FS: Adding block {%d, %d, %d}", a_Block.x, a_Block.y, a_Block.z);
+ FIRE_FLOG("FS: Adding block {0}", a_Block);
ChunkData.push_back(cCoordWithInt(RelX, a_Block.y, RelZ, 100));
}
@@ -352,8 +350,8 @@ void cFireSimulator::TrySpreadFire(cChunk * a_Chunk, int a_RelX, int a_RelY, int
// Start the fire in the neighbor {x, y, z}
/*
- FIRE_LOG("FS: Trying to start fire at {%d, %d, %d}.",
- x + a_Chunk->GetPosX() * cChunkDef::Width, y, z + a_Chunk->GetPosZ() * cChunkDef::Width
+ FIRE_LOG("FS: Trying to start fire at {0}.",
+ a_Chunk->PositionToWorldPosition(x, y, z)
);
*/
if (CanStartFireInBlock(a_Chunk, x, y, z))
@@ -366,7 +364,7 @@ void cFireSimulator::TrySpreadFire(cChunk * a_Chunk, int a_RelX, int a_RelY, int
return;
}
- FIRE_LOG("FS: Starting new fire at {%d, %d, %d}.", a_PosX, y, a_PosZ);
+ FIRE_FLOG("FS: Starting new fire at {0}.", Vector3i{a_PosX, y, a_PosZ});
a_Chunk->UnboundedRelSetBlock(x, y, z, E_BLOCK_FIRE, 0);
}
} // for y
diff --git a/src/Simulator/FloodyFluidSimulator.cpp b/src/Simulator/FloodyFluidSimulator.cpp
index 8d5a3a8ae..7066dc016 100644
--- a/src/Simulator/FloodyFluidSimulator.cpp
+++ b/src/Simulator/FloodyFluidSimulator.cpp
@@ -20,9 +20,9 @@
// Enable or disable detailed logging
#if 0
- #define FLUID_LOG LOGD
+ #define FLUID_FLOG FLOGD
#else
- #define FLUID_LOG(...)
+ #define FLUID_FLOG(...)
#endif
@@ -49,8 +49,8 @@ cFloodyFluidSimulator::cFloodyFluidSimulator(
void cFloodyFluidSimulator::SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ)
{
- FLUID_LOG("Simulating block {%d, %d, %d}: block %d, meta %d",
- a_Chunk->GetPosX() * cChunkDef::Width + a_RelX, a_RelY, a_Chunk->GetPosZ() * cChunkDef::Width + a_RelZ,
+ FLUID_FLOG("Simulating block {0}: block {1}, meta {2}",
+ a_Chunk->PositionToWorldPosition(a_RelX, a_RelY, a_RelZ),
a_Chunk->GetBlock(a_RelX, a_RelY, a_RelZ),
a_Chunk->GetMeta(a_RelX, a_RelY, a_RelZ)
);
@@ -61,7 +61,7 @@ void cFloodyFluidSimulator::SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_Re
if (!IsAnyFluidBlock(MyBlock))
{
// Can happen - if a block is scheduled for simulating and gets replaced in the meantime.
- FLUID_LOG(" BadBlockType exit");
+ FLUID_FLOG(" BadBlockType exit");
return;
}
@@ -79,7 +79,7 @@ void cFloodyFluidSimulator::SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_Re
{
// Has no tributary, has been decreased (in CheckTributaries()),
// no more processing needed (neighbors have been scheduled by the decrease)
- FLUID_LOG(" CheckTributaries exit");
+ FLUID_FLOG(" CheckTributaries exit");
return;
}
}
@@ -154,7 +154,7 @@ bool cFloodyFluidSimulator::CheckTributaries(cChunk * a_Chunk, int a_RelX, int a
if (IsAnyFluidBlock(a_Chunk->GetBlock(a_RelX, a_RelY + 1, a_RelZ)))
{
// This block is fed from above, no more processing needed
- FLUID_LOG(" Fed from above");
+ FLUID_FLOG(" Fed from above");
return false;
}
}
@@ -180,10 +180,8 @@ bool cFloodyFluidSimulator::CheckTributaries(cChunk * a_Chunk, int a_RelX, int a
if (IsAllowedBlock(BlockType) && IsHigherMeta(BlockMeta, a_MyMeta))
{
// This block is fed, no more processing needed
- FLUID_LOG(" Fed from {%d, %d, %d}, type %d, meta %d",
- a_Chunk->GetPosX() * cChunkDef::Width + a_RelX + Coords[i].x,
- a_RelY,
- a_Chunk->GetPosZ() * cChunkDef::Width + a_RelZ + Coords[i].z,
+ FLUID_FLOG(" Fed from {0}, type {1}, meta {2}",
+ a_Chunk->PositionToWorldPosition(a_RelX+ Coords[i].x, a_RelY, a_RelZ + Coords[i].z),
BlockType, BlockMeta
);
return false;
@@ -194,7 +192,7 @@ bool cFloodyFluidSimulator::CheckTributaries(cChunk * a_Chunk, int a_RelX, int a
// Block is not fed, decrease by m_Falloff levels:
if (a_MyMeta >= 8)
{
- FLUID_LOG(" Not fed and downwards, turning into non-downwards meta %d", m_Falloff);
+ FLUID_FLOG(" Not fed and downwards, turning into non-downwards meta {0}", m_Falloff);
a_Chunk->SetBlock(a_RelX, a_RelY, a_RelZ, m_StationaryFluidBlock, m_Falloff);
}
else
@@ -202,12 +200,12 @@ bool cFloodyFluidSimulator::CheckTributaries(cChunk * a_Chunk, int a_RelX, int a
a_MyMeta += m_Falloff;
if (a_MyMeta < 8)
{
- FLUID_LOG(" Not fed, decreasing from %d to %d", a_MyMeta - m_Falloff, a_MyMeta);
+ FLUID_FLOG(" Not fed, decreasing from {0} to {1}", a_MyMeta - m_Falloff, a_MyMeta);
a_Chunk->SetBlock(a_RelX, a_RelY, a_RelZ, m_StationaryFluidBlock, a_MyMeta);
}
else
{
- FLUID_LOG(" Not fed, meta %d, erasing altogether", a_MyMeta);
+ FLUID_FLOG(" Not fed, meta {0}, erasing altogether", a_MyMeta);
a_Chunk->SetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_AIR, 0);
}
}
@@ -253,9 +251,8 @@ void cFloodyFluidSimulator::SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, i
{
// Lava flowing into water, change to stone / cobblestone based on direction:
BLOCKTYPE NewBlock = (a_NewMeta == 8) ? E_BLOCK_STONE : E_BLOCK_COBBLESTONE;
- FLUID_LOG(" Lava flowing into water, turning water at rel {%d, %d, %d} into stone",
- a_RelX, a_RelY, a_RelZ,
- ItemTypeToString(NewBlock).c_str()
+ FLUID_FLOG(" Lava flowing into water, turning water at rel {0} into {1}",
+ Vector3i{a_RelX, a_RelY, a_RelZ}, ItemTypeToString(NewBlock)
);
a_NearChunk->SetBlock(a_RelX, a_RelY, a_RelZ, NewBlock, 0);
@@ -274,8 +271,8 @@ void cFloodyFluidSimulator::SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, i
{
// Water flowing into lava, change to cobblestone / obsidian based on dest block:
BLOCKTYPE NewBlock = (BlockMeta == 0) ? E_BLOCK_OBSIDIAN : E_BLOCK_COBBLESTONE;
- FLUID_LOG(" Water flowing into lava, turning lava at rel {%d, %d, %d} into %s",
- a_RelX, a_RelY, a_RelZ, ItemTypeToString(NewBlock).c_str()
+ FLUID_FLOG(" Water flowing into lava, turning lava at rel {0} into {1}",
+ Vector3i{a_RelX, a_RelY, a_RelZ}, ItemTypeToString(NewBlock)
);
a_NearChunk->SetBlock(a_RelX, a_RelY, a_RelZ, NewBlock, 0);
@@ -320,7 +317,7 @@ void cFloodyFluidSimulator::SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, i
} // if (CanWashAway)
// Spread:
- FLUID_LOG(" Spreading to {%d, %d, %d} with meta %d", BlockX, a_RelY, BlockZ, a_NewMeta);
+ FLUID_FLOG(" Spreading to {0} with meta {1}", Vector3i{BlockX, a_RelY, BlockZ}, a_NewMeta);
a_NearChunk->SetBlock(a_RelX, a_RelY, a_RelZ, m_FluidBlock, a_NewMeta);
m_World.GetSimulatorManager()->WakeUp({BlockX, a_RelY, BlockZ}, a_NearChunk);
@@ -333,7 +330,7 @@ void cFloodyFluidSimulator::SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, i
bool cFloodyFluidSimulator::CheckNeighborsForSource(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ)
{
- FLUID_LOG(" Checking neighbors for source creation");
+ FLUID_FLOG(" Checking neighbors for source creation");
static const Vector3i NeighborCoords[] =
{
@@ -356,21 +353,21 @@ bool cFloodyFluidSimulator::CheckNeighborsForSource(cChunk * a_Chunk, int a_RelX
// Neighbor not available, skip it
continue;
}
- // FLUID_LOG(" Neighbor at {%d, %d, %d}: %s", x, y, z, ItemToFullString(cItem(BlockType, 1, BlockMeta)).c_str());
+ // FLUID_FLOG(" Neighbor at {0}: {1}", Vector3i{x, y, z}, ItemToFullString(cItem(BlockType, 1, BlockMeta)));
if ((BlockMeta == 0) && IsAnyFluidBlock(BlockType))
{
NumNeeded--;
- // FLUID_LOG(" Found a neighbor source at {%d, %d, %d}, NumNeeded := %d", x, y, z, NumNeeded);
+ // FLUID_FLOG(" Found a neighbor source at {0}, NumNeeded := {1}", Vector3i{x, y, z}, NumNeeded);
if (NumNeeded == 0)
{
// Found enough, turn into a source and bail out
- // FLUID_LOG(" Found enough neighbor sources, turning into a source");
+ // FLUID_FLOG(" Found enough neighbor sources, turning into a source");
a_Chunk->SetBlock(a_RelX, a_RelY, a_RelZ, m_FluidBlock, 0);
return true;
}
}
}
- // FLUID_LOG(" Not enough neighbors for turning into a source, NumNeeded = %d", NumNeeded);
+ // FLUID_FLOG(" Not enough neighbors for turning into a source, NumNeeded = {0}", NumNeeded);
return false;
}
diff --git a/src/Simulator/SandSimulator.cpp b/src/Simulator/SandSimulator.cpp
index 53dc3f94d..a75ea2d11 100644
--- a/src/Simulator/SandSimulator.cpp
+++ b/src/Simulator/SandSimulator.cpp
@@ -55,9 +55,9 @@ void cSandSimulator::SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX,
Pos.y = itr->y;
Pos.z = itr->z + BaseZ;
/*
- LOGD(
- "Creating a falling block at {%d, %d, %d} of type %s, block below: %s",
- Pos.x, Pos.y, Pos.z, ItemTypeToString(BlockType).c_str(), ItemTypeToString(BlockBelow).c_str()
+ FLOGD(
+ "Creating a falling block at {0} of type {1}, block below: {2}",
+ Pos, ItemTypeToString(BlockType), ItemTypeToString(BlockBelow)
);
*/
diff --git a/src/Vector3.h b/src/Vector3.h
index cb39a6cde..0456b9e2f 100644
--- a/src/Vector3.h
+++ b/src/Vector3.h
@@ -350,6 +350,22 @@ public:
z = -z;
}
+ // tolua_end
+
+ /** Allows formatting a Vector<T> using the same format specifiers as for T
+ e.g. `fmt::format("{0:0.2f}", Vector3f{0.0231f, 1.2146f, 1.0f}) == "{0.02, 1.21, 1.00}"` */
+ template <typename ArgFormatter>
+ friend void format_arg(fmt::BasicFormatter<char, ArgFormatter> & a_Formatter, const char *& a_FormatStr, Vector3 a_Vec)
+ {
+ std::array<T, 3> Data{{a_Vec.x, a_Vec.y, a_Vec.z}};
+
+ a_Formatter.writer() << '{';
+ fmt::format_arg(a_Formatter, a_FormatStr, fmt::join(Data.cbegin(), Data.cend(), ", "));
+ a_Formatter.writer() << '}';
+ }
+
+ // tolua_begin
+
/** The max difference between two coords for which the coords are assumed equal. */
static const double EPS;
diff --git a/src/World.cpp b/src/World.cpp
index c832f7386..2b151af8e 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -605,7 +605,7 @@ bool cWorld::SetSpawn(double a_X, double a_Y, double a_Z)
m_SpawnX = a_X;
m_SpawnY = a_Y;
m_SpawnZ = a_Z;
- LOGD("Spawn set at {%f, %f, %f}", m_SpawnX, m_SpawnY, m_SpawnZ);
+ FLOGD("Spawn set at {0}", Vector3d{m_SpawnX, m_SpawnY, m_SpawnZ});
return true;
}
else
@@ -695,7 +695,7 @@ void cWorld::GenerateRandomSpawn(int a_MaxSpawnRadius)
{
SetSpawn(BiomeOffset.x + 0.5, SpawnY, BiomeOffset.z + 0.5);
- LOGINFO("World \"%s\": Generated spawnpoint position at {%.2f, %.2f, %.2f}", m_WorldName, m_SpawnX, m_SpawnY, m_SpawnZ);
+ FLOGINFO("World \"{0}\": Generated spawnpoint position at {1:.2f}", m_WorldName, Vector3d{m_SpawnX, m_SpawnY, m_SpawnZ});
return;
}
@@ -729,14 +729,14 @@ void cWorld::GenerateRandomSpawn(int a_MaxSpawnRadius)
cChunkDef::BlockToChunk(static_cast<int>(m_SpawnX), static_cast<int>(m_SpawnZ), ChunkX, ChunkZ);
cSpawnPrepare::PrepareChunks(*this, ChunkX, ChunkZ, a_MaxSpawnRadius);
- LOGINFO("World \"%s\":Generated spawnpoint position at {%.2f, %.2f, %.2f}", m_WorldName, m_SpawnX, m_SpawnY, m_SpawnZ);
+ FLOGINFO("World \"{0}\":Generated spawnpoint position at {1:.2f}", m_WorldName, Vector3d{m_SpawnX, m_SpawnY, m_SpawnZ});
return;
}
}
}
m_SpawnY = GetHeight(static_cast<int>(m_SpawnX), static_cast<int>(m_SpawnZ));
- LOGWARNING("World \"%s\": Did not find an acceptable spawnpoint. Generated a random spawnpoint position at {%.2f, %.2f, %.2f}", m_WorldName, m_SpawnX, m_SpawnY, m_SpawnZ);
+ FLOGWARNING("World \"{0}\": Did not find an acceptable spawnpoint. Generated a random spawnpoint position at {1:.2f}", m_WorldName, Vector3d{m_SpawnX, m_SpawnY, m_SpawnZ});
}
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index db4af6032..d2f3284f5 100755
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -727,10 +727,10 @@ cBlockEntity * cWSSAnvil::LoadBlockEntityFromNBT(const cParsedNBT & a_NBT, int a
{
TypeName.assign(a_NBT.GetData(TagID), static_cast<size_t>(a_NBT.GetDataLength(TagID)));
}
- LOGINFO("WorldLoader(%s): Block entity mismatch: block type %s (%d), type \"%s\", at {%d, %d, %d}; the entity will be lost.",
- m_World->GetName().c_str(),
- ItemTypeToString(a_BlockType).c_str(), a_BlockType, TypeName.c_str(),
- a_BlockX, a_BlockY, a_BlockZ
+ LOGINFO("WorldLoader({0}): Block entity mismatch: block type {1} ({2}), type \"{3}\", at {4}; the entity will be lost.",
+ m_World->GetName(),
+ ItemTypeToString(a_BlockType), a_BlockType, TypeName,
+ Vector3i{a_BlockX, a_BlockY, a_BlockZ}
);
return nullptr;
}
@@ -937,10 +937,10 @@ bool cWSSAnvil::CheckBlockEntityType(const cParsedNBT & a_NBT, int a_TagIdx, con
expectedTypes.append(et);
expectedTypes.push_back('\"');
}
- LOGWARNING("Block entity type mismatch: exp %s, got \"%s\". The block entity at {%d, %d, %d} will lose all its properties.",
+ LOGWARNING("Block entity type mismatch: exp {0}, got \"{1}\". The block entity at {2} will lose all its properties.",
expectedTypes.c_str() + 2, // Skip the first ", " that is extra in the string
- AString(a_NBT.GetData(TagID), static_cast<size_t>(a_NBT.GetDataLength(TagID))).c_str(),
- a_BlockX, a_BlockY, a_BlockZ
+ AString(a_NBT.GetData(TagID), static_cast<size_t>(a_NBT.GetDataLength(TagID))),
+ Vector3i{a_BlockX, a_BlockY, a_BlockZ}
);
return false;
}