summaryrefslogtreecommitdiff
path: root/src/nodemetadata.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-04-05 10:59:48 +0300
committerPerttu Ahola <celeron55@gmail.com>2011-04-05 10:59:48 +0300
commitd6d811f97bc921b11da735fda15b07de180b298b (patch)
tree32d09f6763819253ac78901f236d5fb5396cc1ae /src/nodemetadata.cpp
parentd1d57cf5c34c9a4626fd8e3b40db3ea321b40335 (diff)
downloadminetest-d6d811f97bc921b11da735fda15b07de180b298b.tar.gz
minetest-d6d811f97bc921b11da735fda15b07de180b298b.tar.bz2
minetest-d6d811f97bc921b11da735fda15b07de180b298b.zip
A more robust format for node metadata
Diffstat (limited to 'src/nodemetadata.cpp')
-rw-r--r--src/nodemetadata.cpp38
1 files changed, 27 insertions, 11 deletions
diff --git a/src/nodemetadata.cpp b/src/nodemetadata.cpp
index 21f55a0ca..21b4ed01d 100644
--- a/src/nodemetadata.cpp
+++ b/src/nodemetadata.cpp
@@ -177,7 +177,7 @@ FurnaceNodeMetadata::FurnaceNodeMetadata()
m_inventory = new Inventory();
m_inventory->addList("fuel", 1);
m_inventory->addList("src", 1);
- m_inventory->addList("dst", 1);
+ m_inventory->addList("dst", 4);
m_step_accumulator = 0;
m_fuel_totaltime = 0;
@@ -202,12 +202,15 @@ NodeMetadata* FurnaceNodeMetadata::clone()
NodeMetadata* FurnaceNodeMetadata::create(std::istream &is)
{
FurnaceNodeMetadata *d = new FurnaceNodeMetadata();
+
d->m_inventory->deSerialize(is);
+
int temp;
is>>temp;
d->m_fuel_totaltime = (float)temp/10;
is>>temp;
d->m_fuel_time = (float)temp/10;
+
return d;
}
void FurnaceNodeMetadata::serializeBody(std::ostream &os)
@@ -260,9 +263,10 @@ bool FurnaceNodeMetadata::step(float dtime)
InventoryList *src_list = m_inventory->getList("src");
assert(src_list);
InventoryItem *src_item = src_list->getItem(0);
-
- if(ItemSpec(ITEM_MATERIAL, CONTENT_TREE).checkItem(src_item)
- && dst_list->itemFits(0, new CraftItem("lump_of_coal", 1)))
+
+ // Start only if there are free slots in dst, so that it can
+ // accomodate any result item
+ if(dst_list->getFreeSlots() > 0)
{
m_src_totaltime = 3;
}
@@ -279,13 +283,11 @@ bool FurnaceNodeMetadata::step(float dtime)
m_src_time += dtime;
if(m_src_time >= m_src_totaltime && m_src_totaltime > 0.001)
{
- if(ItemSpec(ITEM_MATERIAL, CONTENT_TREE).checkItem(src_item))
- {
- src_list->decrementMaterials(1);
- dst_list->addItem(0, new CraftItem("lump_of_coal", 1));
- m_src_time = 0;
- m_src_totaltime = 0;
- }
+ src_list->decrementMaterials(1);
+ InventoryItem *cookresult = src_item->createCookResult();
+ dst_list->addItem(cookresult);
+ m_src_time = 0;
+ m_src_totaltime = 0;
}
return true;
}
@@ -340,6 +342,10 @@ void NodeMetadataList::serialize(std::ostream &os)
{
u8 buf[6];
+ u16 version = 1;
+ writeU16(buf, version);
+ os.write((char*)buf, 2);
+
u16 count = m_data.size();
writeU16(buf, count);
os.write((char*)buf, 2);
@@ -366,6 +372,16 @@ void NodeMetadataList::deSerialize(std::istream &is)
u8 buf[6];
is.read((char*)buf, 2);
+ u16 version = readU16(buf);
+
+ if(version > 1)
+ {
+ dstream<<__FUNCTION_NAME<<": version "<<version<<" not supported"
+ <<std::endl;
+ throw SerializationError("NodeMetadataList::deSerialize");
+ }
+
+ is.read((char*)buf, 2);
u16 count = readU16(buf);
for(u16 i=0; i<count; i++)