void cSlotAreaCrafting::ClickedResult(cPlayer & a_Player) { const cItem * ResultSlot = GetSlot(0, a_Player); cItem & DraggingItem = a_Player.GetDraggingItem(); // Get the current recipe: cCraftingRecipe & Recipe = GetRecipeForPlayer(a_Player); cItem * PlayerSlots = GetPlayerSlots(a_Player) + 1; cCraftingGrid Grid(PlayerSlots, m_GridSize, m_GridSize); // If possible, craft: if (DraggingItem.IsEmpty()) { DraggingItem = Recipe.GetResult(); Recipe.ConsumeIngredients(Grid); Grid.CopyToItems(PlayerSlots); } else if (DraggingItem.IsEqual(Recipe.GetResult())) { cItemHandler * Handler = ItemHandler(Recipe.GetResult().m_ItemType); if (DraggingItem.m_ItemCount + Recipe.GetResult().m_ItemCount <= Handler->GetMaxStackSize()) { DraggingItem.m_ItemCount += Recipe.GetResult().m_ItemCount; Recipe.ConsumeIngredients(Grid); Grid.CopyToItems(PlayerSlots); } } // Get the new recipe and update the result slot: UpdateRecipe(a_Player); // We're done. Send all changes to the client and bail out: m_ParentWindow.BroadcastWholeWindow(); }
void cSlotAreaCrafting::UpdateRecipe(cPlayer & a_Player) { cCraftingGrid Grid(GetPlayerSlots(a_Player) + 1, m_GridSize, m_GridSize); cCraftingRecipe & Recipe = GetRecipeForPlayer(a_Player); cRoot::Get()->GetCraftingRecipes()->GetRecipe(&a_Player, Grid, Recipe); SetSlot(0, a_Player, Recipe.GetResult()); m_ParentWindow.SendSlot(a_Player, this, 0); }
void cSlotAreaCrafting::DropClickedResult(cPlayer & a_Player) { // Get the current recipe: cCraftingRecipe & Recipe = GetRecipeForPlayer(a_Player); const cItem & Result = Recipe.GetResult(); cItem * PlayerSlots = GetPlayerSlots(a_Player) + 1; cCraftingGrid Grid(PlayerSlots, m_GridSize, m_GridSize); a_Player.TossPickup(Result); Recipe.ConsumeIngredients(Grid); Grid.CopyToItems(PlayerSlots); HandleCraftItem(Result, a_Player); UpdateRecipe(a_Player); }
void cSlotAreaCrafting::ShiftClickedResult(cPlayer & a_Player) { cItem Result(*GetSlot(0, a_Player)); if (Result.IsEmpty()) { return; } cItem * PlayerSlots = GetPlayerSlots(a_Player) + 1; for (;;) { // Try distributing the result. If it fails, bail out: cItem ResultCopy(Result); m_ParentWindow.DistributeStack(ResultCopy, a_Player, this, false); if (!ResultCopy.IsEmpty()) { // Couldn't distribute all of it. Bail out return; } // Distribute the result, this time for real: ResultCopy = Result; m_ParentWindow.DistributeStack(ResultCopy, a_Player, this, true); // Remove the ingredients from the crafting grid and update the recipe: cCraftingRecipe & Recipe = GetRecipeForPlayer(a_Player); cCraftingGrid Grid(PlayerSlots, m_GridSize, m_GridSize); Recipe.ConsumeIngredients(Grid); Grid.CopyToItems(PlayerSlots); UpdateRecipe(a_Player); // Broadcast the window, we sometimes move items to different locations than Vanilla, causing needless desyncs: m_ParentWindow.BroadcastWholeWindow(); // If the recipe has changed, bail out: if (!Recipe.GetResult().IsEqual(Result)) { return; } } }
void cSlotAreaCrafting::ShiftClickedResult(cPlayer & a_Player) { cItem Result(*GetSlot(0, a_Player)); if (Result.IsEmpty()) { return; } cItem * PlayerSlots = GetPlayerSlots(a_Player) + 1; do { // Try distributing the result. If it fails, bail out: cItem ResultCopy(Result); m_ParentWindow.DistributeStack(ResultCopy, a_Player, this, false); if (!ResultCopy.IsEmpty()) { // Couldn't distribute all of it. Bail out return; } // Distribute the result, this time for real: ResultCopy = Result; m_ParentWindow.DistributeStack(ResultCopy, a_Player, this, true); // Remove the ingredients from the crafting grid and update the recipe: cCraftingRecipe & Recipe = GetRecipeForPlayer(a_Player); cCraftingGrid Grid(PlayerSlots, m_GridSize, m_GridSize); Recipe.ConsumeIngredients(Grid); Grid.CopyToItems(PlayerSlots); UpdateRecipe(a_Player); if (!Recipe.GetResult().IsEqual(Result)) { // The recipe has changed, bail out return; } } while (true); }