Repository navigation
Class Transformers
Trin Wasinger edited this page Sep 9, 2026
·
7 revisions
Class Transformers use Lenni0451/ClassTransform to provide an abstraction around ASM inspired by SpongePowered/Mixin that allows manipulating and injecting into compiled bytecode at runtime.
Class Transformers are defined by annotating normal source files using io.github.sianabeeblebrox.specter.annotations.* and are applied automatically during mod loading. Most features of SpongePowered/Mixin and LlamaLad7/MixinExtras are supported. Of note:
-
Transformermarks a class as a Class Transformer and specifies the target class. -
Injectallows hooking into methods, constructors (using name<init>), and static blocks (using name<clinit>) to invoke callbacks with captured variables and parameters.-
Targetspecifies where in a method to apply changes (valid values areHEAD,RETURN,THROW,TAIL,INVOKE,FIELD,GETFIELD,PUTFIELD,NEW,OPCODE, andCONSTANT; however, modification of constructors and static blocks may lead to errors when not targetingRETURN).
-
-
Requiresis a Specter addition to enable the creation of optional Class Transformers. -
Staticmarks a transformer method as static without needing thestatickeyword (Use when targeting a Java static interface method since Groovy does not allow static interface methods). - And more...
import io.github.sianabeeblebrox.specter.Specter
import io.github.sianabeeblebrox.specter.annotations.*
@Transformer(name='net/minecraft/world/item/Items')
class AddItems {
@Inject(method = '<clinit>', target = @Target('RETURN'))
static void clinit() {
Specter.EVENT_BUS.dispatch('register_items')
}
}- Most annotations in
io.github.sianabeeblebrox.specter.annotations.*are aliases for those innet.lenni0451.classtransform.annotations.*; however, there are a few differences:- Some names were changed to match SpongePowered/Mixin or LlamaLad7/MixinExtras (
COverride→Overwrite,CLocalVariable→Local). -
RequiresandStaticare unique to Specter. - Only Specter's
Transformeris discoverable and automatically applied during mod loading.
- Some names were changed to match SpongePowered/Mixin or LlamaLad7/MixinExtras (
- For more details, see the Javadoc or check out the upstream wiki.