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.io.File
|
||||||
import java.math.BigInteger
|
import java.math.BigInteger
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.CompletableFuture
|
|
||||||
import java.util.stream.Stream
|
import java.util.stream.Stream
|
||||||
import kotlin.ConcurrentModificationException
|
import kotlin.ConcurrentModificationException
|
||||||
import kotlin.collections.ArrayDeque
|
import kotlin.collections.ArrayDeque
|
||||||
@ -532,7 +531,7 @@ object MatterManager {
|
|||||||
return Result(result)
|
return Result(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun tryToBacktrack(item: Item, makeCommentary: Boolean): Result {
|
private fun tryToBacktrack(item: Item, asFallback: Boolean): Result {
|
||||||
val getResult = cachedIterationResults[item]
|
val getResult = cachedIterationResults[item]
|
||||||
|
|
||||||
if (getResult != null) {
|
if (getResult != null) {
|
||||||
@ -541,34 +540,25 @@ object MatterManager {
|
|||||||
|
|
||||||
val value = Registry.direct(item)
|
val value = Registry.direct(item)
|
||||||
|
|
||||||
if (value.hasMatterValue) {
|
if (value.hasMatterValue)
|
||||||
return Result(value)
|
return Result(value)
|
||||||
}
|
|
||||||
|
|
||||||
val value2 = determinedValues[item]
|
val value2 = determinedValues[item]
|
||||||
|
if (value2?.hasMatterValue == true)
|
||||||
if (value2?.hasMatterValue == true) {
|
|
||||||
return Result(value2)
|
return Result(value2)
|
||||||
}
|
|
||||||
|
|
||||||
val value3 = Registry.indirect(item)
|
if (item in seenItems)
|
||||||
|
if (!asFallback || item == seenItems.last() && seenItems.count { it == item } == 1)
|
||||||
if (value3.value != null) {
|
return Result.SKIPPED
|
||||||
return value3
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item in seenItems && item != seenItems.last()) {
|
|
||||||
return Result.SKIPPED
|
|
||||||
}
|
|
||||||
|
|
||||||
seenItems.addLast(item)
|
seenItems.addLast(item)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val indirect = Registry.indirect(item)
|
val value3 = Registry.indirect(item)
|
||||||
if (indirect.value != null)
|
if (value3.value != null)
|
||||||
return indirect
|
return value3
|
||||||
|
|
||||||
val result = doTryToBacktrack(item, makeCommentary)
|
val result = doTryToBacktrack(item, !asFallback)
|
||||||
cachedIterationResults[item] = result
|
cachedIterationResults[item] = result
|
||||||
return result
|
return result
|
||||||
} finally {
|
} finally {
|
||||||
@ -583,7 +573,7 @@ object MatterManager {
|
|||||||
val recipes = output2Recipes[item]
|
val recipes = output2Recipes[item]
|
||||||
|
|
||||||
if (recipes == null || recipes.isEmpty()) {
|
if (recipes == null || recipes.isEmpty()) {
|
||||||
return tryToBacktrack(item, true)
|
return tryToBacktrack(item, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
var hadSkips = false
|
var hadSkips = false
|
||||||
@ -604,12 +594,11 @@ object MatterManager {
|
|||||||
var minimal: IMatterValue? = null
|
var minimal: IMatterValue? = null
|
||||||
var minimalMultiplier = 0.0
|
var minimalMultiplier = 0.0
|
||||||
|
|
||||||
for (input in inputs) {
|
innerInputsLoop@ for (input in inputs) {
|
||||||
val ivalue = determineValue(input.item)
|
val ivalue = determineValue(input.item)
|
||||||
|
|
||||||
if (ivalue.isMissing) {
|
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) {
|
if (recipe.isCritical) {
|
||||||
return Result.MISSING
|
return Result.MISSING
|
||||||
@ -617,11 +606,14 @@ object MatterManager {
|
|||||||
continue@recipesLoop
|
continue@recipesLoop
|
||||||
}
|
}
|
||||||
} else if (ivalue.isSkipped) {
|
} 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
|
if (inputs.size == 1) {
|
||||||
continue@recipesLoop
|
hadSkips = true
|
||||||
|
continue@recipesLoop
|
||||||
|
} else {
|
||||||
|
continue@innerInputsLoop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minimal == null || minimal > ivalue.value!!) {
|
if (minimal == null || minimal > ivalue.value!!) {
|
||||||
@ -662,7 +654,7 @@ object MatterManager {
|
|||||||
|
|
||||||
if (minimalMatter == null || minimalComplexity == null) {
|
if (minimalMatter == null || minimalComplexity == null) {
|
||||||
if (hadSkips) {
|
if (hadSkips) {
|
||||||
val backtrack = tryToBacktrack(item, false)
|
val backtrack = tryToBacktrack(item, true)
|
||||||
|
|
||||||
if (backtrack.value == null) {
|
if (backtrack.value == null) {
|
||||||
return Result.SKIPPED
|
return Result.SKIPPED
|
||||||
@ -1183,6 +1175,7 @@ object MatterManager {
|
|||||||
|
|
||||||
// TODO: /reload
|
// TODO: /reload
|
||||||
fun onServerStarted(event: ServerStartedEvent) {
|
fun onServerStarted(event: ServerStartedEvent) {
|
||||||
|
commentary.clear()
|
||||||
Resolver.resolve(event.server)
|
Resolver.resolve(event.server)
|
||||||
|
|
||||||
matterValues.clear()
|
matterValues.clear()
|
||||||
|
Loading…
Reference in New Issue
Block a user