Fix segfault when crafting uses up all of the first itemstack it checks.

Probably fixes #1356, #1530, #1621 and #1628.

I'd appreciate some testing for this, I couldn't make anything segfault after applying it, and everything seems to use the correct amount of ingredients, but I might not have tested every crafting scenario.

The test I was using was to wish for exactly the amount i needed for some crafting recipe, then craft it. Crashed every time.