User Tools

Site Tools


Sidebar

← Go back to the homepage

Fabric Tutorials

Setup

Basics

These pages are essential must-reads when modding with Fabric, and modding Minecraft in general, if you are new to modding, it is recommended you read the following.

Items

Blocks and Block Entities

Data Generation

World Generation

Commands

These pages will guide you through Mojang's Brigadier library which allows you to create commands with complex arguments and actions.

Events

These pages will guide you through using the many events included in Fabric API, and how to create your own events for you or other mods to use.

Entities

Fluids

Mixins & ASM

These pages will guide you through the usage of SpongePowered's Mixin library, which is a highly complex topic. We recommend you read these pages thoroughly.

Miscellaneous

Yarn

Contribute to Fabric

tutorial:accesswideners

Access Wideners

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 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 a good choice.

In order for access widener changes to show up in the decompiled source, run the genSources gradle task.

Requirements

  • Fabric-loader 0.8.0 or higher
  • Loom 0.2.7 or higher

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.

The file must start with the following header, namespace should usually always be 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.

accessWidener	v1	<namespace>

Once again, the namespace should be named in most if not all cases

Access widener files can have blank lines and comments starting with #

# Comments like this are supported, as well as at the end of the line

Any whitespace can be used to separate in the access widener file, tab is recommended.

Class names are separated with a / and not .

For inner classes, you should use $ instead of /

Classes

Class access can be changed by specifying the access and the class name as named the mappings namespace defined in the header.

<access>   class   <className>
  1. access can be accessible or extendable
Methods

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.

<access>   method   <className>   <methodName>   <methodDesc>
  1. access can be accessible or extendable
  2. className is the owner class
  3. methodName is the method name
  4. methodDesc is the method descriptor
Fields

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.

<access>   field   <className>   <fieldName>   <fieldDesc>
  1. access can be accessible or mutable
  2. className is the owner class
  3. fieldName is the field name
  4. fieldDesc is the field descriptor

Access Changes

Extendable

Extendable should be used where you want to extend a class or override a method.

  • Classes are made public and final is removed
  • Methods are made protected and final is removed

Making a method extendable also makes the class extendable.

Accessible

Accessible should be used when you want to access a class, field or method from another class.

  • Classes are made public
  • Methods are made public and final if private
  • Fields are made public

Making a method or field accessible also makes the class accessible.

Mutable

Mutable should be used when you want to mutate a final field

  • Fields have final removed

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.

Loom 0.9 or higher:

  1. loom {
  2. accessWidenerPath = file("src/main/resources/modid.accesswidener")
  3. }

Loom 0.8 or lower:

  1. loom {
  2. accessWidener = file("src/main/resources/modid.accesswidener")
  3. }

fabric.mod.json:

  1. ...
  2.  
  3. "accessWidener" : "modid.accesswidener",
  4.  
  5. ...

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.

tutorial/accesswideners.txt · Last modified: 2022/07/12 10:27 (external edit)