Skip to content

Commit

Permalink
Updated REI, fixed json recipe crash
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Apr 9, 2024
1 parent a836cfe commit e213582
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ minecraft_version=1.20.4
rhino_version=2004.2.3-build.4
min_rhino_version=2004.2.3-build.4
architectury_version=11.1.17
rei_version=14.0.688
rei_version=14.0.692
#rei_comp_version=9.0.16
neoforge_version=20.4.223
#forge_bookshelf_version=11.0.3
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/dev/latvian/mods/kubejs/recipe/JsonRecipeJS.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import dev.latvian.mods.kubejs.util.UtilsJS;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.Recipe;

public class JsonRecipeJS extends RecipeJS {
@Override
Expand All @@ -18,8 +17,15 @@ public void serialize() {
@Override
public boolean hasInput(ReplacementMatch match) {
if (CommonProperties.get().matchJsonRecipes && match instanceof ItemMatch m && getOriginalRecipe() != null) {
for (var ingredient : getOriginalRecipe().getIngredients()) {
if (ingredient != Ingredient.EMPTY && ingredient.kjs$canBeUsedForMatching() && m.contains(ingredient)) {
var arr = getOriginalRecipe().getIngredients();

//noinspection ConstantValue
if (arr == null || arr.isEmpty()) {
return false;
}

for (var ingredient : arr) {
if (ingredient != null && ingredient != Ingredient.EMPTY && ingredient.kjs$canBeUsedForMatching() && m.contains(ingredient)) {
return true;
}
}
Expand All @@ -34,10 +40,10 @@ public boolean replaceInput(ReplacementMatch match, InputReplacement with) {
}

@Override
@SuppressWarnings("ConstantValue")
public boolean hasOutput(ReplacementMatch match) {
if (CommonProperties.get().matchJsonRecipes && match instanceof ItemMatch m && getOriginalRecipe() != null) {
var result = ((Recipe<?>) this).getResultItem(UtilsJS.staticRegistryAccess);
var result = getOriginalRecipe().getResultItem(UtilsJS.staticRegistryAccess);
//noinspection ConstantValue
return result != null && result != ItemStack.EMPTY && !result.isEmpty() && m.contains(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,11 @@ public void stage(RecipeFilter filter, String stage) {
}

public static void runInParallel(final Runnable runnable) {
PARALLEL_THREAD_POOL.invoke(ForkJoinTask.adapt(runnable));
try {
PARALLEL_THREAD_POOL.invoke(ForkJoinTask.adapt(runnable));
} catch (Throwable ex) {
ConsoleJS.SERVER.error("Error running a recipe task", ex, SKIP_ERROR);
}
}

public static <T> T runInParallel(final Callable<T> callable) {
Expand Down

0 comments on commit e213582

Please sign in to comment.