summaryrefslogtreecommitdiff
path: root/src/inventory.cpp
diff options
context:
space:
mode:
authorLoïc Blot <loic.blot@unix-experience.fr>2017-06-06 16:19:04 +0200
committerLoïc Blot <loic.blot@unix-experience.fr>2017-06-06 16:19:04 +0200
commit8bdde45895658f16aa6b2546ccb59c5c4c9fc699 (patch)
tree33fd9c49f42a0f9a3194d68c74aee1c99ab6cec4 /src/inventory.cpp
parentfee5171298606d928d0f718d8ec0eeb2cacc1e71 (diff)
downloadminetest-8bdde45895658f16aa6b2546ccb59c5c4c9fc699.tar.gz
minetest-8bdde45895658f16aa6b2546ccb59c5c4c9fc699.tar.bz2
minetest-8bdde45895658f16aa6b2546ccb59c5c4c9fc699.zip
Revert "Remove deprecated code segments (#5891)"
This reverts commit 599e13e95e81aadb959c9f3715aec9b425ede084.
Diffstat (limited to 'src/inventory.cpp')
-rw-r--r--src/inventory.cpp163
1 files changed, 141 insertions, 22 deletions
diff --git a/src/inventory.cpp b/src/inventory.cpp
index b4d1b4dd9..8617f7263 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -24,6 +24,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "log.h"
#include "itemdef.h"
#include "util/strfnd.h"
+#include "content_mapnode.h" // For loading legacy MaterialItems
+#include "nameidmapping.h" // For loading legacy MaterialItems
#include "util/serialize.h"
#include "util/string.h"
@@ -31,6 +33,18 @@ with this program; if not, write to the Free Software Foundation, Inc.,
ItemStack
*/
+static content_t content_translate_from_19_to_internal(content_t c_from)
+{
+ for(u32 i=0; i<sizeof(trans_table_19)/sizeof(trans_table_19[0]); i++)
+ {
+ if(trans_table_19[i][1] == c_from)
+ {
+ return trans_table_19[i][0];
+ }
+ }
+ return c_from;
+}
+
ItemStack::ItemStack(const std::string &name_, u16 count_,
u16 wear_, IItemDefManager *itemdef) :
name(itemdef->getAlias(name_)),
@@ -85,35 +99,140 @@ void ItemStack::deSerialize(std::istream &is, IItemDefManager *itemdef)
if(!tmp.empty())
throw SerializationError("Unexpected text after item name");
- do { // This loop is just to allow "break;"
- // The real thing
-
- // Apply item aliases
+ if(name == "MaterialItem")
+ {
+ // Obsoleted on 2011-07-30
+
+ u16 material;
+ is>>material;
+ u16 materialcount;
+ is>>materialcount;
+ // Convert old materials
+ if(material <= 0xff)
+ material = content_translate_from_19_to_internal(material);
+ if(material > 0xfff)
+ throw SerializationError("Too large material number");
+ // Convert old id to name
+ NameIdMapping legacy_nimap;
+ content_mapnode_get_name_id_mapping(&legacy_nimap);
+ legacy_nimap.getName(material, name);
+ if(name == "")
+ name = "unknown_block";
if (itemdef)
name = itemdef->getAlias(name);
-
- // Read the count
- std::string count_str;
- std::getline(is, count_str, ' ');
- if (count_str.empty()) {
+ count = materialcount;
+ }
+ else if(name == "MaterialItem2")
+ {
+ // Obsoleted on 2011-11-16
+
+ u16 material;
+ is>>material;
+ u16 materialcount;
+ is>>materialcount;
+ if(material > 0xfff)
+ throw SerializationError("Too large material number");
+ // Convert old id to name
+ NameIdMapping legacy_nimap;
+ content_mapnode_get_name_id_mapping(&legacy_nimap);
+ legacy_nimap.getName(material, name);
+ if(name == "")
+ name = "unknown_block";
+ if (itemdef)
+ name = itemdef->getAlias(name);
+ count = materialcount;
+ }
+ else if(name == "node" || name == "NodeItem" || name == "MaterialItem3"
+ || name == "craft" || name == "CraftItem")
+ {
+ // Obsoleted on 2012-01-07
+
+ std::string all;
+ std::getline(is, all, '\n');
+ // First attempt to read inside ""
+ Strfnd fnd(all);
+ fnd.next("\"");
+ // If didn't skip to end, we have ""s
+ if(!fnd.at_end()){
+ name = fnd.next("\"");
+ } else { // No luck, just read a word then
+ fnd.start(all);
+ name = fnd.next(" ");
+ }
+ fnd.skip_over(" ");
+ if (itemdef)
+ name = itemdef->getAlias(name);
+ count = stoi(trim(fnd.next("")));
+ if(count == 0)
count = 1;
- break;
- } else {
- count = stoi(count_str);
+ }
+ else if(name == "MBOItem")
+ {
+ // Obsoleted on 2011-10-14
+ throw SerializationError("MBOItem not supported anymore");
+ }
+ else if(name == "tool" || name == "ToolItem")
+ {
+ // Obsoleted on 2012-01-07
+
+ std::string all;
+ std::getline(is, all, '\n');
+ // First attempt to read inside ""
+ Strfnd fnd(all);
+ fnd.next("\"");
+ // If didn't skip to end, we have ""s
+ if(!fnd.at_end()){
+ name = fnd.next("\"");
+ } else { // No luck, just read a word then
+ fnd.start(all);
+ name = fnd.next(" ");
}
+ count = 1;
+ // Then read wear
+ fnd.skip_over(" ");
+ if (itemdef)
+ name = itemdef->getAlias(name);
+ wear = stoi(trim(fnd.next("")));
+ }
+ else
+ {
+ do // This loop is just to allow "break;"
+ {
+ // The real thing
+
+ // Apply item aliases
+ if (itemdef)
+ name = itemdef->getAlias(name);
+
+ // Read the count
+ std::string count_str;
+ std::getline(is, count_str, ' ');
+ if(count_str.empty())
+ {
+ count = 1;
+ break;
+ }
+ else
+ count = stoi(count_str);
- // Read the wear
- std::string wear_str;
- std::getline(is, wear_str, ' ');
- if (wear_str.empty())
- break;
- else
- wear = stoi(wear_str);
+ // Read the wear
+ std::string wear_str;
+ std::getline(is, wear_str, ' ');
+ if(wear_str.empty())
+ break;
+ else
+ wear = stoi(wear_str);
- // Read metadata
- metadata.deSerialize(is);
+ // Read metadata
+ metadata.deSerialize(is);
- } while(false);
+ // In case fields are added after metadata, skip space here:
+ //std::getline(is, tmp, ' ');
+ //if(!tmp.empty())
+ // throw SerializationError("Unexpected text after metadata");
+
+ } while(false);
+ }
if (name.empty() || count == 0)
clear();