summaryrefslogtreecommitdiff
path: root/src/inventory.cpp
diff options
context:
space:
mode:
authorNils Dagsson Moskopp <nils@dieweltistgarnichtso.net>2011-07-31 20:04:04 +0200
committerNils Dagsson Moskopp <nils@dieweltistgarnichtso.net>2011-07-31 20:04:04 +0200
commit7ece67727dcc1ff7a6634e4b911eeb82ed3eaf45 (patch)
treeb06cf63fb0c8d01f03c1fb84faa936197029e03f /src/inventory.cpp
parent831003156c77c811e7f1fcb65811d1d099587442 (diff)
parent303351de6d2cb54af27198207ba6c8cef49ecf1a (diff)
downloadminetest-7ece67727dcc1ff7a6634e4b911eeb82ed3eaf45.tar.gz
minetest-7ece67727dcc1ff7a6634e4b911eeb82ed3eaf45.tar.bz2
minetest-7ece67727dcc1ff7a6634e4b911eeb82ed3eaf45.zip
Merge remote-tracking branch 'origin/upstream'
Diffstat (limited to 'src/inventory.cpp')
-rw-r--r--src/inventory.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/inventory.cpp b/src/inventory.cpp
index ca050614f..30a43e37f 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -46,6 +46,18 @@ InventoryItem::~InventoryItem()
{
}
+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;
+}
+
InventoryItem* InventoryItem::deSerialize(std::istream &is)
{
DSTACK(__FUNCTION_NAME);
@@ -62,6 +74,21 @@ InventoryItem* InventoryItem::deSerialize(std::istream &is)
is>>material;
u16 count;
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(material, count);
+ }
+ else if(name == "MaterialItem2")
+ {
+ u16 material;
+ is>>material;
+ u16 count;
+ is>>count;
if(material > MAX_CONTENT)
throw SerializationError("Too large material number");
return new MaterialItem(material, count);