diff options
author | chochem <40274384+chochem@users.noreply.github.com> | 2023-05-19 18:56:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-19 19:56:11 +0200 |
commit | 3911a3bdcb1d75df91e2015d61e48b13944f0458 (patch) | |
tree | f4e0192cd0b35cef13b23a48a64d5dcade4df03c /src/main/java/gregtech/api/util | |
parent | 9aa0086254984fc81a551bb3e738985b2d570c25 (diff) | |
download | GT5-Unofficial-3911a3bdcb1d75df91e2015d61e48b13944f0458.tar.gz GT5-Unofficial-3911a3bdcb1d75df91e2015d61e48b13944f0458.tar.bz2 GT5-Unofficial-3911a3bdcb1d75df91e2015d61e48b13944f0458.zip |
Debug for recipe collisions (#2008)
* add collision debug
* fix npe
* try better names
* unwrap nested ifs
* do it for the other too
* follow some code writing suggestions
* add more info to panic crash
* code polishing
Diffstat (limited to 'src/main/java/gregtech/api/util')
-rw-r--r-- | src/main/java/gregtech/api/util/GT_Recipe.java | 36 | ||||
-rw-r--r-- | src/main/java/gregtech/api/util/GT_RecipeBuilder.java | 24 |
2 files changed, 58 insertions, 2 deletions
diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index a232096c85..6d660c67f6 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -5,6 +5,7 @@ import static gregtech.api.enums.Mods.GTPlusPlus; import static gregtech.api.enums.Mods.GregTech; import static gregtech.api.enums.Mods.NEICustomDiagrams; import static gregtech.api.enums.Mods.Railcraft; +import static gregtech.api.util.GT_RecipeBuilder.handleRecipeCollision; import static gregtech.api.util.GT_RecipeConstants.ADDITIVE_AMOUNT; import static gregtech.api.util.GT_RecipeMapUtil.*; import static gregtech.api.util.GT_Utility.formatNumbers; @@ -3738,7 +3739,40 @@ public class GT_Recipe implements Comparable<GT_Recipe> { if (specialHandler != null) r = specialHandler.apply(r); if (r == null) continue; if (checkForCollision - && findRecipe(null, false, true, Long.MAX_VALUE, r.mFluidInputs, r.mInputs) != null) continue; + && findRecipe(null, false, true, Long.MAX_VALUE, r.mFluidInputs, r.mInputs) != null) { + StringBuilder errorInfo = new StringBuilder(); + boolean hasAnEntry = false; + for (FluidStack fStack : r.mFluidInputs) { + if (fStack == null) { + continue; + } + String s = fStack.getLocalizedName(); + if (s == null) { + continue; + } + if (hasAnEntry) { + errorInfo.append("+") + .append(s); + } else { + errorInfo.append(s); + } + hasAnEntry = true; + } + for (ItemStack iStack : r.mInputs) { + if (iStack == null) { + continue; + } + String s = iStack.getDisplayName(); + if (hasAnEntry) { + errorInfo.append("+" + s); + } else { + errorInfo.append(s); + } + hasAnEntry = true; + } + handleRecipeCollision(errorInfo.toString()); + continue; + } ret.add(add(r)); } if (!ret.isEmpty()) { diff --git a/src/main/java/gregtech/api/util/GT_RecipeBuilder.java b/src/main/java/gregtech/api/util/GT_RecipeBuilder.java index bdd09f0a34..0553d08805 100644 --- a/src/main/java/gregtech/api/util/GT_RecipeBuilder.java +++ b/src/main/java/gregtech/api/util/GT_RecipeBuilder.java @@ -1,6 +1,14 @@ package gregtech.api.util; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; import java.util.function.Function; import javax.annotation.Nonnull; @@ -126,6 +134,20 @@ public class GT_RecipeBuilder { } } + public static void handleRecipeCollision(String details) { + if (!PANIC_MODE && !DEBUG_MODE) { + return; + } + GT_Log.err.print("Recipe collision resulting in recipe loss detected with "); + GT_Log.err.println(details); + if (PANIC_MODE) { + throw new IllegalArgumentException("Recipe Collision"); + } else { + // place a breakpoint here to catch all these issues + new IllegalArgumentException().printStackTrace(GT_Log.err); + } + } + /** * Non-OreDicted item inputs. Assumes input is unified. */ |