tinycodinglm / mc /mc-0023.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 16)
d517dc9 verified
|
Raw History Blame Contribute Delete
2.28 kB
opencode trace
System You are an expert Minecraft modder who understands mapping systems (Mojang, Yarn, Intermediary) and how to work with unobfuscated/deobfuscated Minecraft source code.

You are an expert Minecraft modder who understands mapping systems (Mojang, Yarn, Intermediary) and how to work with unobfuscated/deobfuscated Minecraft source code.

User

How do I write access wideners with Mojang mappings in Fabric?

Assistant

Access wideners allow you to make private/protected members public in Minecraft's code using Mojang-mapped names.

Access widener file (mymod.accesswidener):

accesswidener
accessWidener v2 named

# Make a private method public
accessible method net/minecraft/world/entity/LivingEntity tick ()V

# Make a protected field accessible
accessible field net/minecraft/world/level/block/Block stateDefinition Lnet/minecraft/world/level/block/state/StateDefinition;

# Make a private constructor accessible
accessible method net/minecraft/world/entity/Entity <init> (Lnet/minecraft/world/level/Level;)V

fabric.mod.json integration:

json
{
    "schemaVersion": 1,
    "id": "mymod",
    "accessWidener": "mymod.accesswidener",
    "entrypoints": {
        "main": ["com.example.mymod.MyMod"]
    }
}

Using access-widened members in code:

java
package com.example.mymod;

import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.block.Block;

public class MyMod {
    public void modifyEntity(LivingEntity entity) {
        // Can now call tick() even though it's normally protected
        entity.tick();
    }

    public void accessBlockState(Block block) {
        // Access the stateDefinition field directly
        var stateDef = block.stateDefinition;
    }
}

Access widener syntax rules:

  • Use named namespace for Mojang mappings
  • Method descriptors use Mojang names
  • Field descriptors use Mojang class paths
  • Only modify members in Minecraft's code, not mod code

Gradle configuration:

groovy
// build.gradle
fabricApi {
    accessWidenerPath = file("mymod.accesswidener")
}