From f50fbb2475996e34349ceaa3121c983f2eb2a445 Mon Sep 17 00:00:00 2001 From: miozune Date: Mon, 4 Dec 2023 06:49:43 +0900 Subject: [PATCH] Migrate to new RecipeMap (#37) * Migrate to new RecipeMap * Fix wildcard import * update deps --------- Co-authored-by: Martin Robertz --- .github/scripts/test-no-error-reports.sh | 27 ------------- .gitignore | 9 ++++- dependencies.gradle | 17 +++++--- .../nee/processor/GTPPRecipeProcessor.java | 32 +++++++++++---- .../processor/GregTech5RecipeProcessor.java | 39 ++++++++++++++----- .../vfyjxf/nee/processor/RecipeProcessor.java | 15 +++++-- 6 files changed, 84 insertions(+), 55 deletions(-) delete mode 100644 .github/scripts/test-no-error-reports.sh diff --git a/.github/scripts/test-no-error-reports.sh b/.github/scripts/test-no-error-reports.sh deleted file mode 100644 index e387660..0000000 --- a/.github/scripts/test-no-error-reports.sh +++ /dev/null @@ -1,27 +0,0 @@ -if [[ -d "run/crash-reports" ]]; then - echo "Crash reports detected:" - cat $directory/* - exit 1 -fi - -if grep --quiet "Fatal errors were detected" server.log; then - echo "Fatal errors detected:" - cat server.log - exit 1 -fi - -if grep --quiet "The state engine was in incorrect state ERRORED and forced into state SERVER_STOPPED" server.log; then - echo "Server force stopped:" - cat server.log - exit 1 -fi - -if grep --quiet 'Done .+ For help, type "help" or "?"' server.log; then - echo "Server didn't finish startup:" - cat server.log - exit 1 -fi - -echo "No crash reports detected" -exit 0 - diff --git a/.gitignore b/.gitignore index 75c41f6..27a8ae0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .gradle .settings /.idea/ +/.vscode/ /run/ /build/ /eclipse/ @@ -25,7 +26,13 @@ whitelist.json *.iml *.ipr *.iws -src/main/resources/mixins.*.json +src/main/resources/mixins.*([!.]).json *.bat *.DS_Store !gradlew.bat +.factorypath +addon.local.gradle +addon.local.gradle.kts +addon.late.local.gradle +addon.late.local.gradle.kts +layout.json \ No newline at end of file diff --git a/dependencies.gradle b/dependencies.gradle index 35e0843..d1a2d21 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,16 +1,23 @@ dependencies { api("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-291-GTNH:dev") - api("com.github.GTNewHorizons:NotEnoughItems:2.4.12-GTNH:dev") - implementation("com.github.GTNewHorizons:Baubles:1.0.2:dev") + api("com.github.GTNewHorizons:NotEnoughItems:2.4.13-GTNH:dev") + implementation("com.github.GTNewHorizons:Baubles:1.0.3:dev") implementation("com.github.GTNewHorizons:WirelessCraftingTerminal:1.10.1:dev") - compileOnly("com.github.GTNewHorizons:AE2FluidCraft-Rework:1.1.67-gtnh:dev") { transitive = false } + compileOnly("com.github.GTNewHorizons:AE2FluidCraft-Rework:1.1.69-gtnh:dev") { transitive = false } + compileOnly("com.github.GTNewHorizons:Avaritiaddons:1.6.0-GTNH:dev") { transitive = false } + compileOnly("com.github.GTNewHorizons:BuildCraftCompat:7.1.16:dev") { transitive = false } + compileOnly('com.github.GTNewHorizons:EnderIO:2.5.6:dev') { transitive=false } + compileOnly("com.github.GTNewHorizons:ForestryMC:4.7.0:dev") { transitive = false } + compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.44.96:dev") { transitive = false } + compileOnly("com.github.GTNewHorizons:ThaumicEnergistics:1.5.3-GTNH:dev") { transitive = false } + compileOnly("com.github.GTNewHorizons:AE2FluidCraft-Rework:1.1.69-gtnh:dev") { transitive = false } compileOnly("com.github.GTNewHorizons:Avaritiaddons:1.6.0-GTNH:dev") { transitive = false } compileOnly("com.github.GTNewHorizons:BuildCraftCompat:7.1.16:dev") { transitive = false } compileOnly('com.github.GTNewHorizons:EnderIO:2.5.6:dev') {transitive=false} compileOnly("com.github.GTNewHorizons:ForestryMC:4.7.0:dev") { transitive = false } - compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.44.91:dev") { transitive = false } - compileOnly("com.github.GTNewHorizons:GTplusplus:1.10.34:dev") { transitive = false } + compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.44.96:dev") { transitive = false } + compileOnly("com.github.GTNewHorizons:GTplusplus:1.10.37:dev") { transitive = false } compileOnly("com.github.GTNewHorizons:ThaumicEnergistics:1.5.3-GTNH:dev") { transitive = false } compileOnly("com.github.GTNewHorizons:Botania:1.10.3-GTNH:dev") { transitive = false } compileOnly("com.gregoriust.gregtech:gregtech_1.7.10:6.14.23:dev") { transitive = false } diff --git a/src/main/java/com/github/vfyjxf/nee/processor/GTPPRecipeProcessor.java b/src/main/java/com/github/vfyjxf/nee/processor/GTPPRecipeProcessor.java index db94e7e..89c44db 100644 --- a/src/main/java/com/github/vfyjxf/nee/processor/GTPPRecipeProcessor.java +++ b/src/main/java/com/github/vfyjxf/nee/processor/GTPPRecipeProcessor.java @@ -1,7 +1,7 @@ package com.github.vfyjxf.nee.processor; import java.util.ArrayList; -import java.util.Collections; +import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -10,24 +10,40 @@ import codechicken.nei.PositionedStack; import codechicken.nei.recipe.IRecipeHandler; -import gregtech.api.util.GTPP_Recipe; /** * @author vfyjxf */ public class GTPPRecipeProcessor implements IRecipeProcessor { + private final boolean isNH; + + public GTPPRecipeProcessor(boolean isNH) { + this.isNH = isNH; + } + @Nonnull @Override - @SuppressWarnings("deprecation") public Set getAllOverlayIdentifier() { - HashSet identifiers = new HashSet<>(Collections.singletonList("GTPP_Decayables")); + HashSet identifiers = new HashSet<>(); + identifiers.add("GTPP_Decayables"); + if (isNH) { + return identifiers; + } - // GTNH version of GT++ deprecated this, but other versions still use it - for (GTPP_Recipe.GTPP_Recipe_Map_Internal gtppMap : GTPP_Recipe.GTPP_Recipe_Map_Internal.sMappingsEx) { - if (gtppMap.mNEIAllowed) { - identifiers.add(gtppMap.mNEIName); + try { + Class gtRecipeMapClazz = Class.forName("gregtech.api.util.GT_Recipe$GT_Recipe_Map"); + Class gtppRecipeMapClazz = Class.forName("gregtech.api.util.GTPP_Recipe$GTPP_Recipe_Map_Internal"); + Collection sMappingsEx = (Collection) gtppRecipeMapClazz.getDeclaredField("sMappingsEx").get(null); + for (Object gtppMap : sMappingsEx) { + boolean mNEIAllowed = gtRecipeMapClazz.getDeclaredField("mNEIAllowed").getBoolean(gtppMap); + if (mNEIAllowed) { + String mNEIName = (String) gtRecipeMapClazz.getDeclaredField("mNEIName").get(gtppMap); + identifiers.add(mNEIName); + } } + } catch (Exception e) { + throw new RuntimeException(e); } return identifiers; diff --git a/src/main/java/com/github/vfyjxf/nee/processor/GregTech5RecipeProcessor.java b/src/main/java/com/github/vfyjxf/nee/processor/GregTech5RecipeProcessor.java index 98c52eb..ed2201f 100644 --- a/src/main/java/com/github/vfyjxf/nee/processor/GregTech5RecipeProcessor.java +++ b/src/main/java/com/github/vfyjxf/nee/processor/GregTech5RecipeProcessor.java @@ -1,9 +1,11 @@ package com.github.vfyjxf.nee.processor; import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import javax.annotation.Nonnull; @@ -19,7 +21,7 @@ import codechicken.nei.PositionedStack; import codechicken.nei.recipe.IRecipeHandler; import gregtech.api.enums.ItemList; -import gregtech.api.util.GT_Recipe; +import gregtech.api.recipe.RecipeCategory; import gregtech.nei.GT_NEI_DefaultHandler.FixedPositionedStack; /** @@ -29,19 +31,23 @@ public class GregTech5RecipeProcessor implements IRecipeProcessor { private static final Class gtDefaultClz, gtAssLineClz; + private final boolean isNH; + static { Class gtDH = null; Class gtAL = null; try { gtDH = Class.forName("gregtech.nei.GT_NEI_DefaultHandler"); gtAL = Class.forName("gregtech.nei.GT_NEI_AssLineHandler"); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } + } catch (ClassNotFoundException ignored) {} gtDefaultClz = gtDH; gtAssLineClz = gtAL; } + public GregTech5RecipeProcessor(boolean isNH) { + this.isNH = isNH; + } + /** * For resolving NoSuchMethodError Copied from GTNewHorizons/GT5-Unofficial. */ @@ -62,15 +68,28 @@ public static boolean isStackValid(Object aStack) { @Nonnull @Override public Set getAllOverlayIdentifier() { + if (isNH) { + return RecipeCategory.ALL_RECIPE_CATEGORIES.values().stream() + .filter(category -> category.recipeMap.getFrontend().getNEIProperties().registerNEI) + .map(category -> category.unlocalizedName).collect(Collectors.toSet()); + } - Set identifiers = new HashSet<>(); - for (GT_Recipe.GT_Recipe_Map tMap : GT_Recipe.GT_Recipe_Map.sMappings) { - if (tMap.mNEIAllowed) { - identifiers.add(tMap.mNEIName); + try { + Set identifiers = new HashSet<>(); + Class recipeMapClazz = Class.forName("gregtech.api.util.GT_Recipe$GT_Recipe_Map"); + Collection sMappings = (Collection) recipeMapClazz.getDeclaredField("sMappings").get(null); + for (Object tMap : sMappings) { + boolean mNEIAllowed = recipeMapClazz.getDeclaredField("mNEIAllowed").getBoolean(tMap); + if (mNEIAllowed) { + String mNEIName = (String) recipeMapClazz.getDeclaredField("mNEIName").get(tMap); + identifiers.add(mNEIName); + } } + identifiers.add("gt.recipe.fakeAssemblylineProcess"); + return identifiers; + } catch (Exception e) { + throw new RuntimeException(e); } - identifiers.add("gt.recipe.fakeAssemblylineProcess"); - return identifiers; } @Nonnull diff --git a/src/main/java/com/github/vfyjxf/nee/processor/RecipeProcessor.java b/src/main/java/com/github/vfyjxf/nee/processor/RecipeProcessor.java index 9778d68..d16572e 100644 --- a/src/main/java/com/github/vfyjxf/nee/processor/RecipeProcessor.java +++ b/src/main/java/com/github/vfyjxf/nee/processor/RecipeProcessor.java @@ -27,9 +27,16 @@ public static void init() { recipeProcessors.add(new BotaniaRecipeProcessor()); } + boolean isNH = false; if (Loader.isModLoaded("gregtech") && !Loader.isModLoaded("gregapi")) { - NotEnoughEnergistics.logger.info("Found GregTech5,install GregTech5 support"); - recipeProcessors.add(new GregTech5RecipeProcessor()); + try { + Class.forName("gregtech.api.recipe.RecipeMap"); + isNH = true; + NotEnoughEnergistics.logger.info("Found NH version of GregTech5, install GregTech5 support"); + } catch (ClassNotFoundException ignored) { + NotEnoughEnergistics.logger.info("Found GregTech5, install GregTech5 support"); + } + recipeProcessors.add(new GregTech5RecipeProcessor(isNH)); } if (Loader.isModLoaded("gregapi") && Loader.isModLoaded("gregapi_post")) { NotEnoughEnergistics.logger.info("Found GregTech6,install GregTech6 support"); @@ -77,9 +84,9 @@ public static void init() { } if (Loader.isModLoaded("miscutils")) { NotEnoughEnergistics.logger.info("Found GT++, install GT++ support"); - recipeProcessors.add(new GTPPRecipeProcessor()); + recipeProcessors.add(new GTPPRecipeProcessor(isNH)); } - if (Loader.isModLoaded("GoodGenerator")) { + if (!isNH && Loader.isModLoaded("GoodGenerator")) { NotEnoughEnergistics.logger.info("Found Good Generator, install Good Generator support"); recipeProcessors.add(new GoodGeneratorRecipeProcessor()); }