1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Add a callback: minetest.register_on_craft(itemstack, player,

old_craft_grid, craft_inv) and
minetest.register_craft_predict(itemstack, player, old_craft_grid,
craft_inv)
This commit is contained in:
Novatux 2013-10-26 11:25:28 +02:00
parent 2f10cfb226
commit bd6d4666ab
6 changed files with 93 additions and 0 deletions

View file

@ -724,13 +724,19 @@ void ICraftAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGam
}
ItemStack crafted;
ItemStack craftresultitem;
int count_remaining = count;
bool found = getCraftingResult(inv_craft, crafted, false, gamedef);
PLAYER_TO_SA(player)->item_CraftPredict(crafted, player, list_craft, craft_inv);
found = !crafted.empty();
while(found && list_craftresult->itemFits(0, crafted))
{
InventoryList saved_craft_list = *list_craft;
// Decrement input and add crafting output
getCraftingResult(inv_craft, crafted, true, gamedef);
PLAYER_TO_SA(player)->item_OnCraft(crafted, player, &saved_craft_list, craft_inv);
list_craftresult->addItem(0, crafted);
mgr->setInventoryModified(craft_inv);
@ -747,6 +753,8 @@ void ICraftAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGam
// Get next crafting result
found = getCraftingResult(inv_craft, crafted, false, gamedef);
PLAYER_TO_SA(player)->item_CraftPredict(crafted, player, list_craft, craft_inv);
found = !crafted.empty();
}
infostream<<"ICraftAction::apply(): crafted "