Skip to content

Commit

Permalink
Patch TFC Medicinal
Browse files Browse the repository at this point in the history
  • Loading branch information
kappa-maintainer committed Jan 26, 2024
1 parent aa80688 commit d9a615e
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Also check [The Fugue Plane](https://forgottenrealms.fandom.com/wiki/Fugue_Plane
* OpenSecurity
* Enchantments Control
* GregTech CE Unofficial (Temporary)
* TFC Medicinal

## Note
Add ! to start of the file name to fix Lag Goggles.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mappings_version=39-1.12
mod_id=fugue
mod_name=Fugue
mod_main_class=Fugue
mod_version=0.5.1
mod_version=0.5.2
mod_base_package=com.cleanroommc.fugue
mod_authors=kappa_maintainer
mod_description=A mod that patch dead mods for Cleanroom
5 changes: 3 additions & 2 deletions src/main/java/com/cleanroommc/FugueLoadingPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
@SuppressWarnings("deprecation")
public class FugueLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader {
private static final LinkedHashMap<String, IClassTransformer> transformerCache = new LinkedHashMap<>();
private static final String prefix = "com.cleanroommc.transformer.";

static {
List<String> transformers = asList(
Expand All @@ -40,7 +41,7 @@ public class FugueLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader

for(String str : transformers) {
Fugue.LOGGER.info("Registering " + str);
Launch.classLoader.registerSuperTransformer("com.cleanroommc.transformer." + str);
Launch.classLoader.registerSuperTransformer(prefix + str);
}
}

Expand Down Expand Up @@ -74,7 +75,7 @@ public static void unRegisterUselessTransformer() {

@Override
public String[] getASMTransformerClass() {
return new String[0];
return new String[]{prefix + "CommonRegistrar$Transformer"};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.cleanroommc.transformer;

import net.minecraft.launchwrapper.IClassTransformer;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;

public class CommonRegistrar$Transformer implements IClassTransformer {
private static boolean hit = false;
@Override
public byte[] transform(String s, String s1, byte[] bytes) {
if (bytes == null)
{
return null;
}

if (hit || !s1.equals("com.lumintorious.tfcmedicinal.CommonRegistrar$"))
{
return bytes;
}


ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(bytes);
classReader.accept(classNode, 0);
boolean modified = false;
classNode.version = Opcodes.V21;
if (classNode.fields != null)
{
for (FieldNode fieldNode : classNode.fields)
{
if (fieldNode.name.equals("MODULE$"))
{
fieldNode.access -= Opcodes.ACC_FINAL;
}
}
}
if (classNode.methods != null)
{
for (MethodNode methodNode : classNode.methods)
{
if (methodNode.name.equals("registerBarrelRecipes")) {
InsnList instructions = methodNode.instructions;
if (instructions != null)
{
for (AbstractInsnNode insnNode : instructions)
{
if (insnNode.getOpcode() == Opcodes.INVOKESTATIC && insnNode instanceof MethodInsnNode methodInsnNode)
{
if (methodInsnNode.owner.equals("net/dries007/tfc/objects/inventory/ingredient/IIngredient") && methodInsnNode.name.equals("of"))
{
methodInsnNode.itf = true;
modified = true;
}
}
}
}
}
}
}
if (modified)
{
hit = true;
ClassWriter classWriter = new ClassWriter(0);

classNode.accept(classWriter);
return classWriter.toByteArray();
}
return bytes;
}
}

0 comments on commit d9a615e

Please sign in to comment.