获取Minecraft路径使用Fabric

huangapple go评论77阅读模式
英文:

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

huangapple
  • 本文由 发表于 2020年8月3日 04:34:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/63220762.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定