SystemYou are an expert SpongePowered Mixin internals developer. You understand how mixins work at the bytecode level using ASM, and can debug, write, and optimize mixins.
You are an expert SpongePowered Mixin internals developer. You understand how mixins work at the bytecode level using ASM, and can debug, write, and optimize mixins.
User
What's the difference between Access Wideners (Fabric) and Access Transformers (Forge/NeoForge)? How do they work at the bytecode level?
Assistant
Access Wideners (AW) and Access Transformers (AT) both modify class access modifiers, but differ in design and implementation.
Access Wideners (Fabric):
AW files declare access changes in a simple format:
text
accessWidener v1 named
# Widen field access
accessible field net/minecraft/entity/LivingEntity health I
# Widen method access
accessible method net/minecraft/entity/LivingEntity damage (Lnet/minecraft/entity/damage/DamageSource;F)Z
# Widen class access
accessible class net/minecraft/entity/ai/brain/task/Task
AW Processing:
java
// AccessWidenerTransformer applies at class load time:publicclassAccessWidenerTransformer {
publicbyte[] transform(String className, byte[] bytes) {
AccessWidenerwidener= MixinEnvironment.getCurrentEnvironment().getAccessWidener();
if (widener.isAccessWidened(className)) {
ClassNodeclassNode= readClass(bytes);
for (FieldNode field : classNode.fields) {
if (widener.isFieldAccessWidened(className, field.name)) {
// Remove ACC_PRIVATE, ACC_PROTECTED// Add ACC_PUBLIC
field.access = removeModifiers(field.access, ACC_PRIVATE | ACC_PROTECTED);
field.access |= ACC_PUBLIC;
}
}
for (MethodNode method : classNode.methods) {
if (widener.isMethodAccessWidened(className, method.name, method.desc)) {
method.access = removeModifiers(method.access, ACC_PRIVATE | ACC_PROTECTED);
method.access |= ACC_PUBLIC;
}
}
return writeClass(classNode);
}
return bytes;
}
}
Access Transformers (Forge/NeoForge):
AT files use SRG names and support more fine-grained control:
text
public-f net.minecraft.world.level.block.Blocks AIR # some comment
public net.minecraft.world.level.block.state.BlockState # widened state field
Key Differences:
Feature
Access Wideners
Access Transformers
Mapping
Yarn/named
SRG/MCP
Scope
Fields, methods, classes
Fields, methods, packages
Transitive
Yes (propagates to subclasses)
No (target class only)
Complexity
Simple, readable
More powerful but verbose
Platform
Fabric
Forge/NeoForge
Bytecode-level difference:
java
// Both modify the access flags in the class file:// Before: ACC_PRIVATE | ACC_FINAL = 0x001A// After AW: ACC_PUBLIC = 0x0001// After AT: ACC_PUBLIC = 0x0001// The actual change is identical - just different input formats
field.access = ACC_PUBLIC; // Both produce this
Fabric prefers AW because they're declarative and don't require mixins for simple access changes. Mixins remain the tool for adding new behavior, not just changing visibility.