Skip to content

Commit

Permalink
Fix NC GTCECompat config (#469)
Browse files Browse the repository at this point in the history
Co-authored-by: DStrand1 <[email protected]>
  • Loading branch information
Yefancy and serenibyss authored Jan 7, 2022
1 parent 76715c3 commit bec9335
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/java/gregtech/api/recipes/RecipeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ protected ModularUI.Builder addSpecialTexture(ModularUI.Builder builder) {
}


public List<Recipe> getRecipeList() {
public Collection<Recipe> getRecipeList() {
return Collections.unmodifiableList(new ArrayList<>(recipeSet));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@

import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

public class PowerlessJetpack implements ISpecialArmorLogic, IArmorLogic, IJetpack {

private static final List<Recipe> FUELS = RecipeMaps.COMBUSTION_GENERATOR_FUELS.getRecipeList();
private static final Collection<Recipe> FUELS = RecipeMaps.COMBUSTION_GENERATOR_FUELS.getRecipeList();

public static final List<Fluid> FUELS_FORBIDDEN = Arrays.asList(Materials.Oil.getFluid(), Materials.SulfuricLightFuel.getFluid());

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/gregtech/core/GregTechTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import gregtech.core.util.TargetClassVisitor;
import gregtech.core.visitors.*;
import net.minecraft.launchwrapper.IClassTransformer;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
Expand Down Expand Up @@ -108,6 +110,18 @@ public byte[] transform(String name, String transformedName, byte[] basicClass)
classReader.accept(new TargetClassVisitor(classWriter, CCLVisitor.TARGET_METHOD, CCLVisitor::new), 0);
return classWriter.toByteArray();
}
case NuclearCraftRecipeHelperVisitor.TARGET_CLASS_NAME: {
ClassReader classReader = new ClassReader(basicClass);
ClassWriter classWriter = new ClassWriter(0);

ModContainer container = Loader.instance().getIndexedModList().get("nuclearcraft");
if (container.getVersion().contains("2o")) { // overhauled
classReader.accept(new TargetClassVisitor(classWriter, NuclearCraftRecipeHelperVisitor.TARGET_METHOD_NCO, NuclearCraftRecipeHelperVisitor::new), 0);
} else {
classReader.accept(new TargetClassVisitor(classWriter, NuclearCraftRecipeHelperVisitor.TARGET_METHOD_NC, NuclearCraftRecipeHelperVisitor::new), 0);
}
return classWriter.toByteArray();
}
}
return basicClass;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package gregtech.core.visitors;

import gregtech.core.util.ObfMapping;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

public class NuclearCraftRecipeHelperVisitor extends MethodVisitor implements Opcodes {
public static final String TARGET_CLASS_NAME = "nc/integration/gtce/GTCERecipeHelper";

public static final ObfMapping TARGET_METHOD_NC = new ObfMapping(TARGET_CLASS_NAME, "addGTCERecipe", "(Ljava/lang/String;Lnc/recipe/ProcessorRecipe;)V");
public static final ObfMapping TARGET_METHOD_NCO = new ObfMapping(TARGET_CLASS_NAME, "addGTCERecipe", "(Ljava/lang/String;Lnc/recipe/BasicRecipe;)V");

public NuclearCraftRecipeHelperVisitor(MethodVisitor mv) {
super(ASM5, mv);
}

@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
if (opcode == GETSTATIC && name.equals("FLUID_EXTRACTION_RECIPES")) { // FLUID_EXTRACTION_RECIPES -> EXTRACTOR_RECIPES
name = "EXTRACTOR_RECIPES";
}
super.visitFieldInsn(opcode, owner, name, desc);
}
}
7 changes: 2 additions & 5 deletions src/main/java/gregtech/integration/jei/GTJeiPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@

import javax.annotation.Nonnull;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -110,7 +107,7 @@ public void register(IModRegistry registry) {
.filter(recipe -> !recipe.isHidden() && recipe.hasValidInputsForDisplay());

if (recipeMap.getSmallRecipeMap() != null) {
List<Recipe> smallRecipes = recipeMap.getSmallRecipeMap().getRecipeList();
Collection<Recipe> smallRecipes = recipeMap.getSmallRecipeMap().getRecipeList();
recipeStream = recipeStream.filter(recipe -> !smallRecipes.contains(recipe));
}

Expand Down

0 comments on commit bec9335

Please sign in to comment.