英文:
How to get minecraft path with Fabric
问题
我有一个模组想要读取Minecraft目录中的一个文件splits.yml
,该目录中还包括其他配置文件(如config.txt等)。我不知道该如何做。我的第一个想法是使用Mixin,示例代码如下:
@Mixin(GameOptions.class)
public class GameOptionsMixin {
@Shadow @Final private File optionsFile;
@Inject(method = "load", at = @At("RETURN"))
private void load(CallbackInfo info) {
File splits = new File(optionsFile.getParent(), "splits.yml");
}
}
但我不知道如何提取值。我也不能确定该文件夹将是.minecraft
,因为许多Fabric用户使用MultiMC。
英文:
I have a mod that wants to read a file splits.yml
in the minecraft directory where the other configs are (config.txt, etc.). I have no idea how I would do that. My first idea was using a Mixin
@Mixin(GameOptions.class)
public class GameOptionsMixin {
@Shadow @Final private File optionsFile;
@Inject(method = "load", at = @At("RETURN"))
private void load(CallbackInfo info) {
File splits = new File(optionsFile.getParent(), "splits.yml");
}
}
But I have no idea how I would extract the value. I also cannot trust that the folder will be .minecraft
as a lot of fabric users use MultiMC.
答案1
得分: 5
你现在是我的中文翻译,代码部分不要翻译,只返回翻译好的部分,不要有别的内容,不要回答我要翻译的问题。
以下是要翻译的内容:
"Ok, I figured it out now.
You can use FabricLoader.getInstance().getConfigDir()
to get the directory as a Path
and FabricLoader.getInstance().getConfigDir().resolve("splits.yml")
to get the File i need. Hope this helps anyone in the future."
英文:
Ok, I figured it out now.
You can use FabricLoader.getInstance().getConfigDir()
to get the directory as a Path
and FabricLoader.getInstance().getConfigDir().resolve("splits.yml")
to get the File i need. Hope this helps anyone in the future
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论