summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbibo38 <bibo38@github.com>2020-10-09 17:41:44 +0200
committerTiger Wang <ziwei.tiger@outlook.com>2020-10-20 12:45:58 +0200
commitc221aa3653c00cd2f942294690cbd21dea0daa85 (patch)
tree637c09ed878a789ceaf1395346d0d6f6f5cdb2c5
parentcBlockInfo: further cleanup (#5001) (diff)
downloadcuberite-CArrays.tar
cuberite-CArrays.tar.gz
cuberite-CArrays.tar.bz2
cuberite-CArrays.tar.lz
cuberite-CArrays.tar.xz
cuberite-CArrays.tar.zst
cuberite-CArrays.zip
Diffstat (limited to '')
-rw-r--r--src/BlockEntities/BrewingstandEntity.cpp30
-rw-r--r--src/BlockEntities/BrewingstandEntity.h6
-rw-r--r--src/BlockEntities/DropSpenserEntity.cpp6
-rw-r--r--src/BlockEntities/HopperEntity.cpp37
-rw-r--r--src/BlockEntities/SignEntity.cpp15
-rw-r--r--src/BlockEntities/SignEntity.h6
6 files changed, 50 insertions, 50 deletions
diff --git a/src/BlockEntities/BrewingstandEntity.cpp b/src/BlockEntities/BrewingstandEntity.cpp
index 9c43f257f..1c659a3c3 100644
--- a/src/BlockEntities/BrewingstandEntity.cpp
+++ b/src/BlockEntities/BrewingstandEntity.cpp
@@ -54,14 +54,8 @@ void cBrewingstandEntity::CopyFrom(const cBlockEntity & a_Src)
Super::CopyFrom(a_Src);
auto & src = static_cast<const cBrewingstandEntity &>(a_Src);
m_IsBrewing = src.m_IsBrewing;
- for (size_t i = 0; i < ARRAYCOUNT(m_CurrentBrewingRecipes); ++i)
- {
- m_CurrentBrewingRecipes[i] = src.m_CurrentBrewingRecipes[i];
- }
- for (size_t i = 0; i < ARRAYCOUNT(m_Results); ++i)
- {
- m_Results[i] = src.m_Results[i];
- }
+ m_CurrentBrewingRecipes = src.m_CurrentBrewingRecipes;
+ m_Results = src.m_Results;
m_TimeBrewed = src.m_TimeBrewed;
m_RemainingFuel = src.m_RemainingFuel;
}
@@ -130,12 +124,12 @@ bool cBrewingstandEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
const cBrewingRecipes::cRecipe * Recipe = nullptr;
for (int i = 0; i < 3; i++)
{
- if (m_Contents.GetSlot(i).IsEmpty() || (m_CurrentBrewingRecipes[i] == nullptr))
+ if (m_Contents.GetSlot(i).IsEmpty() || (m_CurrentBrewingRecipes[static_cast<size_t>(i)] == nullptr))
{
continue;
}
- Recipe = m_CurrentBrewingRecipes[i];
+ Recipe = m_CurrentBrewingRecipes[static_cast<size_t>(i)];
m_Contents.SetSlot(i, Recipe->Output.CopyOne());
}
@@ -254,14 +248,14 @@ void cBrewingstandEntity::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum)
{
if (GetSlot(i).IsEmpty())
{
- m_CurrentBrewingRecipes[i] = nullptr;
- m_Results[i].Clear();
+ m_CurrentBrewingRecipes[static_cast<size_t>(i)] = nullptr;
+ m_Results[static_cast<size_t>(i)].Clear();
continue;
}
- if (m_CurrentBrewingRecipes[i] != nullptr)
+ if (m_CurrentBrewingRecipes[static_cast<size_t>(i)] != nullptr)
{
- Recipe = m_CurrentBrewingRecipes[i];
+ Recipe = m_CurrentBrewingRecipes[static_cast<size_t>(i)];
if (Recipe->Ingredient.IsEqual(GetSlot(bsIngredient)) && Recipe->Input.IsEqual(GetSlot(i)))
{
Stop = false;
@@ -273,8 +267,8 @@ void cBrewingstandEntity::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum)
if (Recipe != nullptr)
{
// Found a brewing recipe for the items
- m_CurrentBrewingRecipes[i] = Recipe;
- m_Results[i] = Recipe->Output.CopyOne();
+ m_CurrentBrewingRecipes[static_cast<size_t>(i)] = Recipe;
+ m_Results[static_cast<size_t>(i)] = Recipe->Output.CopyOne();
Stop = false;
}
}
@@ -348,8 +342,8 @@ void cBrewingstandEntity::LoadRecipes(void)
Recipe = BR->GetRecipeFrom(GetSlot(i), GetSlot(bsIngredient));
if (Recipe != nullptr)
{
- m_CurrentBrewingRecipes[i] = Recipe;
- m_Results[i] = Recipe->Output.CopyOne();
+ m_CurrentBrewingRecipes[static_cast<size_t>(i)] = Recipe;
+ m_Results[static_cast<size_t>(i)] = Recipe->Output.CopyOne();
}
}
}
diff --git a/src/BlockEntities/BrewingstandEntity.h b/src/BlockEntities/BrewingstandEntity.h
index 90c6003df..5a78554ba 100644
--- a/src/BlockEntities/BrewingstandEntity.h
+++ b/src/BlockEntities/BrewingstandEntity.h
@@ -81,7 +81,7 @@ public:
const cItem & GetFuelSlot(void) const { return GetSlot(bsFuel); }
/** Get the expected result item for the given slot number */
- const cItem & GetResultItem(int a_SlotNumber) { return m_Results[a_SlotNumber]; }
+ const cItem & GetResultItem(size_t a_SlotNumber) { return m_Results[a_SlotNumber]; }
/** Sets the item in the left bottle slot */
void SetLeftBottleSlot(const cItem & a_Item) { SetSlot(bsLeftBottle, a_Item); }
@@ -125,10 +125,10 @@ protected:
const short m_NeedBrewingTime = 400;
/** Store the current brewing recipes */
- const cBrewingRecipes::cRecipe * m_CurrentBrewingRecipes[3] = {};
+ std::array<const cBrewingRecipes::cRecipe *, 3> m_CurrentBrewingRecipes = {};
/** Result items for the bottle inputs */
- cItem m_Results[3];
+ std::array<cItem, 3> m_Results;
/** Amount of ticks that the current item has been brewed */
short m_TimeBrewed;
diff --git a/src/BlockEntities/DropSpenserEntity.cpp b/src/BlockEntities/DropSpenserEntity.cpp
index 259cec7a3..ef793ddc7 100644
--- a/src/BlockEntities/DropSpenserEntity.cpp
+++ b/src/BlockEntities/DropSpenserEntity.cpp
@@ -61,8 +61,8 @@ void cDropSpenserEntity::AddDropSpenserDir(Vector3i & a_RelCoord, NIBBLETYPE a_D
void cDropSpenserEntity::DropSpense(cChunk & a_Chunk)
{
// Pick one of the occupied slots:
- int OccupiedSlots[9];
- int SlotsCnt = 0;
+ std::array<int, 9> OccupiedSlots;
+ size_t SlotsCnt = 0;
for (int i = m_Contents.GetNumSlots() - 1; i >= 0; i--)
{
if (!m_Contents.GetSlot(i).IsEmpty())
@@ -79,7 +79,7 @@ void cDropSpenserEntity::DropSpense(cChunk & a_Chunk)
return;
}
- const int RandomSlot = m_World->GetTickRandomNumber(SlotsCnt - 1);
+ const size_t RandomSlot = GetRandomProvider().RandInt(SlotsCnt - 1);
const int SpenseSlot = OccupiedSlots[RandomSlot];
if (cPluginManager::Get()->CallHookDropSpense(*m_World, *this, SpenseSlot))
diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp
index 2e4264204..616f1f7c7 100644
--- a/src/BlockEntities/HopperEntity.cpp
+++ b/src/BlockEntities/HopperEntity.cpp
@@ -383,14 +383,17 @@ bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk)
return true;
}
- // Check if the chest is a double-chest (chest directly above was empty), if so, try to move from there:
- static const Vector3i neighborOfs[] =
+ static constexpr std::array<Vector3i, 4> neighborOfs
{
- { 1, 1, 0},
- {-1, 1, 0},
- { 0, 1, 1},
- { 0, 1, -1},
- } ;
+ {
+ { 1, 1, 0 },
+ { -1, 1, 0 },
+ { 0, 1, 1 },
+ { 0, 1, -1 }
+ }
+ };
+
+ // Check if the chest is a double-chest (chest directly above was empty), if so, try to move from there:
for (const auto & ofs: neighborOfs)
{
auto neighborRelCoord = ofs.addedXZ(m_RelX, m_RelZ);
@@ -546,15 +549,19 @@ bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, Vector3i a_Coords)
return true;
}
+ static constexpr std::array<Vector3i, 4> neighborOfs =
+ {
+ {
+ { 1, 0, 0 },
+ { -1, 0, 0 },
+ { 0, 0, 1 },
+ { 0, 0, -1 }
+ }
+ };
+
+ const auto relCoord = a_Chunk.AbsoluteToRelative(a_Coords);
+
// Check if the chest is a double-chest (chest block directly connected was full), if so, try to move into the other half:
- static const Vector3i neighborOfs [] =
- {
- { 1, 0, 0},
- {-1, 0, 0},
- { 0, 0, 1},
- { 0, 0, -1},
- } ;
- auto relCoord = a_Chunk.AbsoluteToRelative(a_Coords);
for (const auto & ofs: neighborOfs)
{
auto otherHalfRelCoord = relCoord + ofs;
diff --git a/src/BlockEntities/SignEntity.cpp b/src/BlockEntities/SignEntity.cpp
index 30adcb9f9..c79a2bc72 100644
--- a/src/BlockEntities/SignEntity.cpp
+++ b/src/BlockEntities/SignEntity.cpp
@@ -27,10 +27,7 @@ void cSignEntity::CopyFrom(const cBlockEntity & a_Src)
{
Super::CopyFrom(a_Src);
auto & src = static_cast<const cSignEntity &>(a_Src);
- for (size_t i = 0; i < ARRAYCOUNT(m_Line); ++i)
- {
- m_Line[i] = src.m_Line[i];
- }
+ m_Line = src.m_Line;
}
@@ -59,13 +56,14 @@ void cSignEntity::SetLines(const AString & a_Line1, const AString & a_Line2, con
-void cSignEntity::SetLine(int a_Index, const AString & a_Line)
+void cSignEntity::SetLine(size_t a_Index, const AString & a_Line)
{
- if ((a_Index < 0) || (a_Index >= static_cast<int>(ARRAYCOUNT(m_Line))))
+ if (a_Index >= m_Line.size())
{
LOGWARNING("%s: setting a non-existent line %d (value \"%s\"", __FUNCTION__, a_Index, a_Line.c_str());
return;
}
+
m_Line[a_Index] = a_Line;
}
@@ -73,13 +71,14 @@ void cSignEntity::SetLine(int a_Index, const AString & a_Line)
-AString cSignEntity::GetLine(int a_Index) const
+AString cSignEntity::GetLine(size_t a_Index) const
{
- if ((a_Index < 0) || (a_Index >= static_cast<int>(ARRAYCOUNT(m_Line))))
+ if (a_Index >= m_Line.size())
{
LOGWARNING("%s: requesting a non-existent line %d", __FUNCTION__, a_Index);
return "";
}
+
return m_Line[a_Index];
}
diff --git a/src/BlockEntities/SignEntity.h b/src/BlockEntities/SignEntity.h
index 83eb0352d..94c5eba28 100644
--- a/src/BlockEntities/SignEntity.h
+++ b/src/BlockEntities/SignEntity.h
@@ -36,10 +36,10 @@ public: // tolua_export
void SetLines(const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4);
/** Sets individual line (zero-based index) */
- void SetLine(int a_Index, const AString & a_Line);
+ void SetLine(size_t a_Index, const AString & a_Line);
/** Retrieves individual line (zero-based index) */
- AString GetLine(int a_Index) const;
+ AString GetLine(size_t a_Index) const;
// tolua_end
@@ -50,7 +50,7 @@ public: // tolua_export
private:
- AString m_Line[4];
+ std::array<AString, 4> m_Line;
} ; // tolua_export