summaryrefslogtreecommitdiffstats
path: root/src/CraftingRecipes.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-08-28 16:35:56 +0200
committerMattes D <github@xoft.cz>2014-08-28 16:35:56 +0200
commite931b649ac7915de1326d1dc124503383d82d3cf (patch)
tree3065edcd8277ee6f375ee433498fd6f6a67fe620 /src/CraftingRecipes.cpp
parentFixed a typo. (diff)
parentFinal template keyword style fix. (diff)
downloadcuberite-e931b649ac7915de1326d1dc124503383d82d3cf.tar
cuberite-e931b649ac7915de1326d1dc124503383d82d3cf.tar.gz
cuberite-e931b649ac7915de1326d1dc124503383d82d3cf.tar.bz2
cuberite-e931b649ac7915de1326d1dc124503383d82d3cf.tar.lz
cuberite-e931b649ac7915de1326d1dc124503383d82d3cf.tar.xz
cuberite-e931b649ac7915de1326d1dc124503383d82d3cf.tar.zst
cuberite-e931b649ac7915de1326d1dc124503383d82d3cf.zip
Diffstat (limited to 'src/CraftingRecipes.cpp')
-rw-r--r--src/CraftingRecipes.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp
index 1a31a6e90..2d80ecaf8 100644
--- a/src/CraftingRecipes.cpp
+++ b/src/CraftingRecipes.cpp
@@ -83,7 +83,7 @@ cItem & cCraftingGrid::GetItem(int x, int y) const
-void cCraftingGrid::SetItem(int x, int y, ENUM_ITEM_ID a_ItemType, int a_ItemCount, short a_ItemHealth)
+void cCraftingGrid::SetItem(int x, int y, ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemHealth)
{
// Accessible through scripting, must verify parameters:
if ((x < 0) || (x >= m_Width) || (y < 0) || (y >= m_Height))
@@ -228,7 +228,7 @@ void cCraftingRecipe::Clear(void)
-void cCraftingRecipe::SetResult(ENUM_ITEM_ID a_ItemType, int a_ItemCount, short a_ItemHealth)
+void cCraftingRecipe::SetResult(ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemHealth)
{
m_Result = cItem(a_ItemType, a_ItemCount, a_ItemHealth);
}
@@ -324,7 +324,11 @@ void cCraftingRecipes::LoadRecipes(void)
return;
}
AString Everything;
- f.ReadRestOfFile(Everything);
+ if (!f.ReadRestOfFile(Everything))
+ {
+ LOGWARNING("Cannot read file \"crafting.txt\", no crafting recipes will be available!");
+ return;
+ }
f.Close();
// Split it into lines, then process each line as a single recipe:
@@ -388,8 +392,7 @@ void cCraftingRecipes::AddRecipeLine(int a_LineNum, const AString & a_RecipeLine
}
if (ResultSplit.size() > 1)
{
- Recipe->m_Result.m_ItemCount = atoi(ResultSplit[1].c_str());
- if (Recipe->m_Result.m_ItemCount == 0)
+ if (!StringToInteger<char>(ResultSplit[1].c_str(), Recipe->m_Result.m_ItemCount))
{
LOGWARNING("crafting.txt: line %d: Cannot parse result count, ignoring the recipe.", a_LineNum);
LOGINFO("Offending line: \"%s\"", a_RecipeLine.c_str());
@@ -441,8 +444,7 @@ bool cCraftingRecipes::ParseItem(const AString & a_String, cItem & a_Item)
if (Split.size() > 1)
{
AString Damage = TrimString(Split[1]);
- a_Item.m_ItemDamage = atoi(Damage.c_str());
- if ((a_Item.m_ItemDamage == 0) && (Damage.compare("0") != 0))
+ if (!StringToInteger<short>(Damage.c_str(), a_Item.m_ItemDamage))
{
// Parsing the number failed
return false;