1
0

Shift-click completed in survival inventory window

git-svn-id: http://mc-server.googlecode.com/svn/trunk@732 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2012-08-14 08:33:09 +00:00
parent 63e68865b1
commit e946616772
2 changed files with 37 additions and 2 deletions

View File

@ -348,7 +348,7 @@ int cInventory::MoveItem(ENUM_ITEM_ID a_ItemType, short a_ItemDamage, int a_Coun
{
int MaxCount = ItemHandler(a_ItemType)->GetMaxStackSize();
ASSERT(m_Slots[i].m_ItemCount <= MaxCount);
int NumToMove = std::min(a_Count, MaxCount);
int NumToMove = std::min(a_Count, MaxCount - m_Slots[i].m_ItemCount);
m_Slots[i].m_ItemCount += NumToMove;
m_Slots[i].m_ItemHealth = a_ItemDamage;
m_Slots[i].m_ItemID = a_ItemType;

View File

@ -151,7 +151,42 @@ void cSurvivalInventory::ShiftClicked(cPacket_WindowClick * a_ClickPacket)
void cSurvivalInventory::ShiftClickedCraftingResult(short a_Slot)
{
// TODO
// Craft until either the recipe changes (due to ingredients) or there's not enough storage for the result
cItem * CraftingResult = GetSlot(SLOT_CRAFTING_RESULT);
if ((CraftingResult == NULL) || CraftingResult->IsEmpty())
{
return;
}
cItem ResultCopy = *CraftingResult;
int HowManyItemsWillFit = HowManyCanFit(CraftingResult->m_ItemID, CraftingResult->m_ItemHealth, SLOT_INVENTORY_MIN, SLOT_INVENTORY_MAX);
HowManyItemsWillFit += HowManyCanFit(CraftingResult->m_ItemID, CraftingResult->m_ItemHealth, SLOT_HOTBAR_MIN, SLOT_HOTBAR_MAX);
int HowManyPassesWillFit = HowManyItemsWillFit / CraftingResult->m_ItemCount;
for (int i = 0; i < HowManyPassesWillFit; i++)
{
// First try moving into the hotbar:
int NumMoved = MoveItem(CraftingResult->m_ItemID, CraftingResult->m_ItemHealth, CraftingResult->m_ItemCount, SLOT_HOTBAR_MIN, SLOT_HOTBAR_MAX);
// If something didn't fit, move into main inventory:
if (NumMoved < CraftingResult->m_ItemCount)
{
MoveItem(CraftingResult->m_ItemID, CraftingResult->m_ItemHealth, CraftingResult->m_ItemCount - NumMoved, SLOT_INVENTORY_MIN, SLOT_INVENTORY_MAX);
}
// "Use" the crafting recipe once:
cCraftingGrid Grid(m_Slots + SLOT_CRAFTING_MIN, 2, 2);
cCraftingRecipe Recipe(Grid);
cRoot::Get()->GetCraftingRecipes()->GetRecipe(m_Owner, Grid, Recipe);
Recipe.ConsumeIngredients(Grid);
Grid.CopyToItems(m_Slots + c_CraftOffset + 1);
cRoot::Get()->GetCraftingRecipes()->GetRecipe(m_Owner, Grid, Recipe);
m_Slots[SLOT_CRAFTING_RESULT] = Recipe.GetResult();
// If the recipe changed, abort:
if (!Recipe.GetResult().Equals(ResultCopy))
{
break;
}
}
}