tutorial:accesswideners
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:accesswideners [2021/02/27 11:57] – [Requirements] fix typo, part 2 kb1000 | tutorial:accesswideners [2023/01/21 07:46] – [Access Changes] You must use both mutable and accessible to make a private field both mutable and accessible bluemeanial | ||
---|---|---|---|
Line 3: | Line 3: | ||
Access wideners provide a way to loosen the access limits of classes, methods or fields. Access wideners are similar to the commonly known Access Transformers. | Access wideners provide a way to loosen the access limits of classes, methods or fields. Access wideners are similar to the commonly known Access Transformers. | ||
- | Access wideners | + | Access wideners |
- | There are currently | + | |
* Needing to access a (package) private class, especially for the purpose of shadowing or accessing a field or method in a mixin. | * 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. | * Being able to override final methods or subclass final classes. | ||
- | * Before you consider overriding final methods, try mixin injecting in final methods first! | ||
* If you want to subclass a class with only (package) private constructors, | * If you want to subclass a class with only (package) private constructors, | ||
Line 19: | Line 17: | ||
A specific file format is used to define the access changes included in your mod. To aid IDE's you should use the '' | 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, '' | + | The file must start with the following header. '' |
<code [enable_line_numbers=" | <code [enable_line_numbers=" | ||
Line 25: | Line 23: | ||
</ | </ | ||
- | **Once again, the namespace should | + | **Once again, the namespace should |
Access widener files can have blank lines and comments starting with # | Access widener files can have blank lines and comments starting with # | ||
Line 59: | Line 57: | ||
- access can be // | - access can be // | ||
- | - classname | + | - className |
- methodName is the method name | - methodName is the method name | ||
- | - methodDesc is the method | + | - methodDesc is the method |
== Fields == | == Fields == | ||
Line 102: | Line 100: | ||
* Fields have final removed | * 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 ===== | ===== 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. | + | 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=" | <code groovy [enable_line_numbers=" | ||
- | minecraft | + | loom { |
- | accessWidener | + | accessWidenerPath |
} | } | ||
</ | </ | ||
+ | |||
+ | Loom 0.8 or lower: | ||
+ | |||
+ | <code groovy [enable_line_numbers=" | ||
+ | loom { | ||
+ | accessWidener = file(" | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | fabric.mod.json: | ||
<code json [enable_line_numbers=" | <code json [enable_line_numbers=" | ||
Line 120: | Line 132: | ||
... | ... | ||
</ | </ | ||
+ | |||
+ | ===== Validating the file ===== | ||
+ | By default, accesswidener entries that don't exist are ignored. | ||
+ | On recent versions of Loom, you can run '' |
tutorial/accesswideners.txt · Last modified: 2024/06/09 05:33 by haykam