cooking guide

This commit is contained in:
darkrose 2014-03-22 16:37:56 +10:00
parent 7b85175a3a
commit 7e81cab058
4 changed files with 248 additions and 1 deletions

View File

@ -88,6 +88,7 @@ void content_craftitem_init()
f->description = "Iron Lump";
f->cook_result = "CraftItem steel_ingot 1";
lists::add("creative",i);
lists::add("cooking",i);
i = CONTENT_CRAFTITEM_CLAY;
f = &g_content_craftitem_features[i];
@ -97,6 +98,7 @@ void content_craftitem_init()
f->description = "Clay Lump";
f->cook_result = "CraftItem clay_brick 1";
lists::add("creative",i);
lists::add("cooking",i);
i = CONTENT_CRAFTITEM_TIN;
f = &g_content_craftitem_features[i];
@ -106,6 +108,7 @@ void content_craftitem_init()
f->description = "Tin Lump";
f->cook_result = "CraftItem tin_ingot 1";
lists::add("creative",i);
lists::add("cooking",i);
i = CONTENT_CRAFTITEM_COPPER;
f = &g_content_craftitem_features[i];
@ -115,6 +118,7 @@ void content_craftitem_init()
f->description = "Copper Lump";
f->cook_result = "CraftItem copper_ingot 1";
lists::add("creative",i);
lists::add("cooking",i);
i = CONTENT_CRAFTITEM_SILVER;
f = &g_content_craftitem_features[i];
@ -124,6 +128,7 @@ void content_craftitem_init()
f->description = "Silver Lump";
f->cook_result = "CraftItem silver_ingot 1";
lists::add("creative",i);
lists::add("cooking",i);
i = CONTENT_CRAFTITEM_GOLD;
f = &g_content_craftitem_features[i];
@ -133,6 +138,7 @@ void content_craftitem_init()
f->description = "Gold Lump";
f->cook_result = "CraftItem gold_ingot 1";
lists::add("creative",i);
lists::add("cooking",i);
i = CONTENT_CRAFTITEM_QUARTZ;
f = &g_content_craftitem_features[i];
@ -207,6 +213,7 @@ void content_craftitem_init()
f->cook_result = "CraftItem cooked_rat 1";
f->drop_count = 1;
lists::add("creative",i);
lists::add("cooking",i);
i = CONTENT_CRAFTITEM_COOKED_RAT;
f = &g_content_craftitem_features[i];
@ -217,6 +224,7 @@ void content_craftitem_init()
f->cook_result = "CraftItem scorched_stuff 1";
f->edible = 6;
lists::add("creative",i);
lists::add("cooking",i);
i = CONTENT_CRAFTITEM_SCORCHED_STUFF;
f = &g_content_craftitem_features[i];
@ -562,6 +570,7 @@ void content_craftitem_init()
crafting::set1Any2Recipe(CONTENT_CRAFTITEM_FLOUR,CONTENT_CRAFTITEM_FLOUR,CONTENT_CRAFTITEM_DOUGH);
lists::add("craftguide",i);
lists::add("creative",i);
lists::add("cooking",i);
i = CONTENT_CRAFTITEM_BREAD;
f = &g_content_craftitem_features[i];
@ -581,6 +590,7 @@ void content_craftitem_init()
f->cook_result = std::string("CraftItem roast_potato 1");
f->edible = 3;
lists::add("creative",i);
lists::add("cooking",i);
i = CONTENT_CRAFTITEM_STARCH;
f = &g_content_craftitem_features[i];
@ -620,6 +630,7 @@ void content_craftitem_init()
f->edible = 3;
crafting::set1over1Recipe(CONTENT_CRAFTITEM_CARROT,CONTENT_CRAFTITEM_DOUGH,CONTENT_CRAFTITEM_CARROT_CAKE_RAW);
lists::add("craftguide",i);
lists::add("cooking",i);
i = CONTENT_CRAFTITEM_CARROT_CAKE;
f = &g_content_craftitem_features[i];

View File

