is>>count;
// Convert old materials
if(material <= 0xff)
- {
material = content_translate_from_19_to_internal(material);
- }
if(material > MAX_CONTENT)
throw SerializationError("Too large material number");
return new MaterialItem(gamedef, material, count);
throw SerializationError("Too large material number");
return new MaterialItem(gamedef, material, count);
}
- else if(name == "MaterialItem3")
+ else if(name == "NodeItem" || name == "MaterialItem3")
{
std::string all;
std::getline(is, all, '\n');
+ std::string nodename;
+ // First attempt to read inside ""
Strfnd fnd(all);
fnd.next("\"");
- std::string nodename = fnd.next("\"");
+ // If didn't skip to end, we have ""s
+ if(!fnd.atend()){
+ nodename = fnd.next("\"");
+ } else { // No luck, just read a word then
+ fnd.start(all);
+ nodename = fnd.next(" ");
+ }
+ fnd.skip_over(" ");
u16 count = stoi(trim(fnd.next("")));
return new MaterialItem(gamedef, nodename, count);
}
}
else if(name == "CraftItem")
{
+ std::string all;
+ std::getline(is, all, '\n');
std::string subname;
- std::getline(is, subname, ' ');
- u16 count;
- is>>count;
+ // First attempt to read inside ""
+ Strfnd fnd(all);
+ fnd.next("\"");
+ // If didn't skip to end, we have ""s
+ if(!fnd.atend()){
+ subname = fnd.next("\"");
+ } else { // No luck, just read a word then
+ fnd.start(all);
+ subname = fnd.next(" ");
+ }
+ // Then read count
+ fnd.skip_over(" ");
+ u16 count = stoi(trim(fnd.next("")));
return new CraftItem(gamedef, subname, count);
}
else if(name == "ToolItem")
{
+ std::string all;
+ std::getline(is, all, '\n');
std::string toolname;
- std::getline(is, toolname, ' ');
- u16 wear;
- is>>wear;
+ // First attempt to read inside ""
+ Strfnd fnd(all);
+ fnd.next("\"");
+ // If didn't skip to end, we have ""s
+ if(!fnd.atend()){
+ toolname = fnd.next("\"");
+ } else { // No luck, just read a word then
+ fnd.start(all);
+ toolname = fnd.next(" ");
+ }
+ // Then read wear
+ fnd.skip_over(" ");
+ u16 wear = stoi(trim(fnd.next("")));
return new ToolItem(gamedef, toolname, wear);
}
else
}
virtual void serialize(std::ostream &os) const
{
- std::string nodename = m_nodename;
- if(nodename == "")
- nodename = "unknown_block";
-
- os<<"MaterialItem3";
+ os<<"NodeItem";
os<<" \"";
- os<<nodename;
+ os<<m_nodename;
os<<"\" ";
os<<m_count;
-
- // Old
- /*os<<"MaterialItem2";
- os<<" ";
- os<<(unsigned int)m_content;
- os<<" ";
- os<<m_count;*/
}
virtual InventoryItem* clone()
{
virtual void serialize(std::ostream &os) const
{
os<<getName();
- os<<" ";
+ os<<" \"";
os<<m_subname;
- os<<" ";
+ os<<"\" ";
os<<m_count;
}
virtual InventoryItem* clone()
virtual void serialize(std::ostream &os) const
{
os<<getName();
- os<<" ";
+ os<<" \"";
os<<m_toolname;
- os<<" ";
+ os<<"\" ";
os<<m_wear;
}
virtual InventoryItem* clone()