From b355bdeccecf727d30e48634df9b5d424db570bc Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Mon, 4 Jun 2012 12:08:20 +0000 Subject: Added the new recipe parser, parsing the crafting.txt file. Included are a few recipes. The old parser still works, but will be replaced soon. git-svn-id: http://mc-server.googlecode.com/svn/trunk@549 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/BlockID.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'source/BlockID.cpp') 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: -- cgit v1.2.3