Skip to content

Class Transformers

Trin Wasinger edited this page Sep 9, 2026 · 7 revisions

Overview

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.

Annotations

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:

  • Transformer marks a class as a Class Transformer and specifies the target class.
  • Inject allows hooking into methods, constructors (using name <init>), and static blocks (using name <clinit>) to invoke callbacks with captured variables and parameters.
    • Target specifies where in a method to apply changes (valid values are HEAD, RETURN, THROW, TAIL, INVOKE, FIELD, GETFIELD, PUTFIELD, NEW, OPCODE, and CONSTANT; however, modification of constructors and static blocks may lead to errors when not targeting RETURN).
  • Requires is a Specter addition to enable the creation of optional Class Transformers.
  • Static marks a transformer method as static without needing the static keyword (Use when targeting a Java static interface method since Groovy does not allow static interface methods).
  • And more...

Examples

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')
    }
}

Notes

  • Most annotations in io.github.sianabeeblebrox.specter.annotations.* are aliases for those in net.lenni0451.classtransform.annotations.*; however, there are a few differences:
    • Some names were changed to match SpongePowered/Mixin or LlamaLad7/MixinExtras (COverride → Overwrite, CLocalVariable → Local).
    • Requires and Static are unique to Specter.
    • Only Specter's Transformer is discoverable and automatically applied during mod loading.
  • For more details, see the Javadoc or check out the upstream wiki.

Clone this wiki locally