summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2020-05-04 12:50:02 +0200
committerTiger Wang <ziwei.tiger@outlook.com>2020-05-04 14:29:56 +0200
commiteb3ca16921080b1496d2e71de95ce533929241e1 (patch)
treee1dc67df2493c8e36ea34f473f4184e0576c0440
parentFix incorrect formatter invocation (diff)
downloadcuberite-eb3ca16921080b1496d2e71de95ce533929241e1.tar
cuberite-eb3ca16921080b1496d2e71de95ce533929241e1.tar.gz
cuberite-eb3ca16921080b1496d2e71de95ce533929241e1.tar.bz2
cuberite-eb3ca16921080b1496d2e71de95ce533929241e1.tar.lz
cuberite-eb3ca16921080b1496d2e71de95ce533929241e1.tar.xz
cuberite-eb3ca16921080b1496d2e71de95ce533929241e1.tar.zst
cuberite-eb3ca16921080b1496d2e71de95ce533929241e1.zip
Diffstat (limited to '')
-rw-r--r--src/Generating/VerticalLimit.cpp63
-rw-r--r--src/Generating/VerticalStrategy.cpp61
-rw-r--r--src/Protocol/Protocol_1_11.cpp8
-rw-r--r--src/Protocol/Protocol_1_12.cpp8
-rw-r--r--src/Protocol/Protocol_1_8.cpp10
-rw-r--r--src/Protocol/Protocol_1_9.cpp6
6 files changed, 79 insertions, 77 deletions
diff --git a/src/Generating/VerticalLimit.cpp b/src/Generating/VerticalLimit.cpp
index 0d27c85bf..f6b1b456c 100644
--- a/src/Generating/VerticalLimit.cpp
+++ b/src/Generating/VerticalLimit.cpp
@@ -30,36 +30,39 @@ If a_LogWarnings is true, outputs failure reasons to console.
The range is returned in a_Min and a_Max.
If no value is in the string, both values are left unchanged.
If only the minimum is in the string, it is assigned to both a_Min and a_Max. */
-static bool ParseRange(const AString & a_Params, int & a_Min, int & a_Max, bool a_LogWarnings)
+namespace VerticalLimit
{
- auto params = StringSplitAndTrim(a_Params, "|");
- if (params.size() == 0)
+ static bool ParseRange(const AString & a_Params, int & a_Min, int & a_Max, bool a_LogWarnings)
{
- // No params, generate directly on top:
- return true;
- }
- if (!StringToInteger(params[0], a_Min))
- {
- // Failed to parse the min rel height:
- CONDWARNING(a_LogWarnings, "Cannot parse minimum height from string \"%s\"!", params[0].c_str());
- return false;
- }
- if (params.size() == 1)
- {
- // Only one param was given, there's no range
- a_Max = a_Min;
+ auto params = StringSplitAndTrim(a_Params, "|");
+ if (params.size() == 0)
+ {
+ // No params, generate directly on top:
+ return true;
+ }
+ if (!StringToInteger(params[0], a_Min))
+ {
+ // Failed to parse the min rel height:
+ CONDWARNING(a_LogWarnings, "Cannot parse minimum height from string \"%s\"!", params[0].c_str());
+ return false;
+ }
+ if (params.size() == 1)
+ {
+ // Only one param was given, there's no range
+ a_Max = a_Min;
+ return true;
+ }
+ if (!StringToInteger(params[1], a_Max))
+ {
+ CONDWARNING(a_LogWarnings, "Cannot parse maximum height from string \"%s\"!", params[1].c_str());
+ return false;
+ }
+ if (a_Max < a_Min)
+ {
+ std::swap(a_Max, a_Min);
+ }
return true;
}
- if (!StringToInteger(params[1], a_Max))
- {
- CONDWARNING(a_LogWarnings, "Cannot parse maximum height from string \"%s\"!", params[1].c_str());
- return false;
- }
- if (a_Max < a_Min)
- {
- std::swap(a_Max, a_Min);
- }
- return true;
}
@@ -144,7 +147,7 @@ public:
// Parameters: "<MinBlocksAbove>|<MaxBlocksAbove>", both optional
m_MinBlocksAbove = 0;
m_MaxBlocksAbove = 0;
- return ParseRange(a_Params, m_MinBlocksAbove, m_MaxBlocksAbove, a_LogWarnings);
+ return VerticalLimit::ParseRange(a_Params, m_MinBlocksAbove, m_MaxBlocksAbove, a_LogWarnings);
}
@@ -191,7 +194,7 @@ public:
// Parameters: "<MinBlocksAbove>|<MaxBlocksAbove>", both optional
m_MinBlocksAbove = 0;
m_MaxBlocksAbove = 0;
- return ParseRange(a_Params, m_MinBlocksAbove, m_MaxBlocksAbove, a_LogWarnings);
+ return VerticalLimit::ParseRange(a_Params, m_MinBlocksAbove, m_MaxBlocksAbove, a_LogWarnings);
}
@@ -275,7 +278,7 @@ public:
// Parameters: "<MinBlocksBelow>|<MaxBlocksBelow>", both optional
m_MinBlocksBelow = 0;
m_MaxBlocksBelow = 0;
- return ParseRange(a_Params, m_MinBlocksBelow, m_MaxBlocksBelow, a_LogWarnings);
+ return VerticalLimit::ParseRange(a_Params, m_MinBlocksBelow, m_MaxBlocksBelow, a_LogWarnings);
}
@@ -321,7 +324,7 @@ public:
// Parameters: "<MinBlocksBelow>|<MaxBlocksBelow>", both optional
m_MinBlocksBelow = 0;
m_MaxBlocksBelow = 0;
- return ParseRange(a_Params, m_MinBlocksBelow, m_MaxBlocksBelow, a_LogWarnings);
+ return VerticalLimit::ParseRange(a_Params, m_MinBlocksBelow, m_MaxBlocksBelow, a_LogWarnings);
}
diff --git a/src/Generating/VerticalStrategy.cpp b/src/Generating/VerticalStrategy.cpp
index 6ca7cec9d..0651958f9 100644
--- a/src/Generating/VerticalStrategy.cpp
+++ b/src/Generating/VerticalStrategy.cpp
@@ -38,37 +38,40 @@ static const int SEED_OFFSET = 135;
Returns true if successful, false on failure.
If a_LogWarnings is true, outputs failure reasons to console.
The range is returned in a_Min and a_Range, they are left unchanged if the range value is not present in the string. */
-static bool ParseRange(const AString & a_Params, int & a_Min, int & a_Range, bool a_LogWarnings)
+namespace VerticalStrategy
{
- auto params = StringSplitAndTrim(a_Params, "|");
- if (params.size() == 0)
+ static bool ParseRange(const AString & a_Params, int & a_Min, int & a_Range, bool a_LogWarnings)
{
- // No params, generate directly on top:
- return true;
- }
- if (!StringToInteger(params[0], a_Min))
- {
- // Failed to parse the min rel height:
- CONDWARNING(a_LogWarnings, "Cannot parse minimum height from string \"%s\"!", params[0].c_str());
- return false;
- }
- if (params.size() == 1)
- {
- // Only one param was given, there's no range
+ auto params = StringSplitAndTrim(a_Params, "|");
+ if (params.size() == 0)
+ {
+ // No params, generate directly on top:
+ return true;
+ }
+ if (!StringToInteger(params[0], a_Min))
+ {
+ // Failed to parse the min rel height:
+ CONDWARNING(a_LogWarnings, "Cannot parse minimum height from string \"%s\"!", params[0].c_str());
+ return false;
+ }
+ if (params.size() == 1)
+ {
+ // Only one param was given, there's no range
+ return true;
+ }
+ int maxHeight = a_Min;
+ if (!StringToInteger(params[1], maxHeight))
+ {
+ CONDWARNING(a_LogWarnings, "Cannot parse maximum height from string \"%s\"!", params[1].c_str());
+ return false;
+ }
+ if (maxHeight < a_Min)
+ {
+ std::swap(maxHeight, a_Min);
+ }
+ a_Range = maxHeight - a_Min + 1;
return true;
}
- int maxHeight = a_Min;
- if (!StringToInteger(params[1], maxHeight))
- {
- CONDWARNING(a_LogWarnings, "Cannot parse maximum height from string \"%s\"!", params[1].c_str());
- return false;
- }
- if (maxHeight < a_Min)
- {
- std::swap(maxHeight, a_Min);
- }
- a_Range = maxHeight - a_Min + 1;
- return true;
}
@@ -202,7 +205,7 @@ public:
// Params: "<MinRelativeHeight>|<MaxRelativeHeight>", all optional
m_MinRelHeight = 0;
m_RelHeightRange = 1;
- return ParseRange(a_Params, m_MinRelHeight, m_RelHeightRange, a_LogWarnings);
+ return VerticalStrategy::ParseRange(a_Params, m_MinRelHeight, m_RelHeightRange, a_LogWarnings);
}
@@ -258,7 +261,7 @@ public:
// Params: "<MinRelativeHeight>|<MaxRelativeHeight>", all optional
m_MinRelHeight = 0;
m_RelHeightRange = 1;
- return ParseRange(a_Params, m_MinRelHeight, m_RelHeightRange, a_LogWarnings);
+ return VerticalStrategy::ParseRange(a_Params, m_MinRelHeight, m_RelHeightRange, a_LogWarnings);
}
diff --git a/src/Protocol/Protocol_1_11.cpp b/src/Protocol/Protocol_1_11.cpp
index 677662a6f..b12b45814 100644
--- a/src/Protocol/Protocol_1_11.cpp
+++ b/src/Protocol/Protocol_1_11.cpp
@@ -58,9 +58,9 @@ Implements the 1.11 protocol classes:
#pragma clang diagnostic ignored "-Wduplicate-enum"
#endif
-namespace Metadata
+namespace Metadata_1_11
{
- enum Metadata_Index
+ enum MetadataIndex
{
// Entity
ENTITY_FLAGS,
@@ -653,7 +653,7 @@ void cProtocol_1_11_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer)
void cProtocol_1_11_0::WriteEntityMetadata(cPacketizer & a_Pkt, const cEntity & a_Entity)
{
- using namespace Metadata;
+ using namespace Metadata_1_11;
// Common metadata:
Int8 Flags = 0;
@@ -860,7 +860,7 @@ void cProtocol_1_11_0::WriteEntityMetadata(cPacketizer & a_Pkt, const cEntity &
void cProtocol_1_11_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob)
{
- using namespace Metadata;
+ using namespace Metadata_1_11;
// Living Enitiy Metadata
if (a_Mob.HasCustomName())
diff --git a/src/Protocol/Protocol_1_12.cpp b/src/Protocol/Protocol_1_12.cpp
index 8cf8df6ca..d2e7b2071 100644
--- a/src/Protocol/Protocol_1_12.cpp
+++ b/src/Protocol/Protocol_1_12.cpp
@@ -42,9 +42,9 @@ Implements the 1.12 protocol classes:
#pragma clang diagnostic ignored "-Wduplicate-enum"
#endif
-namespace Metadata
+namespace Metadata_1_12
{
- enum Metadata_Index
+ enum MetadataIndex
{
// Entity
ENTITY_FLAGS,
@@ -372,7 +372,7 @@ void cProtocol_1_12::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer)
void cProtocol_1_12::WriteEntityMetadata(cPacketizer & a_Pkt, const cEntity & a_Entity)
{
- using namespace Metadata;
+ using namespace Metadata_1_12;
// Common metadata:
Int8 Flags = 0;
@@ -579,7 +579,7 @@ void cProtocol_1_12::WriteEntityMetadata(cPacketizer & a_Pkt, const cEntity & a_
void cProtocol_1_12::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob)
{
- using namespace Metadata;
+ using namespace Metadata_1_12;
// Living Enitiy Metadata
if (a_Mob.HasCustomName())
diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp
index 4aa312fef..fe2f80146 100644
--- a/src/Protocol/Protocol_1_8.cpp
+++ b/src/Protocol/Protocol_1_8.cpp
@@ -54,13 +54,6 @@ Implements the 1.8 protocol classes:
-/** The slot number that the client uses to indicate "outside the window". */
-static const Int16 SLOT_NUM_OUTSIDE = -999;
-
-
-
-
-
#define HANDLE_READ(ByteBuf, Proc, Type, Var) \
Type Var; \
do { \
@@ -2825,6 +2818,9 @@ void cProtocol_1_8_0::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
cItem Item;
ReadItem(a_ByteBuffer, Item);
+ /** The slot number that the client uses to indicate "outside the window". */
+ static const Int16 SLOT_NUM_OUTSIDE = -999;
+
// Convert Button, Mode, SlotNum and HeldItem into eClickAction:
eClickAction Action;
switch ((Mode << 8) | Button)
diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp
index 150e81339..ff62df242 100644
--- a/src/Protocol/Protocol_1_9.cpp
+++ b/src/Protocol/Protocol_1_9.cpp
@@ -58,9 +58,6 @@ Implements the 1.9 protocol classes:
-/** The slot number that the client uses to indicate "outside the window". */
-static const Int16 SLOT_NUM_OUTSIDE = -999;
-
/** Value for main hand in Hand parameter for Protocol 1.9. */
static const UInt32 MAIN_HAND = 0;
static const UInt32 OFF_HAND = 1;
@@ -1034,6 +1031,9 @@ void cProtocol_1_9_0::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
cItem Item;
ReadItem(a_ByteBuffer, Item);
+ /** The slot number that the client uses to indicate "outside the window". */
+ static const Int16 SLOT_NUM_OUTSIDE = -999;
+
// Convert Button, Mode, SlotNum and HeldItem into eClickAction:
eClickAction Action;
switch ((Mode << 8) | Button)