Register a Custom Class Transformer
Setting Up Your Transformer
SpASM Mod allows you to create custom class transformers that automatically scan and modify game bytecode during loading. This is useful when you need to inject behavior into multiple classes without knowing their exact names in advance.
Implementation Steps
1. Create a class implementing ClassTransformer from the net.mine_diver.spasm.api.transform package. This interface requires you to implement the transformation logic that will be applied to scanned classes.
2. Define your transformation logic in the required method. Your transformer will receive class bytecode and should return the modified bytecode. You can inspect class structure, add methods, modify existing code, or inject calls.
3. Register via the spasm:transformer entrypoint in your mod's metadata file. Add an entry pointing to your transformer class implementation.
4. Test your transformer by launching the game. SpASM will automatically invoke your transformer on all loaded classes during the loading phase. Check logs for any bytecode manipulation errors.
Your transformer will run before the game fully initializes, allowing deep modifications to core game behavior across many classes simultaneously.