-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66899f5
commit dfda237
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/gregtech/asm/transformers/MicroBlock_FixLoggerCrash.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |