Migrate to new RecipeMap (#37)

* Migrate to new RecipeMap

* Fix wildcard import

* update deps

---------

Co-authored-by: Martin Robertz <[email protected]>
This commit is contained in:
miozuneandMartin Robertz authored and GitHub committed 2023-12-03 22:49:43 +01:00
1 parent 702f61256d
commit f50fbb2475
6 files changed
+86 -57

No files matched your search

@@ -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 javax.annotation.Nonnull;
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<String> getAllOverlayIdentifier() {
HashSet<String> identifiers = new HashSet<>(Collections.singletonList("GTPP_Decayables"));
HashSet<String> 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;
@@ -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 com.glodblock.github.client.gui.GuiFluidPatternTerminalEx;
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 class GregTech5RecipeProcessor implements IRecipeProcessor {
@Nonnull
@Override
public Set<String> getAllOverlayIdentifier() {
Set<String> identifiers = new HashSet<>();
for (GT_Recipe.GT_Recipe_Map tMap : GT_Recipe.GT_Recipe_Map.sMappings) {
if (tMap.mNEIAllowed) {
identifiers.add(tMap.mNEIName);
}
if (isNH) {
return RecipeCategory.ALL_RECIPE_CATEGORIES.values().stream()
.filter(category -> category.recipeMap.getFrontend().getNEIProperties().registerNEI)
.map(category -> category.unlocalizedName).collect(Collectors.toSet());
}
try {
Set<String> 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
@@ -27,9 +27,16 @@ public class RecipeProcessor {
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 class RecipeProcessor {
}
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());
}