From c1c30cf1ad44c30bc51dfe41608f0cc01b895293 Mon Sep 17 00:00:00 2001 From: miozune Date: Tue, 28 Nov 2023 17:46:54 +0900 Subject: [PATCH] Compat with GT change --- build.gradle | 4 +- dependencies.gradle | 1 - .../nei/recipes/DefaultExtractorLoader.java | 41 +++++++++++++------ .../github/util/ModAndClassUtil.java | 16 +++++++- 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/build.gradle b/build.gradle index f3a7fa278..4e31dc883 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: 1699290261 +//version: 1700844281 /* DO NOT CHANGE THIS FILE! Also, you may replace this file at any time if there is an update available. @@ -302,7 +302,7 @@ if (apiPackage) { } if (accessTransformersFile) { - for (atFile in accessTransformersFile.split(",")) { + for (atFile in accessTransformersFile.split(" ")) { String targetFile = "src/main/resources/META-INF/" + atFile.trim() if (!getFile(targetFile).exists()) { throw new GradleException("Could not resolve \"accessTransformersFile\"! Could not find " + targetFile) diff --git a/dependencies.gradle b/dependencies.gradle index 4a5039df5..5ed826b7c 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -52,7 +52,6 @@ dependencies { compileOnly('com.gregoriust.gregtech:gregtech_1.7.10:6.14.23:dev') { transitive = false } compileOnly('com.github.GTNewHorizons:OpenComputers:1.9.19-GTNH:dev') { transitive = false } compileOnly('com.github.GTNewHorizons:ThaumicEnergistics:1.5.0-GTNH:dev') { transitive = false } - compileOnly('com.github.GTNewHorizons:GTplusplus:1.10.30:dev') { transitive = false } compileOnly("com.github.GTNewHorizons:Hodgepodge:2.3.31:dev") { transitive = false } runtimeOnlyNonPublishable("com.github.GTNewHorizons:DuraDisplay:1.1.7:dev") diff --git a/src/main/java/com/glodblock/github/nei/recipes/DefaultExtractorLoader.java b/src/main/java/com/glodblock/github/nei/recipes/DefaultExtractorLoader.java index 90329a1c3..ee2bff4fb 100644 --- a/src/main/java/com/glodblock/github/nei/recipes/DefaultExtractorLoader.java +++ b/src/main/java/com/glodblock/github/nei/recipes/DefaultExtractorLoader.java @@ -1,5 +1,7 @@ package com.glodblock.github.nei.recipes; +import java.util.Collection; + import com.glodblock.github.nei.recipes.extractor.AvaritiaRecipeExtractor; import com.glodblock.github.nei.recipes.extractor.EnderIORecipeExtractor; import com.glodblock.github.nei.recipes.extractor.ForestryRecipeExtractor; @@ -19,8 +21,6 @@ import forestry.factory.recipes.nei.NEIHandlerSqueezer; import forestry.factory.recipes.nei.NEIHandlerStill; import gregapi.recipes.Recipe; -import gregtech.api.util.GTPP_Recipe; -import gregtech.api.util.GT_Recipe; public class DefaultExtractorLoader implements Runnable { @@ -32,12 +32,19 @@ public void run() { FluidRecipe.addRecipeMap("crafting2x2", new VanillaRecipeExtractor(true)); if (ModAndClassUtil.GT5) { - for (GT_Recipe.GT_Recipe_Map tMap : GT_Recipe.GT_Recipe_Map.sMappings) { - FluidRecipe.addRecipeMap( - tMap.mNEIName, - new GregTech5RecipeExtractor( - tMap.mNEIName.equals("gt.recipe.scanner") - || tMap.mNEIName.equals("gt.recipe.fakeAssemblylineProcess"))); + try { + Class recipeMapClazz = Class.forName("gregtech.api.util.GT_Recipe$GT_Recipe_Map"); + Collection sMappings = (Collection) recipeMapClazz.getDeclaredField("sMappings").get(null); + for (Object tMap : sMappings) { + String mNEIName = (String) recipeMapClazz.getDeclaredField("mNEIName").get(tMap); + FluidRecipe.addRecipeMap( + mNEIName, + new GregTech5RecipeExtractor( + mNEIName.equals("gt.recipe.scanner") + || mNEIName.equals("gt.recipe.fakeAssemblylineProcess"))); + } + } catch (Exception e) { + throw new RuntimeException(e); } } @@ -47,11 +54,21 @@ public void run() { } } - if (ModAndClassUtil.GTPP) { - for (GTPP_Recipe.GTPP_Recipe_Map_Internal gtppMap : GTPP_Recipe.GTPP_Recipe_Map_Internal.sMappingsEx) { - if (gtppMap.mNEIAllowed) { - FluidRecipe.addRecipeMap(gtppMap.mNEIName, new GTPPRecipeExtractor()); + if (ModAndClassUtil.GTPP && !ModAndClassUtil.GT5NH) { + 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); + FluidRecipe.addRecipeMap(mNEIName, new GTPPRecipeExtractor()); + } } + } catch (Exception e) { + throw new RuntimeException(e); } } diff --git a/src/main/java/com/glodblock/github/util/ModAndClassUtil.java b/src/main/java/com/glodblock/github/util/ModAndClassUtil.java index a32af0aeb..ed1b18b22 100644 --- a/src/main/java/com/glodblock/github/util/ModAndClassUtil.java +++ b/src/main/java/com/glodblock/github/util/ModAndClassUtil.java @@ -12,6 +12,13 @@ public final class ModAndClassUtil { + /** + * GTNH fork of GregTech5 Unofficial + */ + public static boolean GT5NH = false; + /** + * GregTech5 / GregTech5 Unofficial (Blood-Asp's "official" GT5u) + */ public static boolean GT5 = false; public static boolean GT6 = false; public static boolean EC2 = false; @@ -119,7 +126,14 @@ public static void init() { isTypeFilter = false; } - if (Loader.isModLoaded("gregtech") && !Loader.isModLoaded("gregapi")) GT5 = true; + if (Loader.isModLoaded("gregtech") && !Loader.isModLoaded("gregapi")) { + try { + Class.forName("gregtech.api.recipe.RecipeMap"); + GT5NH = true; + } catch (ClassNotFoundException e) { + GT5 = true; + } + } if (Loader.isModLoaded("gregapi") && Loader.isModLoaded("gregapi_post")) GT6 = true; if (Loader.isModLoaded("extracells")) EC2 = true; if (Loader.isModLoaded("EnderIO")) EIO = true;