Skip to content

Commit

Permalink
Use client-side registry access for rendering guidebook recipes. (#8117)
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte authored Aug 5, 2024
1 parent 5261675 commit a97f192
Showing 1 changed file with 6 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ private record RecipeTypeMapping<T extends Recipe<C>, C extends RecipeInput>(
Function<RecipeHolder<T>, LytBlock> factory) {
@Nullable
LytBlock tryCreate(RecipeManager recipeManager, Item resultItem) {
var registryAccess = Platform.getClientRegistryAccess();

// We try to find non-special recipes first then fall back to special
List<RecipeHolder<T>> fallbackCandidates = new ArrayList<>();
for (var recipe : recipeManager.byType(recipeType)) {
Expand All @@ -117,24 +119,14 @@ LytBlock tryCreate(RecipeManager recipeManager, Item resultItem) {
continue;
}

try {
if (recipe.value().getResultItem(null).getItem() == resultItem) {
return factory.apply(recipe);
}
} catch (Exception ignored) {
// :-P
// Happens if the recipe doesn't accept a null RegistryAccess
if (recipe.value().getResultItem(registryAccess).getItem() == resultItem) {
return factory.apply(recipe);
}
}

for (var recipe : fallbackCandidates) {
try {
if (recipe.value().getResultItem(null).getItem() == resultItem) {
return factory.apply(recipe);
}
} catch (Exception ignored) {
// :-P
// Happens if the recipe doesn't accept a null RegistryAccess
if (recipe.value().getResultItem(registryAccess).getItem() == resultItem) {
return factory.apply(recipe);
}
}

Expand Down

0 comments on commit a97f192

Please sign in to comment.