Skip to content

Commit

Permalink
Add patch to NBTPeripheral
Browse files Browse the repository at this point in the history
  • Loading branch information
kappa-maintainer committed Feb 28, 2025
1 parent c18c201 commit bceb3a1
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ If you are still using 0.1.0 Cleanroom, use 0.5.4. But that's not recommended.
* Offline Skins
* Worse Hurt Time
* Inventory Tweaks
* More Sound Config
* NBTPeripheral

## Note
Add + to start of the file if it's not there.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.cleanroommc.fugue.transformer.loliasm.LoliReflectorTransformer;
import com.cleanroommc.fugue.transformer.loliasm.ModIdentifierTransformer;
import com.cleanroommc.fugue.transformer.moresoundconfig.SoundDevicesTransformer;
import com.cleanroommc.fugue.transformer.nbtperipheral.LinkedTreeMapTransformer;
import com.cleanroommc.fugue.transformer.nothirium.BufferBuilderTransformer;
import com.cleanroommc.fugue.transformer.nothirium.FreeSectorManagerTransformer;
import com.cleanroommc.fugue.transformer.nothirium.MixinBufferBuilderTransformer;
Expand Down Expand Up @@ -514,6 +515,14 @@ public static void registerTransformers() {
"ichttt.mods.moresoundconfig.SoundDevices"
);
}
if (FugueConfig.modPatchConfig.enableNBTPeripheral) {
TransformerDelegate.registerExplicitTransformer(
new LinkedTreeMapTransformer(),
"nl.makertim.nbtperipheral.cc.BlockStateUtil",
"nl.makertim.nbtperipheral.cc.CCUtil",
"nl.makertim.nbtperipheral.cc.NBTUtil"
);
}

//Common patches below

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,6 @@ public class ModPatchConfig {
public boolean enableInvTweaks = true;
@Config.Name("Enable Sound Device Options / More Sound Config Patch")
public boolean enableMoreSoundConfig = true;
@Config.Name("Enable NBT Peripheral Patch")
public boolean enableNBTPeripheral = true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.cleanroommc.fugue.transformer.nbtperipheral;

import com.cleanroommc.fugue.common.Fugue;
import javassist.*;
import javassist.expr.ConstructorCall;
import javassist.expr.ExprEditor;
import javassist.expr.MethodCall;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.*;
import top.outlands.foundation.IExplicitTransformer;

import java.io.ByteArrayInputStream;

public class LinkedTreeMapTransformer 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)
{
InsnList instructions = methodNode.instructions;
if (instructions != null)
{
for (AbstractInsnNode insnNode : instructions)
{
if (insnNode instanceof MethodInsnNode methodInsnNode
&& methodInsnNode.owner.equals("com/google/gson/internal/LinkedTreeMap")
&& methodInsnNode.name.equals("<init>")
)
{
methodInsnNode.desc = "(Ljava/util/Comparator;Z)V";
instructions.insertBefore(methodInsnNode, new InsnNode(Opcodes.ICONST_0));
}
}
}

}
}
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES);

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

0 comments on commit bceb3a1

Please sign in to comment.