fix reverse craft book. clear recipe/result boxes if no item.

This commit is contained in:
JonnyW 2018-03-01 09:50:53 +00:00
parent 318a9968b9
commit 375a1ec93f
2 changed files with 66 additions and 21 deletions

View File

@ -987,19 +987,20 @@ FoundReverseRecipe getReverseRecipe(InventoryItem *iitem, int index)
}
//how to update an ingredient list given a range of new craft items
void addToIngredientList(std::vector<listdata_t> results, uint32_t begin, std::vector<content_t>& ingredient_list)
void addToIngredientList(contentlist_t *list, uint32_t begin, std::vector<content_t>& ingredient_list)
{
using namespace std;
//make a set to hold the items as the list is compiled
set<content_t> ingredients (ingredient_list.begin(), ingredient_list.end());
//go through the result list
for (std::vector<listdata_t>::iterator it = results.begin()+begin; it != results.end(); ++it) {
listdata_t *d = list->data;
//go through the result list
while (d) {
listdata_t d = *it;
//make a temporary inventory item for the result
InventoryItem *result = InventoryItem::create(d.content, 1, 0, d.data);
InventoryItem *result = InventoryItem::create(d->content, 1, 0, d->data);
//go through every recipe for this item
for (int rec_ind = getRecipeCount(result); rec_ind--;) {
@ -1020,6 +1021,8 @@ void addToIngredientList(std::vector<listdata_t> results, uint32_t begin, std::v
//clean up
delete result;
d = d->next;
}
//ignore CONTENT_IGNORE
@ -1050,8 +1053,7 @@ std::vector<content_t>& getCraftGuideIngredientList()
if (list_size > last_craftguide_count) {
//if so, add the new stuff
/* TODO: basically everything for reverse lookup */
//addToIngredientList(craft_list, last_craftguide_count, ingredient_list);
addToIngredientList(cl, last_craftguide_count, ingredient_list);
//and update the craftguide count
last_craftguide_count = list_size;

View File

@ -136,8 +136,17 @@ bool CraftGuideNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env
{
InventoryList *l = m_inventory->getList("result");
InventoryItem *t = l->getItem(0);
if (!t || t->getContent() == CONTENT_IGNORE)
if (!t || t->getContent() == CONTENT_IGNORE){
// nothing in result box so clear recipe list
InventoryList *rec_list = m_inventory->getList("recipe");
if (rec_list) {
//clear out the recipe grid if the item slot is empty
rec_list->clearItems();
return true;
}
return false;
}
content_t *r = crafting::getRecipe(t,m_recipe);
if (!r) {
if (m_recipe == 0)
@ -468,12 +477,24 @@ void ReverseCraftGuideNodeMetadata::inventoryModified()
}
bool ReverseCraftGuideNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
{
//make sure there's a valid item list
InventoryList *item_list = m_inventory->getList("item");
if (!item_list) return false;
//get the item in the item box
InventoryItem *item = m_inventory->getList("item")->getItem(0);
InventoryItem *item = item_list->getItem(0);
//if there's no item in the item box, do nothing
if (!item || item->getContent() == CONTENT_IGNORE)
return false;
if (!item || item->getContent() == CONTENT_IGNORE) {
// nothing in item box so clear recipe and result lists
InventoryList *rec_list = m_inventory->getList("recipe");
if (rec_list)
rec_list->clearItems();
InventoryList *res_list = m_inventory->getList("result");
if (res_list)
res_list->clearItems();
return true;
}
//attempt to look up the recipe
crafting::FoundReverseRecipe recipe = crafting::getReverseRecipe(item, m_recipe);
@ -731,8 +752,17 @@ 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)
if (!t || t->getContent() == CONTENT_IGNORE){
// nothing in result box so clear recipe list
InventoryList *rec_list = m_inventory->getList("recipe");
if (rec_list) {
//clear out the recipe grid if the item slot is empty
rec_list->clearItems();
return true;
}
return false;
}
InventoryItem *cookresult = t->createCookResult();
if (!cookresult || cookresult->getContent() == CONTENT_IGNORE)
return false;
@ -992,16 +1022,29 @@ bool DeCraftNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
{
InventoryList *l = m_inventory->getList("result");
InventoryItem *t = l->getItem(0);
int leave = 0;
if (!t || t->getContent() == CONTENT_IGNORE)
return false;
if ((t->getContent()&CONTENT_CRAFTITEM_MASK) == CONTENT_CRAFTITEM_MASK)
return false;
if ((t->getContent()&CONTENT_TOOLITEM_MASK) == CONTENT_TOOLITEM_MASK)
return false;
if ((t->getContent()&CONTENT_CLOTHESITEM_MASK) == CONTENT_CLOTHESITEM_MASK)
return false;
if (content_features(t->getContent()).dug_item == "" && content_features(t->getContent()).extra_dug_item == "")
return false;
leave=1;
else if ((t->getContent()&CONTENT_CRAFTITEM_MASK) == CONTENT_CRAFTITEM_MASK)
leave=1;
else if ((t->getContent()&CONTENT_TOOLITEM_MASK) == CONTENT_TOOLITEM_MASK)
leave=1;
else if ((t->getContent()&CONTENT_CLOTHESITEM_MASK) == CONTENT_CLOTHESITEM_MASK)
leave=1;
else if (content_features(t->getContent()).dug_item == "" && content_features(t->getContent()).extra_dug_item == "")
leave=1;
if (leave) {
// nothing in item box so clear recipe and result lists
InventoryList *rec_list = m_inventory->getList("recipe");
if (rec_list)
rec_list->clearItems();
InventoryList *ran_list = m_inventory->getList("random");
if (ran_list)
ran_list->clearItems();
return true;
}
l = m_inventory->getList("recipe");
l->clearItems();
if (content_features(t->getContent()).dug_item != "") {