summaryrefslogtreecommitdiffstats
path: root/source/BlockID.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-06-04 14:08:20 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-06-04 14:08:20 +0200
commitb355bdeccecf727d30e48634df9b5d424db570bc (patch)
tree00489a1317e6ad22a28698f24bd9935160257789 /source/BlockID.cpp
parentFixed MSVC2010 projects for new zlib (diff)
downloadcuberite-b355bdeccecf727d30e48634df9b5d424db570bc.tar
cuberite-b355bdeccecf727d30e48634df9b5d424db570bc.tar.gz
cuberite-b355bdeccecf727d30e48634df9b5d424db570bc.tar.bz2
cuberite-b355bdeccecf727d30e48634df9b5d424db570bc.tar.lz
cuberite-b355bdeccecf727d30e48634df9b5d424db570bc.tar.xz
cuberite-b355bdeccecf727d30e48634df9b5d424db570bc.tar.zst
cuberite-b355bdeccecf727d30e48634df9b5d424db570bc.zip
Diffstat (limited to '')
-rw-r--r--source/BlockID.cpp43
1 files changed, 42 insertions, 1 deletions
diff --git a/source/BlockID.cpp b/source/BlockID.cpp
index 989ca55a9..12771513f 100644
--- a/source/BlockID.cpp
+++ b/source/BlockID.cpp
@@ -6,6 +6,7 @@
#include "Globals.h"
#include "BlockID.h"
#include "../iniFile/iniFile.h"
+#include "cItem.h"
@@ -35,6 +36,11 @@ public:
return m_Ini.GetValueI("Items", a_ItemName, -1);
}
+ AString ResolveString(AString & a_ItemName)
+ {
+ return m_Ini.GetValue("Items", a_ItemName, "");
+ }
+
protected:
cIniFile m_Ini;
} ;
@@ -58,12 +64,47 @@ int BlockStringToType(const AString & a_BlockTypeString)
return res;
}
- return gsBlockIDMap.Resolve(a_BlockTypeString);
+ return gsBlockIDMap.Resolve(TrimString(a_BlockTypeString));
+}
+
+
+
+
+bool StringToItem(const AString & a_ItemTypeString, cItem & a_Item)
+{
+ AString Resolved = TrimString(gsBlockIDMap.ResolveString(TrimString(a_ItemTypeString)));
+ AString txt = (!Resolved.empty()) ? Resolved : a_ItemTypeString;
+ AStringVector Split = StringSplit(txt, ":");
+ if (Split.size() == 1)
+ {
+ Split = StringSplit(txt, "^");
+ }
+ if (Split.empty())
+ {
+ return false;
+ }
+ a_Item.m_ItemID = (ENUM_ITEM_ID)atoi(Split[0].c_str());
+ if ((a_Item.m_ItemID == 0) && (Split[0] != "0"))
+ {
+ // Parsing the number failed
+ return false;
+ }
+ if (Split.size() > 1)
+ {
+ a_Item.m_ItemHealth = atoi(Split[1].c_str());
+ if ((a_Item.m_ItemHealth == 0) && (Split[1] != "0"))
+ {
+ // Parsing the number failed
+ return false;
+ }
+ }
+ return true;
}
+
EMCSBiome StringToBiome(const AString & a_BiomeString)
{
// If it is a number, return it: