跳到正文

Lexiconfig

作者:CodinGlitch

这是一个配置 API,旨在与其他前置库一起提供大量集成功能,并且尽可能易于使用,无论对开发者还是用户都是如此。

收藏

介绍

介绍由机器翻译自 Modrinth 原页面,仅供参考。

概述

这是一个配置 API,旨在为多个不同的配置前置库提供兼容性,同时便于在多加载器项目环境中使用,主要用于我的模组。

它采用简单易用的基于注解的语法,让创建新的配置文件变得尽可能简单。

如果你只是模组用户,那么这些信息可能对你没什么用。不过,如果你是模组开发者,并且希望在自己的项目中使用 Lexiconfig,请继续查看“开发”部分。

目前它还不支持其他配置前置库,但随着我持续更新,我会逐步为每个配置前置库添加更多兼容性支持,以确保它不会与其他前置库发生冲突,而是能够在它们之间无缝集成。

以下是当前已经集成以及计划集成的不同配置前置库/API:

❌ – 未集成
✅ – 已集成
❓ – 进行中
| 状态 | 模组 |
| ————- | ————- |
| ❌ | Cloth Config |
| ❌ | oωo config |
| ✅ | Configured |
| ❌ | Forge Config Screens |

开发

此模组包含一个 API,可用于收纳新的词典、监听事件等。

依赖

build.gradle

repositories {
  maven { url 'https://maven.codinglitch.com/repository/releases' }
}

dependencies {
  implementation "com.codinglitch.lexiconfig:lexiconfig-api:API_VERSION_HERE"
}

你可以前往 https://versions.codinglitch.com 查看最新的 API 版本。

用法

要收纳你自己的词典,首先需要创建自己的 Library。只需创建一个继承自 Library 类的新类,并使用 LexiconLibrary 注解进行标注即可。

@LexiconLibrary
public class MyNewLibrary extends Library {
  @Override
  public void shelveLexicons() {
      
  }
}

在 Forge 环境中,不需要进行其他更改。不过,如果你是为 Fabric 开发,则需要将此类作为入口点添加到你的 fabric.mod.json 中。

fabric.mod.json

//...
"entrypoints": {
  "lexiconfig": [
    "com.path.to.MyNewLibrary"
  ]
}
//...

下一步就是创建并收纳你的词典。你只需为词典创建另一个类,并为其提供适当的注解,如下所示:

@Lexicon(name = MY_LEXICON_TITLE) // preferably use your mod id as a name
public class MyLexicon extends LexiconData {
  @LexiconEntry(comment = "This is a comment for a simple field!")
  public String mySimpleField = "content";

  @LexiconPage(comment = "This is a fancy new comment on the fancy new category!")
  public MyNewPage myNewPage = new MyNewPage();

  public static class MyNewPage extends LexiconPageData {
    @LexiconEntry(comment = "This field is inside a lexicon page!")
    public Boolean myPageField = true;
  }
}

最后一步是收纳词典,只需将其实例作为字段添加到 Library 中,并在指定的方法里将其收纳即可。

@LexiconLibrary
public class MyNewLibrary extends Library {
  public static MyLexicon MY_LEXICON = new MyLexicon();
  
  @Override
  public void shelveLexicons() {
    LexiconfigApi.shelveLexicon(MY_LEXICON);
  }
}

评论

登录后评论和评分

CodinGlitch 的其他作品

查看全部 →