From 072c15960f9484a59f8df3eb293ffe5c52cbc1e9 Mon Sep 17 00:00:00 2001 From: arcade_kappa Date: Fri, 13 Sep 2024 20:08:29 +0800 Subject: [PATCH] Update readme & add crossbow patch --- README.md | 4 ++ .../fugue/common/FugueLoadingPlugin.java | 3 ++ .../fugue/config/ModPatchConfig.java | 2 + .../TransformerEntityArrowTransformer.java | 40 +++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 src/main/java/com/cleanroommc/fugue/transformer/TransformerEntityArrowTransformer.java diff --git a/README.md b/README.md index 9e18e62..6da6aa8 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,10 @@ If you are still using 0.1.0 Cleanroom, use 0.5.4. But that's not recommended. * In Control! * More Refined Storage * Better Formatting Code +* 5zig +* Ears +* Colytra +* Crossbow ## Note Add + to start of the file if it's not there. \ No newline at end of file diff --git a/src/main/java/com/cleanroommc/fugue/common/FugueLoadingPlugin.java b/src/main/java/com/cleanroommc/fugue/common/FugueLoadingPlugin.java index 515ee93..ec1a61e 100644 --- a/src/main/java/com/cleanroommc/fugue/common/FugueLoadingPlugin.java +++ b/src/main/java/com/cleanroommc/fugue/common/FugueLoadingPlugin.java @@ -172,6 +172,9 @@ public class FugueLoadingPlugin implements IFMLLoadingPlugin { if (FugueConfig.modPatchConfig.enableColytra) { TransformerDelegate.registerExplicitTransformerByInstance(new EntityLivingBaseTransformer(), "net.minecraft.entity.EntityLivingBase"); } + if (FugueConfig.modPatchConfig.enableCrossbow) { + TransformerDelegate.registerExplicitTransformerByInstance(new TransformerEntityArrowTransformer(), "git.jbredwards.crossbow.mod.asm.transformer.TransformerEntityArrow"); + } if (FugueConfig.getCodeSourcePatchTargets.length > 0) { TransformerDelegate.registerExplicitTransformerByInstance(new ITweakerTransformer(), FugueConfig.getCodeSourcePatchTargets); } diff --git a/src/main/java/com/cleanroommc/fugue/config/ModPatchConfig.java b/src/main/java/com/cleanroommc/fugue/config/ModPatchConfig.java index c89ce0e..02b0b4a 100644 --- a/src/main/java/com/cleanroommc/fugue/config/ModPatchConfig.java +++ b/src/main/java/com/cleanroommc/fugue/config/ModPatchConfig.java @@ -110,4 +110,6 @@ public class ModPatchConfig { public boolean enableColytra = true; @Config.Name("Enable InfinityLib Patch") public boolean enableInfLib = true; + @Config.Name("Enable Crossbow(jbredwards) Patch") + public boolean enableCrossbow = true; } diff --git a/src/main/java/com/cleanroommc/fugue/transformer/TransformerEntityArrowTransformer.java b/src/main/java/com/cleanroommc/fugue/transformer/TransformerEntityArrowTransformer.java new file mode 100644 index 0000000..0acc81e --- /dev/null +++ b/src/main/java/com/cleanroommc/fugue/transformer/TransformerEntityArrowTransformer.java @@ -0,0 +1,40 @@ +package com.cleanroommc.fugue.transformer; + +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.tree.*; +import top.outlands.foundation.IExplicitTransformer; + +public class TransformerEntityArrowTransformer implements IExplicitTransformer { + @Override + public byte[] transform(byte[] bytes) { + ClassNode classNode = new ClassNode(); + ClassReader classReader = new ClassReader(bytes); + classReader.accept(classNode, 0); + if (classNode.methods != null) + { + for (MethodNode methodNode : classNode.methods) + { + if (methodNode.name.equals("transform")) { + InsnList instructions = methodNode.instructions; + if (instructions != null) + { + for (AbstractInsnNode insnNode : instructions) + { + if (insnNode.getOpcode() == Opcodes.ICONST_0 && insnNode.getPrevious() instanceof LdcInsnNode ldcInsnNode && ldcInsnNode.cst.equals("(Lnet/minecraftforge/common/capabilities/ICapabilityProvider;)Lgit/jbredwards/crossbow/mod/common/capability/ICrossbowArrowData;")) + { + instructions.insert(insnNode, new InsnNode(Opcodes.ICONST_1)); + instructions.remove(insnNode); + } + } + } + } + } + } + ClassWriter classWriter = new ClassWriter(0); + + classNode.accept(classWriter); + return classWriter.toByteArray(); + } +}