Skip to content

Commit

Permalink
Aaaaand that mod has two parts
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoriusT committed Sep 12, 2022
1 parent 66899f5 commit dfda237
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/gregtech/asm/GT_ASM.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public ASMConfig(File mclocation) {
if (mclocation == null) throw new RuntimeException("Failed to acquire `location` in GT6 CoreMod");

transformers.put(MultiPart_FixLoggerCrash.class.getName(), true);
transformers.put(MicroBlock_FixLoggerCrash.class.getName(), true);
transformers.put(CoFHCore_CrashFix.class.getName(), true);
transformers.put(CoFHLib_HashFix.class.getName(), true);
transformers.put(ExtraUtils_FixThaumcraftAspects.class.getName(), true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Copyright (c) 2022 GregTech-6 Team
*
* This file is part of GregTech.
*
* GregTech is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GregTech is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GregTech. If not, see <http://www.gnu.org/licenses/>.
*/

package gregtech.asm.transformers;

import gregapi.log.LoggerFML;
import gregtech.asm.GT_ASM;
import net.minecraft.launchwrapper.IClassTransformer;
import org.apache.logging.log4j.Logger;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.MethodNode;

/**
* @author Gregorius Techneticies
*/
public class MicroBlock_FixLoggerCrash implements IClassTransformer {
public static Logger FAKE_LOGGER = new LoggerFML("FMB");

@Override
public byte[] transform(String name, String transformedName, byte[] basicClass) {
if (!transformedName.equals("codechicken.microblock.handler.MicroblockProxy")) return basicClass;
ClassNode classNode = GT_ASM.makeNodes(basicClass);

for (MethodNode m: classNode.methods) {
if (m.name.equals("logger")) {
GT_ASM.logger.info("Transforming codechicken.microblock.handler.MicroblockProxy.logger");
m.instructions.clear();
m.instructions.add(new FieldInsnNode(Opcodes.GETSTATIC, "gregtech/asm/transformers/MicroBlock_FixLoggerCrash", "FAKE_LOGGER", "Lorg/apache/logging/log4j/Logger;"));
m.instructions.add(new InsnNode(Opcodes.ARETURN));
}
}

return GT_ASM.writeByteArray(classNode);
}
}

0 comments on commit dfda237

Please sign in to comment.