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;
}
InventoryItem *olditem = m_items[i];
m_items[i] = newitem;
+ //setDirty(true);
return olditem;
}
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
in_water(false),
in_water_stable(false),
swimming_up(false),
+ craftresult_is_preview(true),
peer_id(PEER_ID_INEXISTENT),
m_pitch(0),
m_yaw(0),
args.setFloat("pitch", m_pitch);
args.setFloat("yaw", m_yaw);
args.setV3F("position", m_position);
+ args.setBool("craftresult_is_preview", craftresult_is_preview);
args.writeLines(os);
m_pitch = args.getFloat("pitch");
m_yaw = args.getFloat("yaw");
m_position = args.getV3F("position");
+ try{
+ craftresult_is_preview = args.getBool("craftresult_is_preview");
+ }catch(SettingNotFoundException &e){
+ craftresult_is_preview = true;
+ }
inventory.deSerialize(is);
}
if(ma->to_inv == "current_player" &&
ma->from_inv == "current_player")
{
- // Don't allow moving anything to craftresult
- if(ma->to_list == "craftresult")
+ InventoryList *rlist = player->inventory.getList("craftresult");
+ assert(rlist);
+ InventoryList *clist = player->inventory.getList("craft");
+ assert(clist);
+ InventoryList *mlist = player->inventory.getList("main");
+ assert(mlist);
+ /*
+ Craftresult is no longer preview if something
+ is moved into it
+ */
+ if(ma->to_list == "craftresult"
+ && ma->from_list != "craftresult")
{
- // Do nothing
- disable_action = true;
+ // If it currently is a preview, remove
+ // its contents
+ if(player->craftresult_is_preview)
+ {
+ rlist->deleteItem(0);
+ }
+ player->craftresult_is_preview = false;
+ }
+ /*
+ Crafting takes place if this condition is true.
+ */
+ if(player->craftresult_is_preview &&
+ ma->from_list == "craftresult")
+ {
+ player->craftresult_is_preview = false;
+ clist->decrementMaterials(1);
}
- // When something is removed from craftresult
- if(ma->from_list == "craftresult")
+ /*
+ If the craftresult is placed on itself, move it to
+ main inventory instead of doing the action
+ */
+ if(ma->to_list == "craftresult"
+ && ma->from_list == "craftresult")
{
disable_action = true;
- // Remove stuff from craft
- InventoryList *clist = player->inventory.getList("craft");
- if(clist)
- {
- u16 count = ma->count;
- if(count == 0)
- count = 1;
- clist->decrementMaterials(count);
- }
- // Do action
- // Feed action to player inventory
- //a->apply(&player->inventory);
- a->apply(&c, this);
- // Eat it
- delete a;
- // If something appeared in craftresult, throw it
- // in the main list
- InventoryList *rlist = player->inventory.getList("craftresult");
- InventoryList *mlist = player->inventory.getList("main");
- if(rlist && mlist && rlist->getUsedSlots() == 1)
- {
- InventoryItem *item1 = rlist->changeItem(0, NULL);
- mlist->addItem(item1);
- }
+
+ InventoryItem *item1 = rlist->changeItem(0, NULL);
+ mlist->addItem(item1);
}
}
}
if(disable_action == false)
{
// Feed action to player inventory
- //a->apply(&player->inventory);
a->apply(&c, this);
// Eat the action
delete a;
DSTACK(__FUNCTION_NAME);
Player* player = m_env.getPlayer(peer_id);
+ assert(player);
/*
Calculate crafting stuff
{
InventoryList *clist = player->inventory.getList("craft");
InventoryList *rlist = player->inventory.getList("craftresult");
- if(rlist)
+
+ if(rlist->getUsedSlots() == 0)
+ player->craftresult_is_preview = true;
+
+ if(rlist && player->craftresult_is_preview)
{
rlist->clearItems();
}
- if(clist && rlist)
+ if(clist && rlist && player->craftresult_is_preview)
{
InventoryItem *items[9];
for(u16 i=0; i<9; i++)
found = true;
}
}
-
}
+
} // if creative_mode == false
/*