-
Notifications
You must be signed in to change notification settings - Fork 339
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 22 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,181 @@ | ||
| --- | ||
| title: Access Widening | ||
| description: Learn how to use access wideners from class tweaker files. | ||
| authors-nogithub: | ||
| - glitch | ||
| - lightningtow | ||
| - siglong | ||
| authors: | ||
| - Ayutac | ||
| - cassiancc | ||
| - cootshk | ||
| - Earthcomputer | ||
| - florensie | ||
| - froyo4u | ||
| - haykam821 | ||
| - hYdos | ||
| - kb-1000 | ||
| - kcrca | ||
| - liach | ||
| - lmvdz | ||
| - matjojo | ||
| - MildestToucan | ||
| - modmuss50 | ||
| - octylFractal | ||
| - OroArmor | ||
| - T3sT3ro | ||
| - Technici4n | ||
| - UpcraftLP | ||
| - YTG1234 | ||
| --- | ||
|
|
||
| Access widening is a type of [class tweaking](../classtweaker) used to loosen the access limits of classes, methods and fields. This includes making them public, extendable and/or mutable. | ||
| To access fields or methods, it can be an alternative to [accessor mixins](https://wiki.fabricmc.net/tutorial:mixin_accessors), | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| but there are two situations where [accessors](https://wiki.fabricmc.net/tutorial:mixin_accessors) are insufficient and access widening is necessary: | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - Needing to access a (package) private class | ||
| - Needing to override a final method or subclass a final class. | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Note that, unlike [accessor mixins](https://wiki.fabricmc.net/tutorial:mixin_accessors), [class tweaking](../classtweaker) 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) and | ||
| fields or methods must specify their name along with their [bytecode descriptor](../mixins/bytecode#field-and-method-descriptors). | ||
MildestToucan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The names of targets should match your current mappings. Note that constructor methods are always named `<init>`, and always return void. | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Classes {#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 {#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 {#fields} | ||
|
|
||
| Format: | ||
|
|
||
| ```txt:no-line-numbers | ||
| <accessible / mutable> field <className> <methodName> <methodDescriptor> | ||
| ``` | ||
|
|
||
| Example: | ||
|
|
||
| @[code lang=txt:no-line-numbers transcludeWith=:::accesswidening-examples:fields:::](@/reference/latest/src/main/resources/example-mod.classtweaker) | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Generating Entries {#generating-entries} | ||
|
|
||
| Manually writing access widener entries is prone to human error and time-consuming. This section goes over tools that simplify a part of the process by allowing you to generate and copy entries. | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### mcsrc.dev {#mcsrc-dev} | ||
|
|
||
| Available for all versions with an [unobfuscated](../migrating-mappings/index#whats-going-on-with-mappings) jar, namely 1.21.11 and above, | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
MildestToucan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| [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. | ||
| On 1.21.11, the names of classes, methods and fields on [mcsrc](https://mcsrc.dev) will align with [Mojang Mappings](../migrating-mappings/index#mappings). | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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. | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|  | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Then, click on `Copy Class Tweaker / Access Widener`, and a confirmation should appear at the top of the page. | ||
|
|
||
|  | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| You can then paste the entry in your class tweaker file. | ||
|
|
||
| ### Minecraft Development Plugin (IntelliJ IDEA) {#mcdev-plugin} | ||
|
|
||
| The Minecraft Development Plugin, also known as MCDev, is an IntelliJ IDEA plugin to assist in various aspects of Minecraft mod development. | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| This section will show its ability to copy access widener entries to clipboard from the decompiled source target. | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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. | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|  | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Then, click on `Copy / Paste Special` and `AW Entry`. | ||
|
|
||
|  | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| A confirmation should now pop up on the element you right-clicked. | ||
|
|
||
|  | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| You can then paste the entry in your class tweaker file. | ||
|
|
||
| ### Linkie {#linkie} | ||
|
|
||
| [Linkie](https://linkie.shedaniel.dev) is a website to browse and translate between mappings. It also provides access widener entries for the class, method or field you're viewing. | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| First, make sure you have the correct version and mappings selected on the menu on the left: | ||
|
|
||
|  | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Then, search for the element you want to modify, and the access widener entry will be listed as `AW` under the result: | ||
|
|
||
|  | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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 [regenerate sources](../getting-started/generating-sources). The targeted elements should | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| have their access limits modified appropriately. If modifications do not appear, you can try [validating the file](../classtweaker/index#validating-the-file) | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| and see if any errors appear. | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The modified targets can then be used without any additional steps. | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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,57 @@ | ||
| --- | ||
| title: Class Tweakers | ||
| description: Learn what class tweakers are, and how to set them up. | ||
| authors: | ||
| - cassiancc | ||
| - Earthcomputer | ||
| - its-miroma | ||
| - MildestToucan | ||
| --- | ||
|
|
||
| Class tweakers, known as access wideners prior to gaining further functionality, are used to complement Mixin's bytecode manipulation by providing additional transformation tools and allowing for certain runtime modifications to be visible from the development environment. | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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, appended with `.classtweaker` to help IDE plugins recognize them. They should be stored in `resources`. | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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 for backward compatibility reasons. | ||
its-miroma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #### 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", | ||
|
|
||
| ... | ||
| ``` | ||
|
|
||
| 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. | ||
Binary file added
BIN
+46.9 KB
public/assets/develop/classtweaker/accesswidening/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
...c/assets/develop/classtweaker/accesswidening/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
public/assets/develop/classtweaker/accesswidening/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
...ic/assets/develop/classtweaker/accesswidening/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
...c/assets/develop/classtweaker/accesswidening/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
public/assets/develop/classtweaker/accesswidening/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
...c/assets/develop/classtweaker/accesswidening/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.