Fix recursive recipes resolving bugs
This commit is contained in:
parent
804dfed42c
commit
dcdb4b88e4
@ -66,7 +66,6 @@ import ru.dbotthepony.mc.otm.storage.ItemStackWrapper
|
||||
import java.io.File
|
||||
import java.math.BigInteger
|
||||
import java.util.*
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.stream.Stream
|
||||
import kotlin.ConcurrentModificationException
|
||||
import kotlin.collections.ArrayDeque
|
||||
@ -532,7 +531,7 @@ object MatterManager {
|
||||
return Result(result)
|
||||
}
|
||||
|
||||
private fun tryToBacktrack(item: Item, makeCommentary: Boolean): Result {
|
||||
private fun tryToBacktrack(item: Item, asFallback: Boolean): Result {
|
||||
val getResult = cachedIterationResults[item]
|
||||
|
||||
if (getResult != null) {
|
||||
@ -541,34 +540,25 @@ object MatterManager {
|
||||
|
||||
val value = Registry.direct(item)
|
||||
|
||||
if (value.hasMatterValue) {
|
||||
if (value.hasMatterValue)
|
||||
return Result(value)
|
||||
}
|
||||
|
||||
val value2 = determinedValues[item]
|
||||
|
||||
if (value2?.hasMatterValue == true) {
|
||||
if (value2?.hasMatterValue == true)
|
||||
return Result(value2)
|
||||
}
|
||||
|
||||
val value3 = Registry.indirect(item)
|
||||
|
||||
if (value3.value != null) {
|
||||
return value3
|
||||
}
|
||||
|
||||
if (item in seenItems && item != seenItems.last()) {
|
||||
return Result.SKIPPED
|
||||
}
|
||||
if (item in seenItems)
|
||||
if (!asFallback || item == seenItems.last() && seenItems.count { it == item } == 1)
|
||||
return Result.SKIPPED
|
||||
|
||||
seenItems.addLast(item)
|
||||
|
||||
try {
|
||||
val indirect = Registry.indirect(item)
|
||||
if (indirect.value != null)
|
||||
return indirect
|
||||
val value3 = Registry.indirect(item)
|
||||
if (value3.value != null)
|
||||
return value3
|
||||
|
||||
val result = doTryToBacktrack(item, makeCommentary)
|
||||
val result = doTryToBacktrack(item, !asFallback)
|
||||
cachedIterationResults[item] = result
|
||||
return result
|
||||
} finally {
|
||||
@ -583,7 +573,7 @@ object MatterManager {
|
||||
val recipes = output2Recipes[item]
|
||||
|
||||
if (recipes == null || recipes.isEmpty()) {
|
||||
return tryToBacktrack(item, true)
|
||||
return tryToBacktrack(item, false)
|
||||
}
|
||||
|
||||
var hadSkips = false
|
||||
@ -604,12 +594,11 @@ object MatterManager {
|
||||
var minimal: IMatterValue? = null
|
||||
var minimalMultiplier = 0.0
|
||||
|
||||
for (input in inputs) {
|
||||
innerInputsLoop@ for (input in inputs) {
|
||||
val ivalue = determineValue(input.item)
|
||||
|
||||
if (ivalue.isMissing) {
|
||||
if (recipe.isCritical)
|
||||
comment(item, TextComponent("Input '${input.item.registryName}' at input slot $i in ${recipe.formattedName} has no matter value"))
|
||||
comment(item, TextComponent("Input '${input.item.registryName}' at input slot $i in ${recipe.formattedName} has no matter value"))
|
||||
|
||||
if (recipe.isCritical) {
|
||||
return Result.MISSING
|
||||
@ -617,11 +606,14 @@ object MatterManager {
|
||||
continue@recipesLoop
|
||||
}
|
||||
} else if (ivalue.isSkipped) {
|
||||
if (recipe.isCritical)
|
||||
comment(item, TextComponent("Input '${input.item.registryName}' at input slot $i in ${recipe.formattedName} is recursive"))
|
||||
comment(item, TextComponent("Input '${input.item.registryName}' at input slot $i in ${recipe.formattedName} is recursive"))
|
||||
|
||||
hadSkips = true
|
||||
continue@recipesLoop
|
||||
if (inputs.size == 1) {
|
||||
hadSkips = true
|
||||
continue@recipesLoop
|
||||
} else {
|
||||
continue@innerInputsLoop
|
||||
}
|
||||
}
|
||||
|
||||
if (minimal == null || minimal > ivalue.value!!) {
|
||||
@ -662,7 +654,7 @@ object MatterManager {
|
||||
|
||||
if (minimalMatter == null || minimalComplexity == null) {
|
||||
if (hadSkips) {
|
||||
val backtrack = tryToBacktrack(item, false)
|
||||
val backtrack = tryToBacktrack(item, true)
|
||||
|
||||
if (backtrack.value == null) {
|
||||
return Result.SKIPPED
|
||||
@ -1183,6 +1175,7 @@ object MatterManager {
|
||||
|
||||
// TODO: /reload
|
||||
fun onServerStarted(event: ServerStartedEvent) {
|
||||
commentary.clear()
|
||||
Resolver.resolve(event.server)
|
||||
|
||||
matterValues.clear()
|
||||
|
Loading…
Reference in New Issue
Block a user