Fixed number of returned items from disassembler not taking into account recipe output size. Closes #1017.

This commit is contained in:
Florian Nücke 2015-04-04 18:20:37 +02:00
parent 6f02abad8c
commit 0d2554e08f

View File

@ -46,20 +46,30 @@ object ItemUtils {
def loadStack(nbt: NBTTagCompound) = ItemStack.loadItemStackFromNBT(nbt) def loadStack(nbt: NBTTagCompound) = ItemStack.loadItemStackFromNBT(nbt)
def getIngredients(stack: ItemStack): Array[ItemStack] = try { def getIngredients(stack: ItemStack): Array[ItemStack] = try {
val recipes = CraftingManager.getInstance.getRecipeList.map(_.asInstanceOf[IRecipe]) def getFilteredInputs(inputs: Iterable[ItemStack], outputSize: Double) = inputs.filter(input =>
val recipe = recipes.find(recipe => recipe.getRecipeOutput != null && recipe.getRecipeOutput.isItemEqual(stack)) input != null &&
val count = recipe.fold(0)(_.getRecipeOutput.stackSize) input.getItem != null &&
val ingredients = (recipe match { math.floor(input.stackSize / outputSize) > 0 &&
case Some(recipe: ShapedRecipes) => recipe.recipeItems.toIterable
case Some(recipe: ShapelessRecipes) => recipe.recipeItems.map(_.asInstanceOf[ItemStack])
case Some(recipe: ShapedOreRecipe) => resolveOreDictEntries(recipe.getInput)
case Some(recipe: ShapelessOreRecipe) => resolveOreDictEntries(recipe.getInput)
case _ => Iterable.empty
}).filter(ingredient => ingredient != null &&
// Strip out buckets, because those are returned when crafting, and // Strip out buckets, because those are returned when crafting, and
// we have no way of returning the fluid only (and I can't be arsed // we have no way of returning the fluid only (and I can't be arsed
// to make it output fluids into fluiducts or such, sorry). // to make it output fluids into fluiducts or such, sorry).
!ingredient.getItem.isInstanceOf[ItemBucket]).toArray !input.getItem.isInstanceOf[ItemBucket]).toArray
def getOutputSize(recipe: IRecipe) =
if (recipe != null && recipe.getRecipeOutput != null)
recipe.getRecipeOutput.stackSize
else
Double.PositiveInfinity
val recipes = CraftingManager.getInstance.getRecipeList.map(_.asInstanceOf[IRecipe])
val recipe = recipes.find(recipe => recipe.getRecipeOutput != null && recipe.getRecipeOutput.isItemEqual(stack))
val count = recipe.fold(0)(_.getRecipeOutput.stackSize)
val ingredients = recipe match {
case Some(recipe: ShapedRecipes) => getFilteredInputs(recipe.recipeItems.toIterable, getOutputSize(recipe))
case Some(recipe: ShapelessRecipes) => getFilteredInputs(recipe.recipeItems.map(_.asInstanceOf[ItemStack]), getOutputSize(recipe))
case Some(recipe: ShapedOreRecipe) => getFilteredInputs(resolveOreDictEntries(recipe.getInput), getOutputSize(recipe))
case Some(recipe: ShapelessOreRecipe) => getFilteredInputs(resolveOreDictEntries(recipe.getInput), getOutputSize(recipe))
case _ => Array.empty
}
// Avoid positive feedback loops. // Avoid positive feedback loops.
if (ingredients.exists(ingredient => ingredient.isItemEqual(stack))) { if (ingredients.exists(ingredient => ingredient.isItemEqual(stack))) {
return Array.empty return Array.empty