User Tools

Site Tools


tutorial:accesswidening

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
tutorial:accesswidening [2025/11/21 13:26] – ↷ Page name changed from tutorial:accesswideners to tutorial:accesswidening gauntreclusetutorial:accesswidening [2025/11/23 23:40] (current) – The big class tweaker rename earthcomputer
Line 1: Line 1:
 ====== Access Widening ====== ====== 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 widening provides a way to loosen the access limits of classes, methods or fields. This includes making them public, or making them extendable (subclassable).
  
-Access wideners may be used instead of accessor mixins, and there are currently 2 cases where the functionality provided by mixin is not sufficient:+Access widening 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.   * 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.
     * 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 sourcerun the ''genSources'' gradle task and then reload the gradle project in your IDE.+Access widening is a type of //class tweaking//, and is defined in the class tweaker file. In previous Fabric versions, the class tweaker was known as the "access widener" (as it had no other functionality).
  
-Note: Unlike accessor mixins, access wideners do not work for source of mods.+As with other types of class tweaking, in order for access widening changes to show up in the decompiled source, run the ''genSources'' gradle task and then reload the gradle project in your IDE. 
 + 
 +Note: Unlike accessor mixins, class tweaking only works on Minecraft code, and not on other mods.
  
-===== Requirements ===== 
-  * Fabric-loader 0.8.0 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 ''.accesswidener'' file extension.+A specific file format is used to define the access changes included in your mod. To aid IDEs you should use the ''.classtweaker'' file extension.
  
-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.+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 class tweaker file for you into ''intermediary'' along with your mod. In unobfuscated versions (upcoming, 1.21.12+), the namespace will be ''official'', and the class tweaker will not be remapped.
  
 <code [enable_line_numbers="true"]> <code [enable_line_numbers="true"]>
-accessWidener v2 <namespace>+classTweaker v1 <namespace>
 </code> </code>
  
 **Once again, the namespace should be ''named'' in most if not all cases** **Once again, the namespace should be ''named'' in most if not all cases**
  
-Access widener files can have blank lines and comments starting with #+Class tweaker files can have blank lines and comments starting with #
  
 <code [enable_line_numbers="true"]> <code [enable_line_numbers="true"]>
Line 33: Line 32:
 </code> </code>
  
-Any whitespace can be used to separate in the access widener file, tab is recommended.+Any whitespace can be used to separate in the class tweaker file, tab is recommended.
  
 Class names are separated with a / and not . Class names are separated with a / and not .
Line 107: Line 106:
 ===== 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. (Replace "modid" in the example with your own mod ID.)+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:+''build.gradle'':
  
 <code groovy [enable_line_numbers="true"]> <code groovy [enable_line_numbers="true"]>
Line 117: Line 116:
 </code> </code>
  
-Loom 0.8 or lower: +''fabric.mod.json'':
- +
-<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"]>
Line 134: Line 125:
 ... ...
 </code> </code>
 +
 +Note that for backwards compatibility reasons, the class tweaker is still referred to as an "access widener" in the ''build.gradle'' and the ''fabric.mod.json''. It will be renamed in FMJ2.0.
  
 ===== Validating the file ===== ===== Validating the file =====
-By default, accesswidener entries that don't exist are ignored. +By default, class tweaker 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.+You can run the ''validateAccessWidener'' gradle task (''./gradlew validateAccessWidener''to check that all the classes, fields and methods specified in the class tweaker 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'').+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 problemFor 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 =====+===== Transitive class tweakers =====
  
-With the v2 version, the ''transitive-*'' prefixed keywords have been added:+On all access widener directives, the ''transitive-*'' prefixed keywords can be used:
  
   * ''transitive-accessible''   * ''transitive-accessible''
Line 149: Line 142:
   * ''transitive-mutable''   * ''transitive-mutable''
  
-They differ from their regular, non-prefixed variants in that they also apply to mods that depend on this one.+They differ from their regular, non-prefixed variants in that they also apply to mods that depend on this one. This is useful for library mods that want to expose their class tweaker changes.
  
  
  
tutorial/accesswidening.txt · Last modified: 2025/11/23 23:40 by earthcomputer