YAML Config:一款 Minecraft 配置模组
概述
YAML Config 是一款强大的 Minecraft 配置模组,使模组开发者能够使用 YAML 文件格式来创建和管理配置设置。它提供用户友好的图形界面(GUI),广泛支持各种数据类型,并具备用于客户端与服务器同步的强大网络功能。
特性
-
YAML 文件格式: YAML Config 采用 YAML 文件格式,以其可读性强和易于使用而闻名。
-
图形界面: 设计精良的 GUI 允许玩家轻松浏览和编辑其配置设置。
-
广泛的数据类型支持: 该模组支持多种数据类型,包括:
- 基本类型:
boolean、int、float、double、String、ResourceLocation、Registry - 集合:
List、Map - 日期和时间:
LocalDateTime
- 基本类型:
-
服务器-客户端同步: 在服务器上对配置所做的更改会自动同步到客户端,确保游戏体验的一致性。
-
整合包支持: 该模组旨在与现有的整合包无缝配合,提供灵活且可扩展的配置系统。
-
验证与错误处理: 该模组包含强大的验证和错误处理机制,确保配置符合预期要求。
安装与使用
安装
- 下载模组: 从 YAML Config 的官方网站、CurseForge 或 Modrinth 下载最新版本。
- 放置模组文件: 将下载的 JAR 文件移动到 Minecraft 目录中的 "mods" 文件夹内。
- 启动 Minecraft: 启动 Minecraft 并加入一个世界。
使用
-
打开配置屏幕: 按下键盘上的 "F12" 键打开配置屏幕。
-
导航至配置项: 配置屏幕会显示可用配置的列表。选择你想要修改配置的模组。
-
编辑配置条目: 配置屏幕会显示可用的设置。每个条目包括:
- 标题: 设置的名称。
- 输入框: 用于编辑值的字段。
- 重置按钮: 用于将值重置为默认值的按钮。
-
保存更改: 点击“保存更改”按钮以保存你的修改。模组会自动将更改保存到配置文件,并与其他玩家同步(如果适用)。
开发
创建配置
1. 定义配置类:
- 在模组的代码库中创建一个新的 Java 类,代表你模组的配置。
public class MyModConfig {
public static IConfig config;
public static IConfigEntry<Boolean> debug;
public static void init() {
ConfigBuilder builder = new ConfigBuilder(MyMod.MOD_ID, "mymod-config", ConfigExtension.YAML, ConfigType.CLIENT);
}
}
2. 定义配置条目:
- 使用
ConfigBuilder类来定义配置的设置。 - 使用
define*方法为每个条目选择合适的数据类型。
// 定义布尔型条目的示例:
debug = builder.defineBoolean("debug", false);
// 定义带有范围限制的整数型条目的示例:
intEntry = builder.defineInteger("intEntry", 10, 0, 100); // 最小值 0,最大值 100
// 定义带有正则表达式模式的字符串型条目的示例:
stringEntry = builder.defineString("stringEntry", "test", "test\\d+");
// 定义注册表条目的示例:
registryEntry = builder.defineRegistry("registryEntry", Blocks.GRASS_BLOCK, BuiltInRegistries.BLOCK);
// 定义列表的示例:
stringListEntry = builder.defineStringList("stringListEntry", List.of("test1", "test2", "test3"), 3, 10); // 最小长度 3,最大长度 10
// 定义映射的示例:
integerMapEntry = builder.defineIntegerMap("integerMapEntry", Map.of("test1", 1, "test2", 2, "test3", 3), 3, 10); // 最小数量 3,最大数量 10
3. 构建配置:
- 在
ConfigBuilder上调用build()方法来创建你的配置。 - 将配置存储在静态字段中,以便在模组代码中轻松访问。
public MyModConfig() {
ConfigBuilder builder = new ConfigBuilder("mymod", "mymod-config", ConfigExtension.YAML, ConfigType.CLIENT);
// ... 定义配置条目
config = builder.build();
}
4. 在代码中访问配置值:
- 使用
get()方法检索配置条目的当前值。 - 使用
set()方法修改配置条目的值。
// 示例:
boolean debugEnabled = MyModConfig.debug.get(); // 检索 "debug" 设置的当前值
if (debugEnabled) {
// 执行调试相关操作
}
MyModConfig.intEntry.set(25); // 将 "intEntry" 的值设置为 25
配置类型
ConfigType.CLIENT: 客户端配置仅针对安装了该模组的客户端。它们不会与服务器上的其他玩家共享。ConfigType.SERVER: 服务器端配置专用于专用服务器。它们不会在单人世界中使用,也不会同步给服务器上的玩家。ConfigType.COMMON: 通用配置在客户端和服务器之间共享。可以通过直接编辑配置文件并重启服务器,或者通过在游戏中编辑值并保存更改来进行修改。
使用自定义数据类型
- 使用
IConfigEntryType接口向 YAML Config 模组注册自定义数据类型。 - 实现自定义序列化器以处理自定义数据类型的序列化和反序列化。
整合包配置
- 如果您正在创建整合包,可以使用 YAML Config 来定义整合包的配置设置。
- 将整合包的配置文件放置在整合包目录下的 "config" 文件夹中。
示例
// 示例:基本的客户端侧配置
public class MyModConfig {
public static IConfig config;
public static IConfigEntry<Boolean> debug;
public static IConfigEntry<Integer> testInt;
public static void init() {
ConfigBuilder builder = new ConfigBuilder("mymod", "mymod-config", ConfigExtension.YAML, ConfigType.CLIENT);
debug = builder.defineBoolean("debug", false) // 默认为 false。
.withComments("是否启用模组的调试模式。");
testInt = builder.defineInteger("testInt", 10, 0, 100); // 默认为 10,最小值为 0,最大值为 100。
config = builder.build();
}
}
YAML Config: A Minecraft Configuration Mod
Overview
YAML Config is a powerful Minecraft configuration mod that enables mod developers to create and manage configuration settings using the YAML file format. It offers a user-friendly GUI, extensive support for data types, and robust networking for client-server synchronization.
Features
-
YAML File Format: YAML Config utilizes the YAML file format, known for its readability and ease of use.
-
GUI Interface: A well-designed GUI allows players to easily navigate and edit their configuration settings.
-
Extensive Data Type Support: The mod supports a wide range of data types, including:
- Primitive Types:
boolean,int,float,double,String,ResourceLocation,Registry - Collections:
List,Map - Date and Time:
LocalDateTime
- Primitive Types:
-
Server-Client Synchronization: Changes made to configurations on the server are automatically synchronized to clients, ensuring consistency across the gameplay experience.
-
Modpack Support: The mod is designed to work seamlessly with existing modpacks, offering a flexible and expandable configuration system.
-
Validation and Error Handling: The mod includes robust validation and error handling, ensuring that configurations meet the expected requirements.
Installation and Usage
Installation
- Download the mod: Download the latest version of YAML Config from the mod's official website, CurseForge, or Modrinth.
- Place the mod file: Move the downloaded JAR file into the "mods" folder within your Minecraft directory.
- Launch Minecraft: Start Minecraft and join a world.
Usage
-
Open the Configs Screen: Press "F12" on your keyboard to open the Configs screen.
-
Navigate to the Config: The Configs Screen displays a list of available configurations. Select the mod whose configuration you want to modify.
-
Edit Config Entries: The Config Screen displays the available settings. Each entry includes:
- Title: The name of the setting.
- Input Field: A field for editing the value.
- Reset Button: A button for resetting the value back to its default.
-
Save Changes: Click the "Save Changes" button to save your modifications. The mod will automatically save the changes to the configuration file and synchronize them with other players on the server (if applicable).
Development
Creating Configurations
1. Define a Config Class:
- Create a new Java class within your mod's codebase that represents your mod's configuration.
public class MyModConfig {
public static IConfig config;
public static IConfigEntry<Boolean> debug;
public static void init() {
ConfigBuilder builder = new ConfigBuilder(MyMod.MOD_ID, "mymod-config", ConfigExtension.YAML, ConfigType.CLIENT);
}
}
2. Define Config Entries:
- Use the
ConfigBuilderclass to define the settings for your configuration. - Choose the appropriate data type for each entry using the
define*methods.
// Example of defining a boolean entry:
debug = builder.defineBoolean("debug", false);
// Example of defining an integer entry with range:
intEntry = builder.defineInteger("intEntry", 10, 0, 100); // Min 0, Max 100
// Example of defining a string entry with pattern:
stringEntry = builder.defineString("stringEntry", "test", "test\\d+");
// Example of defining a registry entry:
registryEntry = builder.defineRegistry("registryEntry", Blocks.GRASS_BLOCK, BuiltInRegistries.BLOCK);
// Example of defining a list:
stringListEntry = builder.defineStringList("stringListEntry", List.of("test1", "test2", "test3"), 3, 10); // Min 3, Max 10
// Example of defining a map:
integerMapEntry = builder.defineIntegerMap("integerMapEntry", Map.of("test1", 1, "test2", 2, "test3", 3), 3, 10); // Min 3, Max 10
3. Build the Configuration:
- Call the
build()method on theConfigBuilderto create your configuration. - Store the configuration in a static field for easy access within your mod's code.
public MyModConfig() {
ConfigBuilder builder = new ConfigBuilder("mymod", "mymod-config", ConfigExtension.YAML, ConfigType.CLIENT);
// ... define config entries
config = builder.build();
}
4. Access Config Values in Your Code:
- Use the
get()method to retrieve the current value of a config entry. - Use the
set()method to modify the value of a config entry.
// Example:
boolean debugEnabled = MyModConfig.debug.get(); // Retrieve the current value of the "debug" setting
if (debugEnabled) {
// Perform debug-related actions
}
MyModConfig.intEntry.set(25); // Set the value of the "intEntry" to 25
Config Type
ConfigType.CLIENT: Client-side configurations are specific to the client who has installed the mod. They are not shared with other players on the server.ConfigType.SERVER: Server-side configurations are specific to dedicated servers. They will not be used on single player worlds and are not synced to the players on the server.ConfigType.COMMON: Common configurations are shared between both clients and the server. They can be edited on the server by editing the config file directly and restarting the server or by editing the values using the in-game GUI and saving the changes.
Using Custom Data Types
- Use the
IConfigEntryTypeinterface to register custom data types with the YAML Config mod. - Implement a custom serializer for handling the serialization and deserialization of your custom data type.
Modpack Configuration
- If you are creating a modpack, you can use YAML Config to define the configuration settings for your modpack.
- Place the configuration file for your modpack in the "config" folder within your modpack's directory.
Examples
// Example: Basic client-side configuration
public class MyModConfig {
public static IConfig config;
public static IConfigEntry<Boolean> debug;
public static IConfigEntry<Integer> testInt;
public static void init() {
ConfigBuilder builder = new ConfigBuilder("mymod", "mymod-config", ConfigExtension.YAML, ConfigType.CLIENT);
debug = builder.defineBoolean("debug", false) // default false.
.withComments("Whether debug mode is enabled for the mod.");
testInt = builder.defineInteger("testInt", 10, 0, 100); // default 10, min 0 and max 100.
config = builder.build();
}
}
下载 YAML Config
下载 YAML Config
下载 YAML Config
下载 YAML Config
下载 YAML Config
下载 YAML Config
下载 YAML Config
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 YAML Config
下载 YAML Config
下载 YAML Config
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
模组
一个用于收集生物掉落物的多区块模组。
模组
显示你正在注视的方块的信息。(适用于 Minecraft 1.16+ 的 Hwyla/Waila 分支)
模组
在游戏画面角落显示附近世界地形、玩家、生物和实体的地图。可创建路径点,帮助你找到标记过的位置。
模组
查看物品与配方
模组
使用 JavaScript 编辑配方、添加自定义物品、编写世界事件!
模组
AE2:一款流行的自动化与存储模组

评论 0
登录后参与评分
还没有评论,来抢沙发吧