From ecc3a2a5e49ecf76b6811d8f42daa1ceb79ce590 Mon Sep 17 00:00:00 2001 From: miozune Date: Mon, 18 Jul 2022 11:27:19 +0900 Subject: Allow showing multiple recipe owners (#1136) --- src/main/java/gregtech/api/util/GT_Recipe.java | 33 +++++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 5a077b4171..a50c925e61 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -88,11 +88,11 @@ public class GT_Recipe implements Comparable { /** * Stores which mod added this recipe */ - public ModContainer owner = null; + public List owners = new ArrayList<>(); /** * Stores stack traces where this recipe was added */ - public List stackTraces = null; + public List> stackTraces = new ArrayList<>(); private GT_Recipe(GT_Recipe aRecipe) { mInputs = GT_Utility.copyStackArray((Object[]) aRecipe.mInputs); @@ -109,6 +109,7 @@ public class GT_Recipe implements Comparable { mFakeRecipe = aRecipe.mFakeRecipe; mEnabled = aRecipe.mEnabled; mHidden = aRecipe.mHidden; + owners = new ArrayList<>(aRecipe.owners); reloadOwner(); } @@ -570,19 +571,39 @@ public class GT_Recipe implements Comparable { } public void reloadOwner() { - this.owner = Loader.instance().activeModContainer(); + setOwner(Loader.instance().activeModContainer()); final List excludedClasses = Arrays.asList( "java.lang.Thread", "gregtech.api.util.GT_Recipe", "gregtech.common.GT_RecipeAdder"); if (GT_Mod.gregtechproxy.mNEIRecipeOwnerStackTrace) { - this.stackTraces = new ArrayList<>(); + List toAdd = new ArrayList<>(); for (StackTraceElement stackTrace : Thread.currentThread().getStackTrace()) { - if (!excludedClasses.stream().anyMatch(c -> stackTrace.getClassName().contains(c))) { - this.stackTraces.add(stackTrace); + if (excludedClasses.stream().noneMatch(c -> stackTrace.getClassName().contains(c))) { + toAdd.add(stackTrace); } } + stackTraces.add(toAdd); + } + } + + public void setOwner(ModContainer newOwner) { + ModContainer oldOwner = owners.size() > 0 ? this.owners.get(owners.size() - 1) : null; + if (newOwner != null && newOwner != oldOwner) { + owners.add(newOwner); + } + } + + /** + * Use in case {@link Loader#activeModContainer()} isn't helpful + */ + public void setOwner(String modId) { + for (ModContainer mod : Loader.instance().getModList()) { + if (mod.getModId().equals(modId)) { + setOwner(mod); + return; + } } } -- cgit