tutorial:accesswidening
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| tutorial:accesswidening [2025/11/21 13:26] – removed - external edit (Unknown date) 127.0.0.1 | tutorial:accesswidening [2025/11/21 13:26] (current) – ↷ Page name changed from tutorial:accesswideners to tutorial:accesswidening gauntrecluse | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Access Widening ====== | ||
| + | |||
| + | Access widening provides a way to loosen the access limits of classes, methods or fields. Access wideners are similar to the commonly known Access Transformers. | ||
| + | |||
| + | Access wideners may be used instead of accessor mixins, and there are currently 2 cases where the functionality provided by mixin is not sufficient: | ||
| + | * Needing to access a (package) private class, especially for the purpose of shadowing or accessing a field or method in a mixin. | ||
| + | * Being able to override final methods or subclass final classes. | ||
| + | * If you want to subclass a class with only (package) private constructors, | ||
| + | |||
| + | In order for access widener changes to show up in the decompiled source, run the '' | ||
| + | |||
| + | Note: Unlike accessor mixins, access wideners do not work for source of mods. | ||
| + | |||
| + | ===== Requirements ===== | ||
| + | * Fabric-loader 0.8.0 or higher | ||
| + | * Loom 0.2.7 or higher | ||
| + | ===== File format ===== | ||
| + | |||
| + | A specific file format is used to define the access changes included in your mod. To aid IDE's you should use the '' | ||
| + | |||
| + | The file must start with the following header. '' | ||
| + | |||
| + | <code [enable_line_numbers=" | ||
| + | accessWidener v2 < | ||
| + | </ | ||
| + | |||
| + | **Once again, the namespace should be '' | ||
| + | |||
| + | Access widener files can have blank lines and comments starting with # | ||
| + | |||
| + | <code [enable_line_numbers=" | ||
| + | # Comments like this are supported, as well as at the end of the line | ||
| + | </ | ||
| + | |||
| + | Any whitespace can be used to separate in the access widener file, tab is recommended. | ||
| + | |||
| + | Class names are separated with a / and not . | ||
| + | |||
| + | For inner classes, you should use '' | ||
| + | |||
| + | == Classes == | ||
| + | |||
| + | Class access can be changed by specifying the access and the class name as named the mappings namespace defined in the header. | ||
| + | |||
| + | |||
| + | <code [enable_line_numbers=" | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | - access can be // | ||
| + | |||
| + | == Methods == | ||
| + | |||
| + | Method access can be changed by specifying the access, class name, method name and method descriptor as named the mappings namespace defined in the header. | ||
| + | |||
| + | <code [enable_line_numbers=" | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | - access can be // | ||
| + | - className is the owner class | ||
| + | - methodName is the method name | ||
| + | - methodDesc is the method descriptor | ||
| + | |||
| + | == Fields == | ||
| + | |||
| + | Field access can be changed by specifying the access, class name, field name and field descriptor as named the mappings namespace defined in the header. | ||
| + | |||
| + | <code [enable_line_numbers=" | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | - access can be // | ||
| + | - className is the owner class | ||
| + | - fieldName is the field name | ||
| + | - fieldDesc is the field descriptor | ||
| + | |||
| + | ===== Access Changes ===== | ||
| + | |||
| + | === Extendable === | ||
| + | |||
| + | Extendable should be used where you want to extend a class or override a method. | ||
| + | |||
| + | * Classes are made public and final is removed | ||
| + | * Methods are made protected and final is removed | ||
| + | |||
| + | Making a method extendable also makes the class extendable. | ||
| + | |||
| + | === Accessible === | ||
| + | |||
| + | Accessible should be used when you want to access a class, field or method from another class. | ||
| + | |||
| + | * Classes are made public | ||
| + | * Methods are made public and final if private | ||
| + | * Fields are made public | ||
| + | |||
| + | Making a method or field accessible also makes the class accessible. | ||
| + | |||
| + | === Mutable === | ||
| + | |||
| + | Mutable should be used when you want to mutate a final field | ||
| + | |||
| + | * Fields have final removed | ||
| + | |||
| + | If you want to make a private final field both accessible //and// mutable, you need to use two directives, one for each change. | ||
| + | |||
| + | ===== Specifying file location ===== | ||
| + | |||
| + | The access widener file location must be specified in your build.gradle and in your fabric.mod.json file. It should be stored in the resources as it needs to be included in the exported jar file. (Replace " | ||
| + | |||
| + | Loom 0.9 or higher: | ||
| + | |||
| + | <code groovy [enable_line_numbers=" | ||
| + | loom { | ||
| + | accessWidenerPath = file(" | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Loom 0.8 or lower: | ||
| + | |||
| + | <code groovy [enable_line_numbers=" | ||
| + | loom { | ||
| + | accessWidener = file(" | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | fabric.mod.json: | ||
| + | |||
| + | <code json [enable_line_numbers=" | ||
| + | ... | ||
| + | |||
| + | " | ||
| + | |||
| + | ... | ||
| + | </ | ||
| + | |||
| + | ===== Validating the file ===== | ||
| + | By default, accesswidener entries that don't exist are ignored. | ||
| + | On recent versions of Loom, you can run '' | ||
| + | |||
| + | The error messages can be a little cryptic. For example, if you make a mistake in specifying a field, the error doesn' | ||
| + | |||
| + | ===== V2 changes ===== | ||
| + | |||
| + | With the v2 version, the '' | ||
| + | |||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | They differ from their regular, non-prefixed variants in that they also apply to mods that depend on this one. | ||
| + | |||
| + | |||