Skip to content

Commit

Permalink
Merge branch 'cuberite:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
iamtakingithard committed Mar 26, 2023
2 parents a72abad + fddbf65 commit 71912df
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Cuberite is a Minecraft-compatible multiplayer game server that is written in C++ and designed to be efficient with memory and CPU, as well as having a flexible Lua Plugin API. Cuberite is compatible with the Java Edition Minecraft client.

Cuberite runs on Windows, *nix and Android operating systems. This includes Android phones and tablets as well as Raspberry Pis.
Cuberite runs on Windows, *nix and Android operating systems. This includes Android phones and tablets as well as Raspberry Pis; support for small embedded devices is experimental.

Currently we support Release 1.8 - 1.12.2 Minecraft protocol versions.

Expand Down
4 changes: 4 additions & 0 deletions Server/Plugins/APIDump/APIDesc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5375,6 +5375,10 @@ ValueName0=SomeOtherValue
insert values by hand. Then you can store the object's contents to a disk file using WriteFile(), or
just forget everything by destroying the object. Note that the file operations are quite slow.</p>
<p>
Cuberite will write the characters '\n' in place of line breaks in the values of the cIniFile when
it is being stored into a file. It will also replace '\n' with line breaks when it reads an INI
file.
<p>
For storing high-volume low-latency data, use the {{sqlite3}} class. For storing
hierarchically-structured data, use the XML format, using the LuaExpat parser in the {{lxp}} class.
]],
Expand Down
30 changes: 12 additions & 18 deletions src/BlockEntities/BrewingstandEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,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;
}
Expand Down Expand Up @@ -117,15 +111,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
Expand Down Expand Up @@ -234,9 +228,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();
Expand All @@ -246,14 +240,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
Expand Down Expand Up @@ -323,13 +317,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;
Expand Down
6 changes: 3 additions & 3 deletions src/BlockEntities/BrewingstandEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class cBrewingstandEntity :
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); }
Expand Down Expand Up @@ -118,10 +118,10 @@ class cBrewingstandEntity :
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;
Expand Down
6 changes: 3 additions & 3 deletions src/BlockEntities/DropSpenserEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,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())
Expand All @@ -65,7 +65,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))
Expand Down
15 changes: 7 additions & 8 deletions src/BlockEntities/SignEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down Expand Up @@ -59,27 +56,29 @@ 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;
}





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];
}

Expand Down
6 changes: 3 additions & 3 deletions src/BlockEntities/SignEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ class cSignEntity :
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

Expand All @@ -48,5 +48,5 @@ class cSignEntity :

private:

AString m_Line[4];
std::array<AString, 4> m_Line;
} ; // tolua_export
6 changes: 5 additions & 1 deletion src/IniFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect)
{
valuename = line.substr(0, pLeft);
value = TrimString(line.substr(pLeft + 1));
ReplaceString(value, "\\n", "\n");
AddValue(keyname, valuename, value);
break;
}
Expand Down Expand Up @@ -191,6 +192,7 @@ bool cIniFile::WriteFile(const AString & a_FileName) const
// Normally you would use ofstream, but the SGI CC compiler has
// a few bugs with ofstream. So ... fstream used.
fstream f;
AString writevalue;

f.open((a_FileName).c_str(), ios::out);
if (f.fail())
Expand Down Expand Up @@ -223,7 +225,9 @@ bool cIniFile::WriteFile(const AString & a_FileName) const
// Values.
for (size_t valueID = 0; valueID < m_Keys[keyID].m_Names.size(); ++valueID)
{
f << m_Keys[keyID].m_Names[valueID] << '=' << m_Keys[keyID].m_Values[valueID] << iniEOL;
writevalue = m_Keys[keyID].m_Values[valueID];
ReplaceString(writevalue, "\n", "\\n");
f << m_Keys[keyID].m_Names[valueID] << '=' << writevalue << iniEOL;
}
f << iniEOL;
}
Expand Down

0 comments on commit 71912df

Please sign in to comment.