-
Notifications
You must be signed in to change notification settings - Fork 338
Class Tweakers: Introduction & Access Widening #517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
its-miroma
merged 33 commits into
FabricMC:main
from
MildestToucan:wikiports-accesswidening
Mar 24, 2026
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
57cd5db
Create ClassTweaker section, create accesswidening.md
MildestToucan a6a9e71
Add Wiki contributors to authors
MildestToucan 564d25d
Add introduction page to class tweakers, call it class tweakers rathe…
MildestToucan 53b7823
first iteration of class tweaker introduction page
MildestToucan abf616f
Merge branch 'FabricMC:main' into wikiports-accesswidening
MildestToucan 5cda3c0
make first iteration of accesswidening.md page contents
MildestToucan 1ac401e
defer class name formatting to bytecode page, specify MC targets and …
MildestToucan b611165
Merge branch 'FabricMC:main' into wikiports-accesswidening
MildestToucan 2a20d01
Merge branch 'FabricMC:main' into wikiports-accesswidening
MildestToucan 3a378fc
Create and specify location for example class tweaker file
MildestToucan 3a03597
Fix depends block being empty
MildestToucan 72c35c6
Get ready for draft PR
MildestToucan 374bbb7
Add AW examples based on Fabric API AW entries
MildestToucan e77d717
Add explicit recommendation to read the introduction
MildestToucan 0cc22ca
Prepare for draft PR
MildestToucan b753194
Document tools to generate and copy AW entries
MildestToucan b645e40
Deduplicate Validating File section
MildestToucan bcd691c
fix build errors
cassiancc 01071ff
Working tree cleanup
MildestToucan 77a9baf
Merge Cassian build error fixes with local changes
MildestToucan fe390f5
Final preparations before pushing out of drafting
MildestToucan 6cce5da
linting
cassiancc 082c30a
Apply suggested changes accordingly
MildestToucan a438ea9
Fix Fields format saying methodName and methodDescriptor instead of f…
MildestToucan 6b27134
Apply build.gradle suggestion from @its-miroma
MildestToucan 03de319
Readd the first line of the AW page. Somehow missed that I removed it.
MildestToucan 8f1ada9
Up info about CTs and MC versions, and only being able to target MC c…
MildestToucan 0fc581d
Note accessors as being safer/simpler for accessing fields and methods
MildestToucan 8241f30
Apply additional suggestions
MildestToucan 8305713
Change URLs, make appropriate renames for files, translation keys and…
MildestToucan 742e2ea
Fix to link to new CT Docs, make path reference a CT file rather than AW
MildestToucan 1b58bc3
Fix to say CT file rather than AW file in comment with link
MildestToucan 4bdeae5
Add TheGlitch76 to authors, remove nogithub equivalent glitch.
MildestToucan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| --- | ||
| title: Access Widening | ||
| description: Learn how to use access wideners from class tweaker files. | ||
| authors-nogithub: | ||
| - lightningtow | ||
| - siglong | ||
| authors: | ||
| - Ayutac | ||
| - cassiancc | ||
| - cootshk | ||
| - Earthcomputer | ||
| - florensie | ||
| - froyo4u | ||
| - haykam821 | ||
| - hYdos | ||
| - its-miroma | ||
| - kb-1000 | ||
| - kcrca | ||
| - liach | ||
| - lmvdz | ||
| - matjojo | ||
| - MildestToucan | ||
| - modmuss50 | ||
| - octylFractal | ||
| - OroArmor | ||
| - T3sT3ro | ||
| - Technici4n | ||
| - TheGlitch76 | ||
| - UpcraftLP | ||
| - YTG1234 | ||
| --- | ||
|
|
||
| Access widening is a type of [class tweaking](../class-tweakers) used to loosen the access limits of classes, methods and fields and reflect that change in the decompiled source. | ||
| This includes making them public, extendable and/or mutable. | ||
|
|
||
| To access fields or methods, it can be safer and simpler to use [accessor mixins](https://wiki.fabricmc.net/tutorial:mixin_accessors), | ||
| but there are two situations where accessors are insufficient and access widening is necessary: | ||
|
|
||
| - If you need to access a `private`, `protected` or package-private class | ||
| - If you need to override a `final` method, or subclass a `final` class | ||
|
|
||
| However, unlike [accessor mixins](https://wiki.fabricmc.net/tutorial:mixin_accessors), [class tweaking](../class-tweakers) only works on Vanilla Minecraft classes, and not on other mods. | ||
|
|
||
| ## Access Directives {#access-directives} | ||
|
|
||
| Access widener entries start with one of three directive keywords to specify the type of modification to apply. | ||
|
|
||
| ### Accessible {#accessible} | ||
|
|
||
| `accessible` can target classes, methods and fields: | ||
|
|
||
| - Fields and Classes are made public. | ||
| - Methods are made public, and final if originally private. | ||
|
|
||
| Making a method or field accessible also makes its class accessible. | ||
|
|
||
| ### Extendable {#extendable} | ||
|
|
||
| `extendable` can target classes and methods: | ||
|
|
||
| - Classes are made public and non-final | ||
| - Methods are made protected and non-final | ||
|
|
||
| Making a method extendable also makes its class extendable. | ||
|
|
||
| ### Mutable {#mutable} | ||
|
|
||
| `mutable` can make a field non-final. | ||
|
|
||
| To make a private final field both accessible and mutable, you must make two separate entries in the file. | ||
|
|
||
| ### Transitive Directives {#transitive-directives} | ||
|
|
||
| In order to expose certain access widener changes to mods depending on yours, you prefix the relevant directives with `transitive-*`: | ||
|
|
||
| ```txt:no-line-numbers | ||
| transitive-accessible | ||
| transitive-extendable | ||
| transitive-mutable | ||
| ``` | ||
|
|
||
| ## Specifying Targets {#specifying-targets} | ||
|
|
||
| For class tweaking, classes use their [internal names](../mixins/bytecode#class-names). For fields and methods you must specify their class name, their name, and their [bytecode descriptor](../mixins/bytecode#field-and-method-descriptors). | ||
|
|
||
| ::: tip | ||
|
|
||
| The names of targets need to correspond to your current mappings. | ||
|
|
||
| ::: | ||
|
|
||
| ::: tabs | ||
|
|
||
| == Classes | ||
|
|
||
| Format: | ||
|
|
||
| ```txt:no-line-numbers | ||
| <accessible / extendable> class <className> | ||
| ``` | ||
|
|
||
| Example: | ||
|
|
||
| @[code lang=txt:no-line-numbers transcludeWith=:::accesswidening-examples:classes:::](@/reference/latest/src/main/resources/example-mod.classtweaker) | ||
|
|
||
| == Methods | ||
|
|
||
| Format: | ||
|
|
||
| ```txt:no-line-numbers | ||
| <accessible / extendable> method <className> <methodName> <methodDescriptor> | ||
| ``` | ||
|
|
||
| Example: | ||
|
|
||
| @[code lang=txt:no-line-numbers transcludeWith=:::accesswidening-examples:methods:::](@/reference/latest/src/main/resources/example-mod.classtweaker) | ||
|
|
||
| == Fields | ||
|
|
||
| Format: | ||
|
|
||
| ```txt:no-line-numbers | ||
| <accessible / mutable> field <className> <fieldName> <fieldDescriptor> | ||
| ``` | ||
|
|
||
| Example: | ||
|
|
||
| @[code lang=txt:no-line-numbers transcludeWith=:::accesswidening-examples:fields:::](@/reference/latest/src/main/resources/example-mod.classtweaker) | ||
|
|
||
| ::: | ||
|
|
||
| ## Generating Entries {#generating-entries} | ||
|
|
||
| Manually writing access widener entries is time-consuming and prone to human error. Let's look at tools that simplify a part of the process by allowing you to generate and copy entries. | ||
|
|
||
| ### mcsrc.dev {#mcsrc-dev} | ||
|
|
||
| Available for all versions with an [unobfuscated JAR](../migrating-mappings/index#whats-going-on-with-mappings) namely 1.21.11 and above, | ||
| [mcsrc](https://mcsrc.dev) allows you to decompile and navigate Minecraft source in the browser and copy Mixin, access widener or access transformer targets to clipboard. | ||
| The names of classes, methods and fields on [mcsrc](https://mcsrc.dev) will align with [Mojang Mappings](../migrating-mappings/index#mappings). | ||
|
|
||
| To copy an access widener entry, first navigate to the class which you want to modify, and right-click on your target to open the popup menu. | ||
|
|
||
|  | ||
|
|
||
| Then, click on `Copy Class Tweaker / Access Widener`, and a confirmation should appear at the top of the page. | ||
|
|
||
|  | ||
|
|
||
| You can then paste the entry in your class tweaker file. | ||
|
|
||
| ### Minecraft Development Plugin (IntelliJ IDEA) {#mcdev-plugin} | ||
|
|
||
| The [Minecraft Development Plugin](../getting-started/intellij-idea/setting-up#installing-idea-plugins), also known as MCDev, is an IntelliJ IDEA plugin to assist in various aspects of Minecraft mod development. | ||
| For example, it lets you copy access widener entries from the decompiled source target to the clipboard. | ||
|
|
||
| To copy an access widener entry, first navigate to the class which you want to modify, and right-click on your target to open the popup menu. | ||
|
|
||
|  | ||
|
|
||
| Then, click on `Copy / Paste Special` and `AW Entry`. | ||
|
|
||
|  | ||
|
|
||
| A confirmation should now pop up on the element you right-clicked. | ||
|
|
||
|  | ||
|
|
||
| You can then paste the entry in your class tweaker file. | ||
|
|
||
| ### Linkie {#linkie} | ||
|
|
||
| [Linkie](https://linkie.shedaniel.dev) is a website that allows you to browse and translate across mappings. It also provides access widener entries for the class, method or field you're viewing. | ||
|
|
||
| First, make sure you have the correct version and mappings selected on the menu on the left: | ||
|
|
||
|  | ||
|
|
||
| Then, search for the element you want to modify, and the access widener entry will be listed as `AW` under the result: | ||
|
|
||
|  | ||
|
|
||
| You can copy it and then paste the entry in your class tweaker file. | ||
|
|
||
| ## Applying Changes {#applying-changes} | ||
|
|
||
| To see your changes applied, you must refresh your Gradle project by [regenerating sources](../getting-started/generating-sources). The elements you targeted should | ||
| have their access limits modified accordingly. If modifications do not appear, you can try [validating the file](../class-tweakers/index#validating-the-file) | ||
| and checking if any errors appear. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| --- | ||
| title: Class Tweakers | ||
| description: Learn what class tweakers are, and how to set them up. | ||
| authors: | ||
| - cassiancc | ||
| - Earthcomputer | ||
| - its-miroma | ||
| - MildestToucan | ||
| --- | ||
|
|
||
| Class tweakers, formerly known as access wideners before gaining further functionality, provide transformation tools complementary to Mixin bytecode manipulation. They also allow some runtime modifications to be accessible within the development environment. | ||
|
|
||
| ::: warning | ||
|
|
||
| Class tweakers are not specific to a given Minecraft version, but are only available starting from Fabric Loader 0.18.0, and may only target Vanilla Minecraft classes. | ||
|
|
||
| ::: | ||
|
|
||
| ## Setup {#setup} | ||
|
|
||
| ### File Format {#file-format} | ||
|
|
||
| Class tweaker files are conventionally named after your modid, `example-mod.classtweaker`, to help IDE plugins recognize them. They should be stored in `resources`. | ||
|
|
||
| The file must have the following header as its first line: | ||
|
|
||
| ```txt | ||
| classTweaker v1 named | ||
| ``` | ||
|
|
||
| Class tweaker files can have blank lines and comments starting with `#`. Comments can start at the end of a line. | ||
|
|
||
| Whilst the specific syntax depends on the feature, modifications are each declared on separate lines. An entry's elements can be separated using any whitespace, including tabs. | ||
|
|
||
| ### Specifying The File Location {#specifying-the-file-location} | ||
|
|
||
| The class tweaker file's location must be specified in your `build.gradle` and `fabric.mod.json` files. Remember that you must also depend on Fabric Loader 0.18.0 or above to use class tweakers. | ||
|
|
||
| The specifications are still named after access wideners to preserve backwards compatibility. | ||
|
|
||
| #### build.gradle {#build-gradle} | ||
|
|
||
| @[code lang=gradle:no-line-numbers transcludeWith=:::classtweaker-setup:gradle:::](@/reference/latest/build.gradle) | ||
|
|
||
| #### fabric.mod.json {#fabric-mod-json} | ||
|
|
||
| ```json:no-line-numbers | ||
| ... | ||
| "accessWidener": "example-mod.classtweaker", | ||
| ... | ||
| ``` | ||
MildestToucan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| After specifying the file location in your `build.gradle` file, make sure to reload your Gradle project in the IDE. | ||
|
|
||
| ## Validating the File {#validating-the-file} | ||
|
|
||
| By default, class tweaker will ignore entries referencing modification targets that cannot be found. To check if all the classes, fields and methods specified in the file are valid, run the `validateAccessWidener` Gradle task. | ||
|
|
||
| Errors will point out any invalid entry, but they can be about which part of an entry is invalid. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+46.9 KB
public/assets/develop/class-tweakers/access-widening/linkie-search-results.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+36.6 KB
...ssets/develop/class-tweakers/access-widening/linkie-version-mappings-select.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+24.9 KB
...ic/assets/develop/class-tweakers/access-widening/mcdev-aw-copy-confirmation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+38.5 KB
...assets/develop/class-tweakers/access-widening/mcdev-copy-paste-special-menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+73.4 KB
...ssets/develop/class-tweakers/access-widening/mcdev-right-click-on-aw-target.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.4 KB
...ic/assets/develop/class-tweakers/access-widening/mcsrc-aw-copy-confirmation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+35.7 KB
...ssets/develop/class-tweakers/access-widening/mcsrc-right-click-on-aw-target.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
reference/latest/src/main/resources/example-mod.classtweaker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| classTweaker v1 named | ||
|
|
||
| # Access widening examples | ||
| # The targets for these examples are non-transitive versions of Fabric API access wideners for 1.21.11 | ||
|
|
||
| # :::accesswidening-examples:classes::: | ||
| # Makes the inner class TypeSpecificTrade in VillagerTrades public | ||
| accessible class net/minecraft/world/entity/npc/villager/VillagerTrades$TypeSpecificTrade | ||
| # :::accesswidening-examples:classes::: | ||
|
|
||
| # :::accesswidening-examples:methods::: | ||
| # Makes the SensorType(Supplier) constructor public | ||
| accessible method net/minecraft/world/entity/ai/sensing/SensorType <init> (Ljava/util/function/Supplier;)V | ||
|
|
||
| # Makes the formatValue() method of return type String in TextColor public | ||
| accessible method net/minecraft/network/chat/TextColor formatValue ()Ljava/lang/String; | ||
| # :::accesswidening-examples:methods::: | ||
|
|
||
|
|
||
| # :::accesswidening-examples:fields::: | ||
| # Makes the field damageTypes of type Registry in DamageSources public. | ||
| accessible field net/minecraft/world/damagesource/DamageSources damageTypes Lnet/minecraft/core/Registry; | ||
| # :::accesswidening-examples:fields::: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.