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.
- Find the class, the member’s name and, for Fabric, its descriptor.
- Add the line to the mod’s access widener or access transformer.
- Refresh Gradle, then use the member like a public one.
For each loader and version
Section titled “For each loader and version”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 fieldLivingEntity.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 ZNeoForge 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.cfgLivingEntity.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 jumpingForge 1.17.1 to 1.20.1
Section titled “Forge 1.17.1 to 1.20.1”Uses:
META-INF/accesstransformer.cfgLivingEntity.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_ # jumpingForge 1.16.5
Section titled “Forge 1.16.5”Uses:
META-INF/accesstransformer.cfgLivingEntity.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 # jumpingForge 1.12.2
Section titled “Forge 1.12.2”Uses:
META-INF/<modid>_at.cfgEntityLivingBase.isJumping
A 1.12.2 access transformer is a file named <modid>_at.cfg in META-INF; add
FMLAT: examplemod_at.cfgto 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 # isJumpingSources
Section titled “Sources”- https://docs.fabricmc.net/1.21.11/develop/class-tweakers/
- https://docs.fabricmc.net/1.21.11/develop/class-tweakers/access-widening
- https://docs.neoforged.net/docs/1.21.1/advanced/accesstransformers
Related how-tos
Section titled “Related how-tos”- A block that does something when clicked
- A command that runs on the client
- A config value players can change
- A crafting recipe
- A furnace recipe
In Linen
Section titled “In Linen”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.