diff options
author | Perttu Ahola <celeron55@gmail.com> | 2011-07-31 02:20:40 +0300 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2011-07-31 02:20:40 +0300 |
commit | d6a9bec8430e39b380d3fc7b1f92683d4d02c33e (patch) | |
tree | 6918d2f27174b3bc49ad4fcc301653d53adefd51 /src/inventory.cpp | |
parent | 306bb667908bae69d2c68ede64ef9007fd25fb78 (diff) | |
download | minetest-d6a9bec8430e39b380d3fc7b1f92683d4d02c33e.tar.gz minetest-d6a9bec8430e39b380d3fc7b1f92683d4d02c33e.tar.bz2 minetest-d6a9bec8430e39b380d3fc7b1f92683d4d02c33e.zip |
Added MaterialItem conversion from old content type namespace to new
Diffstat (limited to 'src/inventory.cpp')
-rw-r--r-- | src/inventory.cpp | 27 |
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); |