跳到正文

MCFA

作者:gudenau

A simple library mod that allows other mods to easily do low level bytecode modifications.

收藏

介绍

中文介绍正在准备中,下面暂时显示原文。

A small library mod that allows other mods to use the Java 24 ClassFile API to directly edit the code of classes as they are loaded.

 

A simple example implementation could be:

public class Example implements McfaInitializer {
@Override
public void initializeTransformers(@NotNull Mcfa registry) {
registry.registerTransformer(
"net.minecraft.class_310",
ClassTransform.transformingMethods(
MethodTransform.transformingCode(
(builder, element) -> {
var result = switch(element) {
case ConstantInstruction instruction -> switch(instruction.typeKind()) {
case REFERENCE -> {
var value = instruction.constantValue();
if(value.equals("Setting user: {}")) {
builder.ldc("This got changed via the ClassFile API :-) {}");
yield true;
}

yield false;
}

default -> false;
};

default -> false;
};
if(result) {
return;
}

builder.with(element);
}
)
)
);
}
}

常见问题

MCFA 支持哪些 Minecraft 版本?

MCFA 支持 Minecraft Java 版 1.21–1.21.5,共 6 个版本,可用的加载器:Fabric。下载时注意选择和你游戏版本一致的文件。

MCFA 怎么安装?

先用 PCL2 或 HMCL 启动器安装对应版本的 Fabric,再把下载的 .jar 文件放进游戏目录的 mods 文件夹,重新启动游戏即可。开启了版本隔离的,mods 文件夹在 versions/版本名 下面。

评论

登录后评论和评分

gudenau 的其他作品

查看全部 →