Unruled API
允许创建新的游戏规则形式,突破原版整数和布尔值的限制。
本模组使开发者能够轻松创建新的浮点数、长整型、双精度浮点数、字符串、文本、枚举驱动、实体选择器甚至注册表条目的游戏规则,使用各自的构建器即可实现,所有构建器均可通过 com.nerjal.unruled_api.UnruledApi 类的静态方法获取。
它还提供了在注册新游戏规则时添加值验证器的功能,从而可以限制游戏规则有效值的范围。例如,它可以用于仅允许整型游戏规则中的奇数值。
此外,本模组还添加了按维度(dimension)的游戏规则覆盖!这些覆盖将在其对应的严格维度中生效(前提是查询正确)。 有关详细信息,请参阅 游戏规则覆盖。
游戏规则注册
示例:
import com.nerjal.unruled_api.UnruledApi;
public class MyClass {
private static final int STRING_RULE_MAX_LENGTH = 24;
public void gamerulesRegistration() {
var myFloatingRule = UnruledApi.floatRuleBuilder(category, 1.5) // 接受类别和初始值作为参数
// 类别决定了在世界创建屏幕中的位置
.register("mymod:my_gamerule"); // 游戏规则注册始终需要游戏规则的 ID
// ID 也决定了游戏规则的翻译名称
var myStringRule = new StringRule.Builder(category, "initial value", STRING_RULE_MAX_LENGTH)
// 使用 UnruledApi 方法或直接创建构建器的结果相同,且参数一致。
// 但是请注意,在某些情况下,强烈建议使用指定的构建器,如字符串
// 规则、枚举和动态注册表条目规则,因为它们对其值和
// 命令处理有更具体的处理逻辑。
.register("mymod:my_other_gamerule");
}
}
此外,为了方便起见,还添加了快速创建和注册的方法:
import com.nerjal.unruled_api.UnruledApi;
public static void quickGamerulesRegistration() {
var myLongRule = UnruledApi.registerLong(Identifier.of("mymod:my_long_rule"), category, 25L);
// 快速注册方法始终遵循相同的参数顺序:名称、类别、初始值、特定于游戏规则类型的参数
// 对于枚举规则除外,其枚举类位于初始值之前
var myEnumRule = UnruledApi.registerEnumRule(Identifier.of("mymod:my_enum_rule"), category, MyEnum.FIRST, MyEnum.class);
}
enum MyEnum {
FIRST,
SECOND,
THIRD
}
为了保持一致性,还创建了用于快速注册原版类型游戏规则的方法。
import com.nerjal.unruled_api.UnruledApi;
public static void registerBasicRules() {
UnruledApi.registerInteger("my_int_rule", category, 5);
UnruledApi.registerBoolean("my_bool_rule", category, false);
}
您还可以使用同一类的方法检索它们的值
自版本 2.0(适用于 Minecraft 1.21.11 及更高版本)发布以来,此方法已过时。
请直接使用游戏规则方法,因为现在由游戏代码定义的方式已改变。
public long getMyLongGamerules(ServerWorld dimension) { // ServerWorld 是 Yarn 映射类。使用 Mojmap 时可能是 Level 或 ServerLevel
return UnruledApi.getLong(dimension.getGameRules(), myLongGamerule);
}
public Block getMyBlockRule(ServerWorld dimension) {
// 查询注册表条目规则会返回注册表条目的实际值,因为它只能在存在于注册表中时设置
return UnruledApi.getRegistryEntry(dimension.getGameRules(), myBlockRegistryEntryRule);
}
命令调整
在原版 Minecraft 中使用游戏规则的平均体验相当糟糕。 浏览长长的名称列表,努力记住你需要的规则名称, 或者更糟的是,搜索一个假设存在的规则,这可能会非常令人烦恼。
因此,Unruled API 旨在通过允许您 按类别 导航同一个列表来稍微减轻这一负担!
因此,您可以在命令中添加类别名称或完整 ID(均为全大写),随后 列出的内容将仅包含相应类别的规则。
例如,输入 /gamerule CHAT 后,游戏只会根据世界创建菜单的列表为您建议
聊天 类别内的规则。
这也适用于所有模组游戏规则和类别,以及来自任何模组的游戏规则类型。
/gamerule [<category NAME or FULL ID>] <gamerule name or ID> [<value>]
游戏规则覆盖
游戏规则覆盖是按维度设置的。它们允许玩家在所需维度中将特定规则设置为特定值,
全部通过 gamerule-override 命令完成。
此命令有许多用途:
- 仅使用
gamerule-override且不带任何参数,可获取当前维度中所有现有覆盖规则的列表。 gamerule-override <dimension id>可获取指定维度中所有现有覆盖规则的列表。gamerule-override get <gamerule id>可查询当前维度中指定游戏规则的潜在覆盖值。gamerule-override set <gamerule id> <value>可在当前维度中将指定游戏规则的覆盖值设置为给定值。gamerule-override unset <gamerule id>可移除当前维度中指定游戏规则已设置的覆盖值。gamerule-override in <dimension id> get <gamerule id>可查询指定维度中特定游戏规则的潜在覆盖值。gamerule-override in <dimension id> set <gamerule id> <value>可在指定维度中将指定游戏规则的覆盖值设置为给定值。gamerule-override in <dimension id> unset <gamerule id>可移除指定维度中指定游戏规则已设置的覆盖值。
游戏规则覆盖规则存储在维度的数据文件夹中,以 gamerules.dat 文件的形式保存。在服务器离线或未加载世界时删除该文件,将直接清除该维度的所有覆盖规则。
此外,为方便起见,在所有情况下,get、set 和 unset 命令均支持按类别进行过滤,以便更便捷地使用。
因此,你可以按如下方式使用命令:
/gamerule-override in <dimension id> set [<category NAME or FULL ID>] <gamerule name or id> <value>
可配置的默认值
此功能对整合包创作者尤为相关,它允许在世界创建时使用自定义值作为游戏规则的默认值。
要设置这些值,你只需创建一个 config/default_gamerules.json 文件,并为每个希望添加默认值的游戏规则设置一个键值对,其中值为所需的字符串形式的新值。(由于 Mojang 代码在 JSON 解析方面的限制,仅接受字符串值,其他类型将被忽略)
示例:
{
"doDaylightCycle": "false",
"mobGriefing": "false"
}
显然,这也同样适用于模组添加的游戏规则和游戏规则类型!
自定义游戏规则类别
自 1.21.11 版本起,游戏规则类别已成为一种注册表(Registry)。以下内容仅适用于此版本之前的游戏版本
开发者可以轻松注册新的自定义游戏规则类别,这些类别将直接添加到类别枚举中!
但你需要在游戏加载过程的早期完成这一操作,即在 gamerules 类被加载之前。
这可以通过 Fabric 的 preLaunch 入口点、(Neo)Forge 中初始化你的 @Mod 类时,或在任意加载器中通过 mixin 配置插件来实现。
你只需向 UnruledEarlyUtils.CATEGORY_PROVIDERS 集合中添加一个 CategoryProvider 实现即可。
CategoryProvider 接口是一个类似 String 供应器的类,允许在创建匹配的类别时可选地实现一个类别消费者。提供的字符串将用作类别名称,但不允许重复条目(即如果两个模组都想添加相同的类别,只会创建一个,但两个提供者都会接收到它)。
在你的项目中使用
你可以使用 Modrinth Maven 将此模组集成到你的项目中。请务必阅读 官方文档。
添加 Modrinth Maven 仓库
repositories {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
}
}
导入模组
Loom 示例:
dependencies {
// 使用 modApi 允许你的项目的依赖项也默认导入依赖
modApi "maven.modrinth:unruled-api:${project.unruled_version}"
}
(neo)ForgeGradle 示例:
dependencies {
implementation "maven.modrinth:unruled-api:${project.unruled_version}"
}
出于版权原因,我们要求你 不要 将此模组打包(如 JiJ、jar-in-a-jar、shadow 等)到你自己的模组中。感谢你的理解。
Unruled API
Allows to create new form of gamerules, beyond the restrictive vanilla integers and booleans.
This mod enables developers to easily create new floating, long, double, string, text, enum-driven,
entity selector and even registry-entry gamerules, using their respective builders,
all available from the com.nerjal.unruled_api.UnruledApi class's static methods.
It also provides means to add value validators alongside registering new gamerules, which in turn allows to restrict the range of valid values for gamerules. For instance, it can be used to only allow odd values in an integer gamerule.
Additionally, this mod also adds per-dimension gamerule overrides! These are applied in their strict dimension (provided they are queried correctly). See gamerules overrides for more details about it.
Gamerules registration
Example:
import com.nerjal.unruled_api.UnruledApi;
public class MyClass {
private static final int STRING_RULE_MAX_LENGTH = 24;
public void gamerulesRegistration() {
var myFloatingRule = UnruledApi.floatRuleBuilder(category, 1.5) // takes the category and the initial value as arguments
// the category determines where in the world creation screen will it be placed
.register("mymod:my_gamerule"); // gamerule registration always takes the gamerule's ID
// the ID also determines the translated name of the gamerule
var myStringRule = new StringRule.Builder(category, "initial value", STRING_RULE_MAX_LENGTH)
// using the UnruledApi methods or directly creating the builder has the same result, and arguments are the same.
// however, mind that in some cases, it is strongly recommended to use the specified builders such as for string
// rules, enum, and dynamic registry entry rules, as they have a more specific processing of their values and
// command handling.
.register("mymod:my_other_gamerule");
}
}
Additionally, quick creation and registration methods have been added for your convenience
import com.nerjal.unruled_api.UnruledApi;
public static void quickGamerulesRegistration() {
var myLongRule = UnruledApi.registerLong(Identifier.of("mymod:my_long_rule"), category, 25L);
// Quick registration methods always follow the same parameter order: name, category, initial value, gamerule-type specific arguments
// Except for enum rules, for which the enum class goes before the initial value
var myEnumRule = UnruledApi.registerEnumRule(Identifier.of("mymod:my_enum_rule"), category, MyEnum.FIRST, MyEnum.class);
}
enum MyEnum {
FIRST,
SECOND,
THIRD
}
For consistency, methods have also been created to allow quickly register vanilla-type gamerules.
import com.nerjal.unruled_api.UnruledApi;
public static void registerBasicRules() {
UnruledApi.registerInteger("my_int_rule", category, 5);
UnruledApi.registerBoolean("my_bool_rule", category, false);
}
You can also retrieve their values using the same class's methods
This has become outdated since release 2.0 (for Minecraft 1.21.11 and later).
Please use the gamerule methods directly as now meant by the game code.
public long getMyLongGamerules(ServerWorld dimension) { // ServerWorld is a Yarn mapping class. Might be Level or ServerLevel with Mojmap
return UnruledApi.getLong(dimension.getGameRules(), myLongGamerule);
}
public Block getMyBlockRule(ServerWorld dimension) {
// querying a registry entry rule returns the registry entry's very value, as it can only be set if it exists in the registry
return UnruledApi.getRegistryEntry(dimension.getGameRules(), myBlockRegistryEntryRule);
}
Command Tweaks
The average experience of using gamerules in vanilla minecraft is pretty poor. Navigating a long list of names, trying to remember the one of the rule you need, or even worse, searching for a hypothetic one, can be pretty annoying.
Thus, Unruled API aims to alleviate that burden ever so slightly, by allowing you to navigate the same list by category!
Hence, you can now add the category name or full ID (both in full caps) in the command and the following list will only contain rules in the appropriate category.
E.g. /gamerule CHAT will then have your game suggest you only the rules inside the
chat category, according to the world creation menu listing.
This also applies to all modded gamerules and categories, as well as modded gamerule types from any and all mod.
/gamerule [<category NAME or FULL ID>] <gamerule name or ID> [<value>]
Gamerules Overrides
Gamerules overrides are set per dimension. They allow players to set specific rules to specific values
in the wanted dimension, all via the gamerule-override command.
This command has many uses:
gamerule-overridealone and with no arguments allows you to get a list of existing overrides in the current dimension.gamerule-override <dimension id>allows you to get a list of existing overrides in the specified dimension.gamerule-override get <gamerule id>allows you to query a potential override for the specified gamerule in the current dimension.gamerule-override set <gamerule id> <value>allows you to set an override for the specified gamerule to the given value in the current dimension.gamerule-override unset <gamerule id>allows you to remove a set override for the specified gamerule in the current dimension.gamerule-override in <dimension id> get <gamerule id>allows you to query a potential override for the specific gamerule in the given dimension.gamerule-override in <dimension id> set <gamerule id> <value>allows you to set an override for the specified gamerule to the given value in the provided dimension.gamerule-override in <dimension id> unset <gamerule id>allows you to remove a set override for the specified gamerule in the provided dimension.
Gamerule overrides are stored in the dimension's data folder, as the gamerules.dat file.
Removing it while the server is offline/world is not being played will simply remove all overrides for the dimension.
Additionally, for your convenience, the get, set and unset in all cases also
support the per-category filtering, for easier usage.
You can thus use the command as follows:
/gamerule-override in <dimension id> set [<category NAME or FULL ID>] <gamerule name or id> <value>
Configurable Default Values
Especially relevant for modpack creators, this feature allows to set custom values to be used as default gamerule values upon world creation.
In order to set them, you only need to create a config/default_gamerules.json file, and for each gamerule you want
to add a default value for, set a key-value pair with the wanted new value, set as a string. (due to limitations in
the mojang code for easy JSON-parsing, only string values are accepted, anything else will simply be ignored)
Example:
{
"doDaylightCycle": "false",
"mobGriefing": "false"
}
Obviously, this works just as well with modded gamerules and gamerule types!
Custom Gamerule Categories
As of 1.21.11, gamerule categories are now a registry. The following is only relevant to game versions prior to this
Developers can easily register new custom gamerule categories, that will be added straight to the category enum! However, you do need it to be done early in the game load process, i.e. before the gamerules class gets loaded.
This can be done on Fabric with a preLaunch entrypoint, on (Neo)Forge upon initializing your @Mod class,
or on any launcher from your mixin config plugin.
You only need to add a CategoryProvider implementation to the UnruledEarlyUtils.CATEGORY_PROVIDERS set.
The CategoryProvider interface is a String supplier-like class, that allows for an optional implementation of a
category consumer upon creation of the matching category. The provided String will be set as the category name, but
will not allow for duplicate entries (i.e. if two mods want to add a same category, only one will be created, but both
providers will receive it as well)
How to use in your project
You can implement this mod in your project using the Modrinth maven. Don't hesitate to read the official documentation.
Add the Modrinth maven repository
repositories {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
}
}
Import the mod
loom example:
dependencies {
// using modApi allows your project's dependents to also import dependencies by default
modApi "maven.modrinth:unruled-api:${project.unruled_version}"
}
(neo)forgeGradle example:
dependencies {
implementation "maven.modrinth:unruled-api:${project.unruled_version}"
}
For copyright reasons, we require you to not include (JiJ, jar-in-a-jar, shadow, etc) this mod inside of your own. Thank you for your comprehension.
下载 Unruled API
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Unruled API
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Unruled API
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Unruled API
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Unruled API
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Unruled API
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Unruled API
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Unruled API
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Unruled API
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Unruled API
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
真正的日光周期覆盖补丁
Minecraft 26.2 补丁
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
模组
一个用于收集生物掉落物的多区块模组。
模组
显示你正在注视的方块的信息。(适用于 Minecraft 1.16+ 的 Hwyla/Waila 分支)
模组
在游戏画面角落显示附近世界地形、玩家、生物和实体的地图。可创建路径点,帮助你找到标记过的位置。
模组
使用 JavaScript 编辑配方、添加自定义物品、编写世界事件!
模组
查看物品与配方
模组
AE2:一款流行的自动化与存储模组
评论 0
登录后参与评分
还没有评论,来抢沙发吧