Skip to content

How to reach a private or protected part of Minecraft

A mod can open up a private or protected field or method of the game instead of copying code or using reflection. Fabric does it with an access widener (called a class tweaker on newer Loom and Fabric Loader versions), named in fabric.mod.json and build.gradle. Forge and NeoForge use an access transformer, normally META-INF/accesstransformer.cfg (on 1.12.2 a META-INF/<modid>_at.cfg file). After the change, Gradle sets the game up again and the code can use the member.

Works on Minecraft 1.20.1 to 26.3 on NeoForge; Minecraft 1.16.5 to 26.3 on Fabric; Minecraft 1.16.5 to 1.20.1 on Forge; Minecraft 1.12.2 on Forge. Each example was compiled against its loader and version before it shipped in Linen.

  1. Find the class, the member’s name and, for Fabric, its descriptor.
  2. Add the line to the mod’s access widener or access transformer.
  3. Refresh Gradle, then use the member like a public one.

The example mod is examplemod in the package com.example.examplemod. Use your own mod id and package.

Fabric 1.16.5 to 1.21.1, Fabric 1.21.2 to 26.3

Section titled “Fabric 1.16.5 to 1.21.1, Fabric 1.21.2 to 26.3”

Uses:

  • accessible field
  • LivingEntity.jumping

src/main/java/com/example/examplemod/access/JumpCheckAccess.java

package com.example.examplemod.access;
import net.minecraft.world.entity.LivingEntity;
// LivingEntity#jumping is protected in Minecraft; the access widener (Fabric) or access transformer (NeoForge) makes it reachable here.
public final class JumpCheckAccess {
private JumpCheckAccess() {
}
public static boolean isJumping(LivingEntity entity) {
return entity.jumping;
}
}

Add this line to your access widener file:

accessible field net/minecraft/world/entity/LivingEntity jumping Z

NeoForge 1.20.1 to 1.21.1, NeoForge 1.21.2 to 26.3

Section titled “NeoForge 1.20.1 to 1.21.1, NeoForge 1.21.2 to 26.3”

Uses:

  • META-INF/accesstransformer.cfg
  • LivingEntity.jumping

src/main/java/com/example/examplemod/access/JumpCheckAccess.java

package com.example.examplemod.access;
import net.minecraft.world.entity.LivingEntity;
// LivingEntity#jumping is protected in Minecraft; the access widener (Fabric) or access transformer (NeoForge) makes it reachable here.
public final class JumpCheckAccess {
private JumpCheckAccess() {
}
public static boolean isJumping(LivingEntity entity) {
return entity.jumping;
}
}

Add this line to src/main/resources/META-INF/accesstransformer.cfg:

public net.minecraft.world.entity.LivingEntity jumping

Uses:

  • META-INF/accesstransformer.cfg
  • LivingEntity.jumping

src/main/java/com/example/examplemod/access/JumpCheckAccess.java

package com.example.examplemod.access;
import net.minecraft.world.entity.LivingEntity;
// LivingEntity#jumping is protected in Minecraft; the access transformer makes it reachable here.
public final class JumpCheckAccess {
private JumpCheckAccess() {
}
public static boolean isJumping(LivingEntity entity) {
return entity.jumping;
}
}

Add this line to src/main/resources/META-INF/accesstransformer.cfg:

public net.minecraft.world.entity.LivingEntity f_20899_ # jumping

Uses:

  • META-INF/accesstransformer.cfg
  • LivingEntity.jumping

Forge 1.16.5 access transformers name members by their SRG name (field_70703_bu is LivingEntity#jumping), not by the Mojang name.

src/main/java/com/example/examplemod/access/JumpCheckAccess.java

package com.example.examplemod.access;
import net.minecraft.entity.LivingEntity;
// LivingEntity#jumping is protected in Minecraft; the access transformer makes it reachable here.
public final class JumpCheckAccess {
private JumpCheckAccess() {
}
public static boolean isJumping(LivingEntity entity) {
return entity.jumping;
}
}

Add this line to src/main/resources/META-INF/accesstransformer.cfg:

public net.minecraft.entity.LivingEntity field_70703_bu # jumping

Uses:

  • META-INF/<modid>_at.cfg
  • EntityLivingBase.isJumping

A 1.12.2 access transformer is a file named <modid>_at.cfg in META-INF; add FMLAT: examplemod_at.cfg to the jar manifest in build.gradle. Members are named by their SRG name (field_70703_bu is EntityLivingBase#isJumping).

src/main/java/com/example/examplemod/access/JumpCheckAccess.java

package com.example.examplemod.access;
import net.minecraft.entity.EntityLivingBase;
// LivingEntity#jumping is protected in Minecraft; the access transformer makes it reachable here.
public final class JumpCheckAccess {
private JumpCheckAccess() {
}
public static boolean isJumping(EntityLivingBase entity) {
return entity.isJumping;
}
}

Add this line to src/main/resources/META-INF/examplemod_at.cfg:

public net.minecraft.entity.EntityLivingBase field_70703_bu # isJumping

Linen’s How-tos library has this page too, with the example for your own mod’s loader and Minecraft version. Hover a name in your code and Linen points to the how-tos that explain it. Both are free. Download Linen.