Rename resolver to finder

This commit is contained in:
DBotThePony 2022-11-06 16:23:47 +07:00
parent b2ea1e9b24
commit b1bd0aa2b5
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -83,14 +83,14 @@ object RecipeResolverManager : SimpleJsonResourceReloadListener(GsonBuilder().se
get() = if (name == null) "One of recipes" else "Recipe $name"
}
fun interface Resolver {
fun interface Finder {
/**
* Returned stream should be thread safe
*/
fun resolve(server: MinecraftServer, json: JsonObject): Stream<ResolvedRecipe>
fun find(server: MinecraftServer, json: JsonObject): Stream<ResolvedRecipe>
}
private val delegate = RegistryDelegate<Resolver>("recipe_resolver") {
private val delegate = RegistryDelegate<Finder>("recipe_resolver") {
disableSync()
disableSaving()
}
@ -100,12 +100,12 @@ object RecipeResolverManager : SimpleJsonResourceReloadListener(GsonBuilder().se
init {
registrar.register("simple") {
Resolver { server, data ->
Finder { server, data ->
val location = (data["recipe_type"] ?: throw JsonSyntaxException("Missing recipe type")).let { ResourceLocation.tryParse(it.asString) } ?: throw JsonSyntaxException("Invalid recipe type: ${data["recipe_type"]}")
if (!ForgeRegistries.RECIPE_TYPES.containsKey(location)) {
LOGGER.error("Invalid or missing recipe category: $location!")
return@Resolver Stream.empty()
return@Finder Stream.empty()
}
val findRecipeType = ForgeRegistries.RECIPE_TYPES.getValue(location) as RecipeType<Recipe<Container>>? ?: throw ConcurrentModificationException()
@ -156,7 +156,7 @@ object RecipeResolverManager : SimpleJsonResourceReloadListener(GsonBuilder().se
var resolved = false
private set
private var foundResolvers: Map<ResourceLocation, Pair<Resolver, JsonObject>> = ImmutableMap.of()
private var foundResolvers: Map<ResourceLocation, Pair<Finder, JsonObject>> = ImmutableMap.of()
override fun prepare(
p_10771_: ResourceManager,
@ -178,7 +178,7 @@ object RecipeResolverManager : SimpleJsonResourceReloadListener(GsonBuilder().se
determinedValues.clear()
commentary.clear()
val builder = ImmutableMap.Builder<ResourceLocation, Pair<Resolver, JsonObject>>()
val builder = ImmutableMap.Builder<ResourceLocation, Pair<Finder, JsonObject>>()
for ((key, json) in map) {
if (json !is JsonObject) {
@ -401,7 +401,7 @@ object RecipeResolverManager : SimpleJsonResourceReloadListener(GsonBuilder().se
val stream = Streams.concat(*foundResolvers.map {
try {
it.value.first.resolve(server, it.value.second).parallel()
it.value.first.find(server, it.value.second).parallel()
} catch(err: Throwable) {
LOGGER.fatal("Recipe resolver ${it.key} experienced internal error", err)
throw RuntimeException("Recipe resolver ${it.key} experienced internal error", err)