#include "debug.h"
#include <sstream>
#include "main.h"
+#include "serverobject.h"
/*
InventoryItem
}
}
+ServerActiveObject* InventoryItem::createSAO(ServerEnvironment *env, u16 id, v3f pos)
+{
+ /*
+ Create an ItemSAO
+ */
+ // Get item string
+ std::ostringstream os(std::ios_base::binary);
+ serialize(os);
+ // Create object
+ ServerActiveObject *obj = new ItemSAO(env, 0, pos, os.str());
+ return obj;
+}
+
+/*
+ MaterialItem
+*/
+
+bool MaterialItem::isCookable()
+{
+ if(m_content == CONTENT_TREE)
+ {
+ return true;
+ }
+ else if(m_content == CONTENT_COBBLE)
+ {
+ return true;
+ }
+ return false;
+}
+
+InventoryItem *MaterialItem::createCookResult()
+{
+ if(m_content == CONTENT_TREE)
+ {
+ return new CraftItem("lump_of_coal", 1);
+ }
+ else if(m_content == CONTENT_COBBLE)
+ {
+ return new MaterialItem(CONTENT_STONE, 1);
+ }
+ return NULL;
+}
+
+/*
+ CraftItem
+*/
+
+#ifndef SERVER
+video::ITexture * CraftItem::getImage()
+{
+ if(g_texturesource == NULL)
+ return NULL;
+
+ std::string name;
+
+ if(m_subname == "Stick")
+ name = "stick.png";
+ else if(m_subname == "lump_of_coal")
+ name = "lump_of_coal.png";
+ else if(m_subname == "lump_of_iron")
+ name = "lump_of_iron.png";
+ else if(m_subname == "steel_ingot")
+ name = "steel_ingot.png";
+ else if(m_subname == "rat")
+ name = "rat.png";
+ else
+ name = "cloud.png";
+
+ // Get such a texture
+ return g_texturesource->getTextureRaw(name);
+}
+#endif
+
+ServerActiveObject* CraftItem::createSAO(ServerEnvironment *env, u16 id, v3f pos)
+{
+ // Special cases
+ if(m_subname == "rat")
+ {
+ ServerActiveObject *obj = new RatSAO(env, id, pos);
+ return obj;
+ }
+ // Default
+ else
+ {
+ return InventoryItem::createSAO(env, id, pos);
+ }
+}
+
+u16 CraftItem::getDropCount()
+{
+ // Special cases
+ if(m_subname == "rat")
+ return 1;
+ // Default
+ else
+ return InventoryItem::getDropCount();
+}
+
+bool CraftItem::isCookable()
+{
+ if(m_subname == "lump_of_iron")
+ {
+ return true;
+ }
+ return false;
+}
+
+InventoryItem *CraftItem::createCookResult()
+{
+ if(m_subname == "lump_of_iron")
+ {
+ return new CraftItem("steel_ingot", 1);
+ }
+ return NULL;
+}
+
/*
MapBlockObjectItem
+ TODO: Remove
*/
#ifndef SERVER
video::ITexture * MapBlockObjectItem::getImage()
m_name = name;
m_size = size;
clearItems();
+ //m_dirty = false;
}
InventoryList::~InventoryList()
{
m_items.push_back(NULL);
}
+
+ //setDirty(true);
}
void InventoryList::serialize(std::ostream &os)
m_items[i] = item->clone();
}
}
+ //setDirty(true);
return *this;
}
return num;
}
+u32 InventoryList::getFreeSlots()
+{
+ return getSize() - getUsedSlots();
+}
+
InventoryItem * InventoryList::getItem(u32 i)
{
if(i > m_items.size() - 1)
InventoryItem *olditem = m_items[i];
m_items[i] = newitem;
+ //setDirty(true);
return olditem;
}
InventoryItem * InventoryList::addItem(InventoryItem *newitem)
{
+ if(newitem == NULL)
+ return NULL;
+
/*
First try to find if it could be added to some existing items
*/
InventoryItem * InventoryList::addItem(u32 i, InventoryItem *newitem)
{
+ if(newitem == NULL)
+ return NULL;
+
+ //setDirty(true);
+
// If it is an empty position, it's an easy job.
InventoryItem *to_item = m_items[i];
if(to_item == NULL)
{
if(count == 0)
return NULL;
+
+ //setDirty(true);
InventoryItem *item = m_items[i];
// If it is an empty position, return NULL