@ -1393,6 +1393,7 @@ void content_mapnode_init()
f->type = CMT_DIRT;
f->hardness = 1.0;
lists::add("creative",i);
lists::add("cooking",i);
i = CONTENT_GRAVEL;
f = &content_features(i);
@ -1464,6 +1465,7 @@ void content_mapnode_init()
crafting::setSoftBlockRecipe(CONTENT_CRAFTITEM_CLAY,CONTENT_CLAY);
lists::add("craftguide",i);
lists::add("creative",i);
lists::add("cooking",i);
i = CONTENT_CLAY_BLUE;
f = &content_features(i);
@ -1666,6 +1668,7 @@ void content_mapnode_init()
f->type = CMT_WOOD;
f->hardness = 1.0;
lists::add("creative",i);
lists::add("cooking",i);
i = CONTENT_APPLE_TREE;
f = &content_features(i);
@ -1683,6 +1686,7 @@ void content_mapnode_init()
f->type = CMT_WOOD;
f->hardness = 1.0;
lists::add("creative",i);
lists::add("cooking",i);
i = CONTENT_JUNGLETREE;
f = &content_features(i);
@ -1732,6 +1736,7 @@ void content_mapnode_init()
f->type = CMT_WOOD;
f->hardness = 0.8;
lists::add("creative",i);
lists::add("cooking",i);
i = CONTENT_JUNGLEGRASS;
f = &content_features(i);
@ -2909,6 +2914,7 @@ void content_mapnode_init()
f->type = CMT_STONE;
f->hardness = 0.5;
lists::add("creative",i);
lists::add("cooking",i);
i = CONTENT_MESE_DIGGING;
f = &content_features(i);
@ -3140,6 +3146,7 @@ void content_mapnode_init()
crafting::set1over1Recipe(CONTENT_CRAFTITEM_APPLE,CONTENT_CRAFTITEM_DOUGH,CONTENT_APPLE_PIE_RAW);
lists::add("craftguide",i);
lists::add("creative",i);
lists::add("cooking",i);
i = CONTENT_APPLE_PIE;
f = &content_features(i);
@ -3252,6 +3259,7 @@ void content_mapnode_init()
crafting::set1over1Recipe(CONTENT_CRAFTITEM_PUMPKINSLICE,CONTENT_CRAFTITEM_DOUGH,CONTENT_PUMPKIN_PIE_RAW);
lists::add("craftguide",i);
lists::add("creative",i);
lists::add("cooking",i);
i = CONTENT_PUMPKIN_PIE;
f = &content_features(i);
@ -4177,6 +4185,8 @@ void content_mapnode_init()
crafting::set1Any2Recipe(CONTENT_BOOK,CONTENT_CRAFTITEM_CHARCOAL,i);
lists::add("craftguide",i);
lists::add("creative",i);
if (f->initial_metadata == NULL)
f->initial_metadata = new ClosedBookNodeMetadata();
i = CONTENT_DECRAFT_BOOK;
f = &content_features(i);
@ -4318,6 +4328,8 @@ void content_mapnode_init()
f->setInventoryTextureNodeBox(i, "guide_cook_top.png", "guide_cook_end.png", "guide_cook_side.png");
f->type = CMT_DIRT;
f->hardness = 1.0;
if (f->initial_metadata == NULL)
f->initial_metadata = new CookBookNodeMetadata();
i = CONTENT_DECRAFT_BOOK_OPEN;
f = &content_features(i);
@ -5284,6 +5296,7 @@ void content_mapnode_init()
crafting::setBlockRecipe(CONTENT_COBBLE,CONTENT_ROUGHSTONE);
lists::add("craftguide",i);
lists::add("creative",i);
lists::add("cooking",i);
i = CONTENT_COBBLE;
f = &content_features(i);
@ -7789,6 +7802,7 @@ void content_mapnode_init()
f->setInventoryTextureNodeBox(i,"flower_pot_raw_top.png","flower_pot_raw.png","flower_pot_raw.png");
crafting::setVRecipe(CONTENT_CRAFTITEM_CLAY,CONTENT_FLOWER_POT_RAW);
lists::add("craftguide",i);
lists::add("cooking",i);
i = CONTENT_FLOWER_POT;
f = &content_features(i);

