Even better recipe backtrack
This commit is contained in:
parent
5d727fc5ce
commit
114c8adbe6
@ -311,7 +311,7 @@ object RecipeResolverManager : SimpleJsonResourceReloadListener(GsonBuilder().se
|
||||
private var changes = false
|
||||
private var cachedIterationResults = Reference2ObjectOpenHashMap<Item, Result>()
|
||||
|
||||
private fun tryToBacktrack(item: Item, makeCommentary: Boolean): Result {
|
||||
private fun doTryToBacktrack(item: Item, makeCommentary: Boolean): Result {
|
||||
val recipes = input2Recipes[item]
|
||||
|
||||
if (recipes == null || recipes.isEmpty() || !recipes.all { it.allowBacktrack } || !recipes.all { it.inputs.all { it.all { it.item == item } } }) {
|
||||
@ -326,15 +326,16 @@ object RecipeResolverManager : SimpleJsonResourceReloadListener(GsonBuilder().se
|
||||
var foundRecipe: ResolvedRecipe? = null
|
||||
|
||||
for (recipe in recipes) {
|
||||
val value = MatterManager.getDirect(recipe.output.item)
|
||||
val value = doDetermineValue(recipe.output.item)
|
||||
|
||||
if (value.hasMatterValue) {
|
||||
if (minimal == null || minimal < value) {
|
||||
minimal = value
|
||||
if (value.value != null) {
|
||||
if (minimal == null || minimal < value.value) {
|
||||
minimal = value.value
|
||||
minimalMultiplier = recipe.output.multiplier / recipe.inputs.size
|
||||
foundRecipe = recipe
|
||||
}
|
||||
} else {
|
||||
} else if (!value.isSkipped) {
|
||||
LOGGER.error("${item.registryName} cant resolve ${recipe.output.item}")
|
||||
minimal = null
|
||||
break
|
||||
}
|
||||
@ -355,6 +356,40 @@ object RecipeResolverManager : SimpleJsonResourceReloadListener(GsonBuilder().se
|
||||
return Result(result)
|
||||
}
|
||||
|
||||
private fun tryToBacktrack(item: Item, makeCommentary: Boolean): Result {
|
||||
val getResult = cachedIterationResults[item]
|
||||
|
||||
if (getResult != null) {
|
||||
return getResult
|
||||
}
|
||||
|
||||
var value: IMatterValue? = MatterManager.getDirect(item)
|
||||
|
||||
if (value?.hasMatterValue == true) {
|
||||
return Result(value)
|
||||
}
|
||||
|
||||
value = determinedValues[item]
|
||||
|
||||
if (value?.hasMatterValue == true) {
|
||||
return Result(value)
|
||||
}
|
||||
|
||||
if (item in seenItems && item != seenItems.last()) {
|
||||
return Result.SKIPPED
|
||||
}
|
||||
|
||||
seenItems.addLast(item)
|
||||
|
||||
try {
|
||||
val result = doTryToBacktrack(item, makeCommentary)
|
||||
cachedIterationResults[item] = result
|
||||
return result
|
||||
} finally {
|
||||
seenItems.removeLast()
|
||||
}
|
||||
}
|
||||
|
||||
private fun doDetermineValue(item: Item): Result {
|
||||
var minimalMatter: ImpreciseFraction? = null
|
||||
var minimalComplexity: Double? = null
|
||||
|
Loading…
Reference in New Issue
Block a user