How To: Access Transformers

Ever been writing some code and wanted to get access to a private field or override a final method? Access Transformers do just that. Sponge already has the basic infrastructure for it, so all you need to do is register what you need!

An access transformer file is available in <project>/src/main/resources, and its name ends with _at.cfg. Each line is in a specific format.

For the purposes of documentation, <...> represents something you need to replace. [...] represents something optional.

Comments and Blank Lines

Comments start with # and go to the end of the line. Blank lines do nothing.

Unobfuscated Fields

public[-f] <fully qualified class name, replace . with / > <field name>
Use -f to indicate that the field should be made nonfinal. For “fully qualified type name”, take the full name of the class name (e.g. net.minecraft.server.MinecraftServer) and replace the dots with slashes (resulting in net/minecraft/server/MinecraftServer).

Unobfuscated Methods

public[-f] <fully qualified class name, replace . with / > <method name><method signature>
The method signature is something special. It starts with (, then includes the argument types in bytecode format (without any separation), then a ) and the return type in bytecode format.

A list of bytecode types:

  • boolean -> Z
  • char -> C
  • byte -> B
  • short -> S
  • int -> I
  • long -> J
  • float -> F
  • double -> D
  • com.example.MyClass -> Lcom/example/MyClass; (L<fully qualified class name, replace . with / >;)
  • int[] -> [I (Place [ before the element type in bytecode format.)
  • com.example.MyClass[][][] -> [[[Lcom/example/MyClass (Repeat [ for each dimension.)

Obfuscated Fields and Methods

Fields - <access modifier>[-f] <fully qualified class name, replace . with / > <srg field name> # <MCP field name>
Methods - public[-f] <fully qualified class name, replace . with / > <method name>(<bytecode types representing arguments>)<bytecode type representing return type> # <MCP field name>

The MCP field name is the one that you use during development. The SRG field name is in the format of field_123456_x or func_123456_x. To find it:

  1. Open your development folder in a file manager.
  2. Go to build/srgs and open srg-mcp.cfg in a text editor.
  3. Search for <fully qualified class name, replace . with / >/<field/method name>.
  4. You will end up with a line separated into three parts. The SRG name is the section after the / in the second part (e.g. in FD: net/minecraft/client/Minecraft/field_123456_x net/minecraft/client/someField, the SRG name is field_123456_x.


public[-f] <fully qualified class name, replace . with / > *
This performs the specified operation with everything in the class

Updating Your Workspace

Once you’ve finished changing the access transformer, re-run gradle setupDecompWorkspace and enjoy your newly updated modifiers!


Also, a link to forge’s wiki

Is -f removing final modifier and +f adding final modifier?

Yes, you are correct. However, I recommend you don’t use +f, as it could break mods (and even Minecraft itself) if they rely on it being non-final.