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/04/24 15:26] modmuss50tutorial:accesswideners [2024/04/01 19:23] (current) – [Access Wideners] explain that to have access wideners show up in the IDE the programmer must refresh the gradle project. matjojo
Line 1: Line 1:
 ====== Access Wideners ====== ====== Access Wideners ======
  
-Access wideners provide a way to loosen the access limits of classes, methods or fields. Access wideners 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 currenly provide 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: 
 +  * 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, wideners are good choice. 
 + 
 +In order for access widener changes to show up in the decompiled source, run the ''genSources'' gradle task and then reload the gradle project in your IDE.
  
 ===== 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'you should use the `.accesswidenerfile 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, `namespaceshould match the mappings namespace of your mod's source code, this is usually `named` loom will remap the access widener file for you into `intermediaryalong with your mod.+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>
  
-Any whitespace can be used to sperate in the access widner file, tab is recommended.+Any whitespace can be used to separate in the access widener file, tab is recommended.
  
 Class names are separated with a / and not . Class names are separated with a / and not .
 +
 +For inner classes, you should use ''$'' instead of ''/''
  
 == Classes == == Classes ==
  
 Class access can be changed by specifying the access and the class name as named the mappings namespace defined in the header. 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="true"]> <code [enable_line_numbers="true"]>
Line 41: Line 50:
 == Methods == == Methods ==
  
-Method access can be changed by specifying the access, class name, method name and method descriptior as named the mappings namespace defined in the header.+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="true"]> <code [enable_line_numbers="true"]>
Line 48: 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 ==
  
-Field access can be changed by specifying the access, class name, field name and field descriptior as named the mappings namespace defined in the header.+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="true"]> <code [enable_line_numbers="true"]>
Line 61: Line 70:
  
   - access can be //accessible// or //mutable//   - access can be //accessible// or //mutable//
-  - classname is the owner class +  - className is the owner class 
-  - fieldNameis the field name +  - fieldName is the field name 
-  - fieldDescis the field descriptior+  - fieldDesc is the field descriptor
  
 ===== Access Changes ===== ===== Access Changes =====
Line 91: 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"]> 
 +loom { 
 + accessWidenerPath = file("src/main/resources/modid.accesswidener"
 +
 +</code> 
 + 
 +Loom 0.8 or lower:
  
 <code groovy [enable_line_numbers="true"]> <code groovy [enable_line_numbers="true"]>
-minecraft {+loom {
  accessWidener = file("src/main/resources/modid.accesswidener")  accessWidener = file("src/main/resources/modid.accesswidener")
 } }
 </code> </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.1587741992.txt.gz · Last modified: 2020/04/24 15:26 by modmuss50