This tool generates wrapper classes using yarn mappings. It can be used as a library or a standalone Fabric mod.
Output: Yarnwrap
The obfuscated nature of Minecraft prevents runtime methods of accessing code in game. This project is created to expose more features of the game to scripting runtimes.
The constructor of the wrapper class takes the source class as argument.
SourcePlayer p = mc.player;
WrappedPlayer wp = new WrappedPlayer(p);The wrapped object is stored in public field wrapperContained.
WrappedPlayer wp = new WrappedPlayer(mc.player);
SourcePlayer p = wp.wrapperContained;Methods can be accessed same as how it is accessed in its source class.
Fields can be accessed as a function by its original name.
int x1 = source.x;
int x2 = wrapped.x();
x1 == x2 // trueAnd using a similar mechanism for writing to fields.
source.x = 123;
wrapped.x(123);Since yarn mappings does not contain inheritance descriptors, inheritance is not represented in the generated code. For instance, using the source classes.
client.Player p;
p.getBlockX(); // .getBlockX() is in client.Entity, not PlayerIn wrapper classes, you can only use classes that are strictly defined in client.player. Alternatively, you may manually convert between classes.
client.PlayerWrapped p;
client.EntityWrapped e = new EntityWrapped(p);
e.getBlockX(); // .getBlockX() is in client.Entity, so we can access it from `e`For Minecraft versions without releases, you can build it yourself instead.
yarn-wrapper-geninstalled on system.
cargo install --git 'https://github.com/FabricCore/yarn-wrapper-gen'gradlew-commentatorinstalled on system.
cargo install --git 'https://github.com/FabricCore/gradlew-commentator'yarnmappings accessible on system.
git clone 'https://github.com/FabricMC/yarn' ~/Downloads/yarn- Specify Minecraft version. Browse
yarncommits to find the specific game version.
git checkout [commit-hash]- Create or open an existing Minecraft mod project (FabricMC + Gradle) make sure your code compiles without error, add the following line to
gradle.build.
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xmaxerrs" << "100000000"
}
}
}- Use
yarn-wrapper-gento generate uncleaned wrapper classes.
yarn-wrapper-gen ~/Downloads/yarn/mappings/net ~/Downloads/yarnwrap 'com.example.package.yarnwrap'
- The first argument points to
/mappings/netin the yarn repository.- The second argument points to the output path for the generated files.
- The third argument is package name for the generated code in your project.
Note that arguments in groups of 2 remaps the parts of the qualifying class name, the
yarnwraplibrary remapsyarnwrap.net.minecrafttoyarnwrap.yarn-wrapper-gen ~/Downloads/yarn/mappings/net ~/Downloads/yarnwrap 'yarnwrap' 'yarnwrap.net.minecraft' 'yarnwrap'
- Copy the generated files to your project, at the specified location (argument 3). Again make sure that your code compiles without errors.
- Change directory to your project, and use
gradlew-commentatorto clean your code to a compilable state. This process runs./gradlew checkmultiple times and may take up to 10 minutes.
gradlew-commentatorNote that if
gradlew-commentatorstop during execution, and./gradlew checkshows the code still contain errors, clean compiler cache with./gradlew cleanand run it again.