View File

@ -1230,6 +1230,200 @@ std::string CraftGuideNodeMetadata::getDrawSpecString()
return spec;
}
/*
CookBookNodeMetadata
*/
// Prototype
CookBookNodeMetadata proto_CookBookNodeMetadata;
CookBookNodeMetadata::CookBookNodeMetadata()
{
NodeMetadata::registerType(typeId(), create);
m_page = 0;
m_inventory = new Inventory();
m_inventory->addList("list", 300);
m_inventory->addList("recipe", 9);
m_inventory->addList("result", 1);
}
CookBookNodeMetadata::~CookBookNodeMetadata()
{
delete m_inventory;
}
u16 CookBookNodeMetadata::typeId() const
{
return CONTENT_COOK_BOOK_OPEN;
}
NodeMetadata* CookBookNodeMetadata::clone()
{
CookBookNodeMetadata *d = new CookBookNodeMetadata();
*d->m_inventory = *m_inventory;
d->m_page = m_page;
InventoryList *l = d->m_inventory->getList("list");
InventoryItem *t;
l->clearItems();
std::vector<content_t> &list = lists::get("cooking");
u16 start = m_page*40;
u16 end = start+40;
if (end > list.size())
end = list.size();
for (int i=start; i<end; i++) {
if ((list[i]&CONTENT_CRAFTITEM_MASK) == CONTENT_CRAFTITEM_MASK) {
t = new CraftItem(list[i],1);
}else if ((list[i]&CONTENT_TOOLITEM_MASK) == CONTENT_TOOLITEM_MASK) {
t = new ToolItem(list[i],1);
}else{
t = new MaterialItem(list[i],1);
}
InventoryItem *cookresult = t->createCookResult();
if (!cookresult || cookresult->getContent() == CONTENT_IGNORE) {
delete t;
delete cookresult;
continue;
}
delete cookresult;
l->addItem(t);
}
return d;
}
NodeMetadata* CookBookNodeMetadata::create(std::istream &is)
{
CookBookNodeMetadata *d = new CookBookNodeMetadata();
d->m_inventory->deSerialize(is);
is>>d->m_page;
return d;
}
void CookBookNodeMetadata::serializeBody(std::ostream &os)
{
m_inventory->serialize(os);
os<<itos(m_page) << " ";
}
bool CookBookNodeMetadata::nodeRemovalDisabled()
{
return false;
}
void CookBookNodeMetadata::inventoryModified()
{
infostream<<"CookBook inventory modification callback"<<std::endl;
}
bool CookBookNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
{
InventoryList *l = m_inventory->getList("result");
InventoryItem *t = l->getItem(0);
if (!t || t->getContent() == CONTENT_IGNORE)
return false;
InventoryItem *cookresult = t->createCookResult();
if (!cookresult || cookresult->getContent() == CONTENT_IGNORE)
return false;
l = m_inventory->getList("recipe");
l->clearItems();
l->addItem(0,cookresult);
return true;
}
bool CookBookNodeMetadata::import(NodeMetadata *meta)
{
if (meta->typeId() == CONTENT_BOOK)
m_page = ((ClosedBookNodeMetadata*)meta)->getPage();
if (m_page < 0)
m_page = 0;
std::vector<content_t> &list = lists::get("cooking");
if (m_page > (list.size()/40))
m_page = list.size()/40;
InventoryList *l = m_inventory->getList("list");
InventoryItem *t;
l->clearItems();
u16 start = m_page*40;
u16 end = start+40;
if (end > list.size())
end = list.size();
for (int i=start; i<end; i++) {
if ((list[i]&CONTENT_CRAFTITEM_MASK) == CONTENT_CRAFTITEM_MASK) {
t = new CraftItem(list[i],1);
}else if ((list[i]&CONTENT_TOOLITEM_MASK) == CONTENT_TOOLITEM_MASK) {
t = new ToolItem(list[i],1);
}else{
t = new MaterialItem(list[i],1);
}
InventoryItem *cookresult = t->createCookResult();
if (!cookresult || cookresult->getContent() == CONTENT_IGNORE) {
delete t;
delete cookresult;
continue;
}
delete cookresult;
l->addItem(t);
}
return true;
}
bool CookBookNodeMetadata::receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player)
{
if (fields["prev"] == "" && fields["next"] == "")
return false;
if (fields["prev"] != "")
m_page--;
if (fields["next"] != "")
m_page++;
if (m_page < 0)
m_page = 0;
std::vector<content_t> &list = lists::get("cooking");
if (m_page > (list.size()/40))
m_page = list.size()/40;
InventoryList *l = m_inventory->getList("list");
InventoryItem *t;
l->clearItems();
u16 start = m_page*40;
u16 end = start+40;
if (end > list.size())
end = list.size();
for (int i=start; i<end; i++) {
if ((list[i]&CONTENT_CRAFTITEM_MASK) == CONTENT_CRAFTITEM_MASK) {
t = new CraftItem(list[i],1);
}else if ((list[i]&CONTENT_TOOLITEM_MASK) == CONTENT_TOOLITEM_MASK) {
t = new ToolItem(list[i],1);
}else{
t = new MaterialItem(list[i],1);
}
InventoryItem *cookresult = t->createCookResult();
if (!cookresult || cookresult->getContent() == CONTENT_IGNORE) {
delete t;
delete cookresult;
continue;
}
delete cookresult;
l->addItem(t);
}
return true;
}
std::string CookBookNodeMetadata::getDrawSpecString()
{
InventoryList *l = m_inventory->getList("result");
InventoryItem *q = l->getItem(0);
int tr = 0;
std::vector<content_t> &list = lists::get("cooking");
if (q && q->getContent() != CONTENT_IGNORE)
tr = crafting::getResultCount(q);
std::string spec("size[8,9]");
spec += "label[0.5,0.75;Add item here to see cook result]";
spec += "list[current_name;result;2,1;1,1;]";
spec += "list[current_name;recipe;4,1;1,1;]";
spec += "button[0.25,3.5;2.5,0.75;prev;<< Previous Page]";
spec += "label[3.5,3.5;Page ";
spec += itos(m_page+1);
spec +=" of ";
spec += itos((list.size()/40)+1);
spec += "]";
spec += "button[6,3.5;2.5,0.75;next;Next Page >>]";
spec += "list[current_name;list;0,4;8,5;]";
return spec;
}
/*
BookNodeMetadata
*/
@ -1375,7 +1569,9 @@ bool DiaryNodeMetadata::import(NodeMetadata *meta)
}
bool DiaryNodeMetadata::receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player)
{
if (m_owner != "" && player->getName() != m_owner)
if (m_owner == "")
m_owner = player->getName();
if (player->getName() != m_owner)
return false;
m_title = fields["title"];
m_content = fields["content"];

View File

@ -322,6 +322,32 @@ private:
u16 m_page;
};
class CookBookNodeMetadata : public NodeMetadata
{
public:
CookBookNodeMetadata();
~CookBookNodeMetadata();
virtual u16 typeId() const;
NodeMetadata* clone();
static NodeMetadata* create(std::istream &is);
virtual void serializeBody(std::ostream &os);
virtual std::string infoText() {return std::string("Cooking Guide");}
virtual Inventory* getInventory() {return m_inventory;}
virtual bool nodeRemovalDisabled();
virtual void inventoryModified();
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
virtual bool import(NodeMetadata *meta);
virtual bool receiveFields(std::string formname, std::map<std::string, std::string> fields, Player *player);
virtual std::string getDrawSpecString();
u16 getPage() {return m_page;}
private:
Inventory *m_inventory;
u16 m_page;
};
class BookNodeMetadata : public NodeMetadata
{
public: