Merge commit 'c747b4911ed4b1833d7f400d62d1835aba704278' into pullstream

This commit is contained in:
Rebekah 2024-02-13 19:55:05 -05:00
commit 0b758cb225
Signed by: oneechanhax
GPG Key ID: 183EB7902964DAE5
5 changed files with 28 additions and 35 deletions

View File

@ -45,14 +45,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;
}
@ -133,15 +127,15 @@ bool cBrewingstandEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
// Loop over all bottle slots and update available bottles
const cBrewingRecipes::cRecipe * Recipe = nullptr;
for (int i = 0; i < 3; i++)
for (std::size_t i = 0; i < 3; i++)
{
if (m_Contents.GetSlot(i).IsEmpty() || (m_CurrentBrewingRecipes[i] == nullptr))
if (m_Contents.GetSlot(static_cast<int>(i)).IsEmpty() || (m_CurrentBrewingRecipes[i] == nullptr))
{
continue;
}
Recipe = m_CurrentBrewingRecipes[i];
m_Contents.SetSlot(i, Recipe->Output.CopyOne());
m_Contents.SetSlot(static_cast<int>(i), Recipe->Output.CopyOne());
}
// Brewing process completed
@ -250,9 +244,9 @@ void cBrewingstandEntity::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum)
cBrewingRecipes * BR = cRoot::Get()->GetBrewingRecipes();
const cBrewingRecipes::cRecipe * Recipe = nullptr;
bool Stop = true;
for (int i = 0; i < 3; i++)
for (std::size_t i = 0; i < 3; i++)
{
if (GetSlot(i).IsEmpty())
if (GetSlot(static_cast<int>(i)).IsEmpty())
{
m_CurrentBrewingRecipes[i] = nullptr;
m_Results[i].Clear();
@ -262,14 +256,14 @@ void cBrewingstandEntity::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum)
if (m_CurrentBrewingRecipes[i] != nullptr)
{
Recipe = m_CurrentBrewingRecipes[i];
if (Recipe->Ingredient.IsEqual(GetSlot(bsIngredient)) && Recipe->Input.IsEqual(GetSlot(i)))
if (Recipe->Ingredient.IsEqual(GetSlot(bsIngredient)) && Recipe->Input.IsEqual(GetSlot(static_cast<int>(i))))
{
Stop = false;
continue;
}
}
Recipe = BR->GetRecipeFrom(m_Contents.GetSlot(i), m_Contents.GetSlot(bsIngredient));
Recipe = BR->GetRecipeFrom(m_Contents.GetSlot(static_cast<int>(i)), m_Contents.GetSlot(bsIngredient));
if (Recipe != nullptr)
{
// Found a brewing recipe for the items
@ -339,13 +333,13 @@ void cBrewingstandEntity::LoadRecipes(void)
cBrewingRecipes * BR = cRoot::Get()->GetBrewingRecipes();
const cBrewingRecipes::cRecipe * Recipe = nullptr;
for (int i = 0; i < 3; i++)
for (std::size_t i = 0; i < 3; i++)
{
if (GetSlot(i).IsEmpty())
if (GetSlot(static_cast<int>(i)).IsEmpty())
{
continue;
}
Recipe = BR->GetRecipeFrom(GetSlot(i), GetSlot(bsIngredient));
Recipe = BR->GetRecipeFrom(GetSlot(static_cast<int>(i)), GetSlot(bsIngredient));
if (Recipe != nullptr)
{
m_CurrentBrewingRecipes[i] = Recipe;

View File

@ -94,7 +94,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); }
@ -134,10 +134,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;

View File

@ -63,8 +63,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())
@ -81,7 +81,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))

View File

@ -43,10 +43,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;
}
@ -75,13 +72,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;
}
@ -89,13 +87,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];
}

View File

@ -50,10 +50,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
@ -64,5 +64,5 @@ public: // tolua_export
private:
AString m_Line[4];
std::array<AString, 4> m_Line;
} ; // tolua_export