User Tools

Site Tools


tutorial:accesswideners

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorial:accesswideners [2020/06/28 19:47] liachtutorial:accesswideners [2023/08/13 10:39] (current) – info about V2 format tooster
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 should **only** be used where mixin does not currently provide a means to do so. +Access wideners may be used instead of accessor mixins, and there are currently 2 cases where the functionality provided by mixin is not sufficient:
-There are currently only 2 cases where mixins are not sufficient:+
   * 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, wideners are a good choice.     * If you want to subclass a class with only (package) private constructors, wideners are a good choice.
 +
 +In order for access widener changes to show up in the decompiled source, run the ''genSources'' gradle task.
  
 ===== Requirements ===== ===== Requirements =====
   * Fabric-loader 0.8.0 or higher   * Fabric-loader 0.8.0 or higher
   * Loom 0.2.7 or higher   * Loom 0.2.7 or higher
- 
 ===== File format ===== ===== 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 ''.accesswidener'' file extension. A specific file format is used to define the access changes included in your mod. To aid IDE's you should use the ''.accesswidener'' file extension.
  
-The file must start with the following header''namespace'' should match the mappings namespace of your mod's source code, this is usually ''named''. Loom will remap the access widener file for you into ''intermediary'' along with your mod. If you use a custom ''RemapJarTask'', set ''remapAccessWidener'' property on it to ''true'' to ensure this happens.+The file must start with the following header''namespace'' should usually always be set to the word ''named'', and not your project namespace. Loom will remap the access widener file for you into ''intermediary'' along with your mod.
  
 <code [enable_line_numbers="true"]> <code [enable_line_numbers="true"]>
-accessWidener v1 <namespace>+accessWidener v2 <namespace>
 </code> </code>
 +
 +**Once again, the namespace should be ''named'' in most if not all cases**
  
 Access widener files can have blank lines and comments starting with # Access widener files can have blank lines and comments starting with #
  
 <code [enable_line_numbers="true"]> <code [enable_line_numbers="true"]>
-# Comments like this are supported, as well at the end of the line+# Comments like this are supported, as well as at the end of the line
 </code> </code>
  
Line 56: Line 57:
  
   - access can be //accessible// or //extendable//   - access can be //accessible// or //extendable//
-  - classname is the owner class+  - className is the owner class
   - methodName is the method name   - methodName is the method name
-  - methodDesc is the method descriptior+  - methodDesc is the method descriptor
  
 == Fields == == Fields ==
Line 99: 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 "modid" in the example with your own mod ID.) 
 + 
 +Loom 0.9 or higher:
  
 <code groovy [enable_line_numbers="true"]> <code groovy [enable_line_numbers="true"]>
-minecraft +loom 
- accessWidener "src/main/resources/modid.accesswidener"+ accessWidenerPath = file("src/main/resources/modid.accesswidener")
 } }
 </code> </code>
 +
 +Loom 0.8 or lower:
 +
 +<code groovy [enable_line_numbers="true"]>
 +loom {
 + accessWidener = file("src/main/resources/modid.accesswidener")
 +}
 +</code>
 +
 +fabric.mod.json:
  
 <code json [enable_line_numbers="true"]> <code json [enable_line_numbers="true"]>
 ... ...
  
-"accessWidener" : "modid.accesswidener","+"accessWidener" : "modid.accesswidener",
  
 ... ...
 </code> </code>
 +
 +===== Validating the file =====
 +By default, accesswidener entries that don't exist are ignored.
 +On recent versions of Loom, you can run ''gradlew validateAccessWidener'' to check that all the classes, fields and methods specified in the accesswidener file exist.
 +
 +The error messages can be a little cryptic. For example, if you make a mistake in specifying a field, the error doesn't say whether the name or the type is the problem For example, if it says it cannot find the field "''fooI''", it could mean there is no field named ''foo'', or that it exists but isn't an ''int'' (''I'').
 +
 +===== V2 changes =====
 +
 +With the v2 version, the ''transitive-*'' prefixed keywords have been added:
 +
 +  * ''transitive-accessible''
 +  * ''transitive-extendable''
 +  * ''transitive-mutable''
 +
 +They differ from their regular, non-prefixed variants in that they also apply to mods that depend on this one.
 +
 +
 +
tutorial/accesswideners.1593373648.txt.gz · Last modified: 2020/06/28 19:47 by liach