Slightly reworked logic of crafting upgrade to also support repairing items, fixes #874. Doesn't appear to break everything else.

This commit is contained in:
Florian Nücke 2015-02-01 00:06:43 +01:00
parent fb8cca23ab
commit d870d376aa

View File

@ -39,15 +39,12 @@ class UpgradeCrafting(val host: EnvironmentHost with Robot) extends prefab.Manag
def craft(wantedCount: Int): Seq[_] = {
load()
CraftingManager.getInstance.getRecipeList.find {
case recipe: IRecipe => recipe.matches(CraftingInventory, host.world)
case _ => false // Shouldn't ever happen, but...
} match {
case Some(recipe: IRecipe) =>
val cm = CraftingManager.getInstance
var countCrafted = 0
val canCraft = cm.findMatchingRecipe(CraftingInventory, host.world) != null
breakable {
while (countCrafted < wantedCount && recipe.matches(this, host.world)) {
val result = recipe.getCraftingResult(CraftingInventory)
while (countCrafted < wantedCount) {
val result = cm.findMatchingRecipe(CraftingInventory, host.world)
if (result == null || result.stackSize < 1) break()
countCrafted += result.stackSize
FMLCommonHandler.instance.firePlayerCraftingEvent(host.player, result, this)
@ -80,9 +77,7 @@ class UpgradeCrafting(val host: EnvironmentHost with Robot) extends prefab.Manag
load()
}
}
Seq(true, countCrafted)
case _ => Seq(false, 0)
}
Seq(canCraft, countCrafted)
}
def load() {