diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/matter/RecipeResolverManager.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/matter/RecipeResolverManager.kt index 49d4c9feb..8bb390c35 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/matter/RecipeResolverManager.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/matter/RecipeResolverManager.kt @@ -45,9 +45,9 @@ object RecipeResolverManager : SimpleJsonResourceReloadListener(GsonBuilder().se */ data class ImmutableStack( val item: Item, - val count: Long = 1L + val multiplier: Double = 1.0 ) { - constructor(item: Item, count: Int) : this(item, count.toLong()) + constructor(item: Item, count: Int) : this(item, 1.0 / count.toDouble()) constructor(item: ItemStack) : this(item.item, item.count) } @@ -63,7 +63,7 @@ object RecipeResolverManager : SimpleJsonResourceReloadListener(GsonBuilder().se val isCritical: Boolean = true, ) { val inputs: List> = inputs - .map { it.filter { it.count > 0L }.collect(ImmutableList.toImmutableList()) } + .map { it.filter { it.multiplier > 0.0 }.collect(ImmutableList.toImmutableList()) } .filter { it.isNotEmpty() } .collect(ImmutableList.toImmutableList()) @@ -223,16 +223,16 @@ object RecipeResolverManager : SimpleJsonResourceReloadListener(GsonBuilder().se private data class Result(val type: Type, val value: MatterManager.IMatterValue? = null) { constructor(value: MatterManager.IMatterValue) : this(Type.RESOLVED, value) - val isRecursion get() = type === Type.RECURSION + val isSkipped get() = type === Type.SKIPPED val isMissing get() = type === Type.MISSING enum class Type { - RESOLVED, RECURSION, MISSING + RESOLVED, SKIPPED, MISSING } companion object { // recursive recipes should be ignored until we resolve everything else - val RECURSION = Result(Type.RECURSION) + val RECURSION = Result(Type.SKIPPED) // missing matter values are fatal, whole recipe chain is then considered defunct val MISSING = Result(Type.MISSING) @@ -245,7 +245,7 @@ object RecipeResolverManager : SimpleJsonResourceReloadListener(GsonBuilder().se private fun doDetermineValue(item: Item): Result { var minimalMatter: ImpreciseFraction? = null var minimalComplexity: Double? = null - var hadRecursion = false + var hadSkips = false recipesLoop@ for (recipe in output2Recipes[item] ?: return Result.MISSING) { if (recipe.inputs.isEmpty()) { @@ -258,7 +258,7 @@ object RecipeResolverManager : SimpleJsonResourceReloadListener(GsonBuilder().se inputsLoop@ for (inputs in recipe.inputs) { var minimal: MatterManager.IMatterValue? = null - var minimalDivisor = 0L + var minimalMultiplier = 0.0 for (input in inputs) { val ivalue = determineValue(input.item) @@ -269,14 +269,14 @@ object RecipeResolverManager : SimpleJsonResourceReloadListener(GsonBuilder().se } else { continue@recipesLoop } - } else if (ivalue.isRecursion) { - hadRecursion = true + } else if (ivalue.isSkipped) { + hadSkips = true break@recipesLoop } if (minimal == null || minimal > ivalue.value!!) { minimal = ivalue.value - minimalDivisor = input.count + minimalMultiplier = input.multiplier } } @@ -284,11 +284,11 @@ object RecipeResolverManager : SimpleJsonResourceReloadListener(GsonBuilder().se return Result.MISSING if (accumulatedMatter == null || accumulatedComplexity == null) { - accumulatedMatter = minimal.matter / minimalDivisor - accumulatedComplexity = minimal.complexity / minimalDivisor + accumulatedMatter = minimal.matter * minimalMultiplier + accumulatedComplexity = minimal.complexity * minimalMultiplier } else { - accumulatedMatter += minimal.matter / minimalDivisor - accumulatedComplexity += minimal.complexity / minimalDivisor + accumulatedMatter += minimal.matter * minimalMultiplier + accumulatedComplexity += minimal.complexity * minimalMultiplier } } @@ -302,13 +302,13 @@ object RecipeResolverManager : SimpleJsonResourceReloadListener(GsonBuilder().se } if (minimalMatter == null || minimalMatter > accumulatedMatter) { - minimalMatter = accumulatedMatter / recipe.output.count - minimalComplexity = accumulatedComplexity / recipe.output.count + minimalMatter = recipe.transformMatterValue(accumulatedMatter * recipe.output.multiplier) + minimalComplexity = recipe.transformComplexity(accumulatedComplexity * recipe.output.multiplier) } } if (minimalMatter == null || minimalComplexity == null) { - if (hadRecursion) { + if (hadSkips) { return Result.RECURSION }