Skip to main content

ClassTweaker & Interface Injection

Graft bundles Fabric's official net.fabricmc:class-tweaker library and integrates it directly into Cloche's AccessWiden and MergeAccessWideners tasks — with zero manual workarounds.

What works out of the box​

1. .classtweaker, .ct, and .accesswidener extensions​

Declare your file in any common, shared, or target block using whichever extension your project prefers:

graft {
common {
accessWideners.from(file("src/main/resources/mymod.classtweaker"))
}
}

Because Cloche's minecraft-codev-access-widener only recognizes .ct and .accesswidener, Graft automatically stages a normalized .ct copy in build/graft/classtweaker/ for Cloche's internal tasks while keeping your source file untouched and referencing it cleanly in fabric.mod.json.

2. Both official and named headers​

On unobfuscated Minecraft 26.1+, you can write standard modern Fabric ClassTweaker files with official:

src/main/resources/mymod.classtweaker
classTweaker v1 official

accessible field net/minecraft/client/Minecraft pause Z
extendable class net/minecraft/client/model/geom/ModelPart

inject-interface net/minecraft/client/player/AbstractClientPlayer com/example/mymod/api/AnimatedPlayer
transitive-inject-interface net/minecraft/client/renderer/entity/state/AvatarRenderState com/example/mymod/api/AnimatedRenderState

Graft normalizes the staged copy to named for Cloche's AccessWiden task and preserves official (along with all inject-interface, transitive-inject-interface, and enum-extension directives) when rewriting the final merged ClassTweaker via MergeAccessWideners.

3. Compile-time interface injection & transitive dependencies​

After Cloche's AccessWiden task finishes producing the widened Minecraft JAR for a target, Graft runs Fabric's ClassTweaker.createClassVisitor(Opcodes.ASM9, writer, null) over every affected target class:

  • Applies your project's inject-interface, transitive-inject-interface, enum-extension, and access-widening rules (including fixing Cloche's extendable class → protected visibility bug).
  • Scans dependency JARs on the target's classpath for:
    • Transitive directives inside their declared fabric.mod.json → accessWidener files.
    • Legacy Fabric Loom fabric.mod.json → custom."loom:injected_interfaces" (and "fabric-loom:injected_interfaces") maps!
  • Writes to a sibling temporary file and atomically replaces the task output (Files.move(..., REPLACE_EXISTING)), so Cloche's shared hard-linked cache is never mutated in place.

This means you can call injected interface methods directly on Minecraft classes without casts — and downstream mods depending on a library that injects interfaces (such as PlayerAnimationLibrary) get full compile-time visibility of those interfaces on both Fabric and NeoForge!

Runtime interface injection on NeoForge

Interface injection in ClassTweaker is a compile-time convenience (so you don't need casts in Java source). At runtime, Mixin actually implements the interface on the target class when your @Mixin(Target.class) public class TargetMixin implements MyInterface is applied. This works identically on both Fabric and NeoForge.

Opting out​

Native ClassTweaker integration is enabled by default. If you ever want Cloche's unmodified AccessWiden and MergeAccessWideners behavior, disable it on graft:

graft {
interfaceInjection = false
}