2,176 bytes added
, 21:01, 24 October 2020
Access Transformers are Forge's native way of allowing you to access (read <code>and </code>write) functions that have a lower-than-ideal visibility, and/or removing finality.
== Visibility ==
Here's a quick rundown of the visibility options offered by Java 8:
* <code>public</code> visible to all classes inside and outside its package
* <code>protected</code> visible only to classes inside the package and subclasses
* <code>default</code> visible only to classes inside the package
* <code>private</code> visible only to inside the class
Additionally, there are final variants of each of these, each represented by the phrase "-f" on the end of the access specifier.
== How It Works ==
As Forge is loading, it scans the jar file for the META-INF/accesstransformers.cfg file. if it's found, it is parsed according to the specification:
<code ->
NewAccessSpecifier MemberSignature # comment
</code>
A random example to understand the syntax:
<code ->
public net.minecraft.util.palette.IResizeCallback # makes IResizeCallback public
</code>
If a valid entry is found on a line, Forge will look into the bytecode of the file where that member is defined, and change its access to whatever you desire it to be.
This startup modification means accessing is O(1) for all accesses after this initial change, which makes it a great option for performance if you're looking at something a <code>lot.</code>
== Using Access Transformers in your mod ==
<block important>
You should avoid using ATs if a private variable / function you're looking at has a getter or a setter. Variables are usually private for a reason.
</block>
Step 1: Uncomment the access transformer line in your build.gradle
[[File:Access-transformers-uncomment-this-line-in-build-gradle.png|600px|frameless]]
Step 2: Create a new file called "accesstransformer.cfg" in the <code><nowiki>src/main/resources/META-INF/</nowiki></code> folder.
Step 3: Refresh the Gradle project. This can be done natively in IDEA and Eclipse.
== When not to use Access Transformers ==
* Unnecessary access transformations (e.g. using ATs to make something <code>public</code> when it's already <code>public</code>)