From 00f1db61dce7a42a6605e117d1f6954967c39784 Mon Sep 17 00:00:00 2001 From: Mary <33456283+FourIsTheNumber@users.noreply.github.com> Date: Sat, 21 Sep 2024 02:16:52 -0400 Subject: [PATCH] Prevent duplicate material registry (#3240) --- src/main/java/gregtech/api/enums/OrePrefixes.java | 15 +++++++++++++++ .../loaders/oreprocessing/ProcessingPlate.java | 1 - 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/gregtech/api/enums/OrePrefixes.java b/src/main/java/gregtech/api/enums/OrePrefixes.java index 418fe716816..27cf37a2de3 100644 --- a/src/main/java/gregtech/api/enums/OrePrefixes.java +++ b/src/main/java/gregtech/api/enums/OrePrefixes.java @@ -15,6 +15,7 @@ import com.google.common.collect.ImmutableList; +import gregtech.api.GregTechAPI; import gregtech.api.enums.TCAspects.TC_AspectStack; import gregtech.api.interfaces.ICondition; import gregtech.api.interfaces.IOreRecipeRegistrator; @@ -1179,6 +1180,8 @@ public enum OrePrefixes { } else if (name().startsWith("battery")) { new TC_AspectStack(TCAspects.ELECTRUM, 1).addToAspectList(mAspects); } + + GregTechAPI.sGTCompleteLoad.add(this::onLoadComplete); } public static boolean isInstanceOf(String aName, OrePrefixes aPrefix) { @@ -1297,12 +1300,20 @@ public boolean add(IOreRecipeRegistrator aRegistrator) { return mOreProcessing.add(aRegistrator); } + // Hack to prevent duplicate registry of oredicted materials + HashSet used = new HashSet<>(); + public void processOre(Materials aMaterial, String aOreDictName, String aModName, ItemStack aStack) { if (aMaterial == null) { return; } + if (aMaterial != Materials._NULL && !used.add(aMaterial)) { + GTLog.out.println("Duplicate material registry attempted by " + aModName + " for " + aOreDictName); + return; + } + if (aMaterial.contains(SubTag.NO_RECIPES)) { return; } @@ -1325,6 +1336,10 @@ public void processOre(Materials aMaterial, String aOreDictName, String aModName } } + public void onLoadComplete() { + used = null; + } + public Object get(Object aMaterial) { if (aMaterial instanceof Materials) return new ItemData(this, (Materials) aMaterial); return name() + aMaterial; diff --git a/src/main/java/gregtech/loaders/oreprocessing/ProcessingPlate.java b/src/main/java/gregtech/loaders/oreprocessing/ProcessingPlate.java index 05e6aaeeb35..beedad1d7ab 100644 --- a/src/main/java/gregtech/loaders/oreprocessing/ProcessingPlate.java +++ b/src/main/java/gregtech/loaders/oreprocessing/ProcessingPlate.java @@ -19,7 +19,6 @@ import static gregtech.api.util.GTRecipeBuilder.TICKS; import static gregtech.api.util.GTRecipeBuilder.WILDCARD; import static gregtech.api.util.GTRecipeConstants.ADDITIVE_AMOUNT; -import static gregtech.api.util.GTRecipeConstants.COMPRESSION_TIER; import static gregtech.api.util.GTRecipeConstants.FUEL_TYPE; import static gregtech.api.util.GTRecipeConstants.FUEL_VALUE; import static gregtech.api.util.GTUtility.calculateRecipeEU;