Skip to content

Commit

Permalink
Migrate to new RecipeMap (#37)
Browse files Browse the repository at this point in the history
* Migrate to new RecipeMap

* Fix wildcard import

* update deps

---------

Co-authored-by: Martin Robertz <[email protected]>
  • Loading branch information
miozune and Dream-Master authored Dec 3, 2023
1 parent 702f612 commit f50fbb2
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 55 deletions.
27 changes: 0 additions & 27 deletions .github/scripts/test-no-error-reports.sh

This file was deleted.

9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.gradle
.settings
/.idea/
/.vscode/
/run/
/build/
/eclipse/
Expand All @@ -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
17 changes: 12 additions & 5 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;

/**
Expand All @@ -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.
*/
Expand All @@ -62,15 +68,28 @@ public static boolean isStackValid(Object aStack) {
@Nonnull
@Override
public Set<String> 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<String> 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<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
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/com/github/vfyjxf/nee/processor/RecipeProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit f50fbb2

Please sign in to comment.