简介
Item Registry (IR) 旨在提供关于 Minecraft 物品系统的可靠事实来源。这通过提供物品组件数据(例如堆叠数量和稀有度属性)以及各种已排序和过滤的物品列表来实现。一旦注册表被导入,就可以使用 /data get storage 等命令查询物品数据。
工作原理
IR 的核心仅包含一个名为 import_registry.mcfunction 的函数,执行时需传入两个参数:
- storage: 用于加载注册表的任意 NBT 存储
- path: 存储内任意的 NBT 路径
物品数据通常可通过两个复合标签访问:
- item_components: 存储物品属性,如堆叠数量、稀有度、翻译键
- item_lists: 以各种已排序和过滤的列表形式存储物品 ID
为确保 IR 始终处于最新状态,整个生成和发布流程完全自动化。系统会定期检查 Minecraft 版本。如果最新版本发生变化,IR 会在发布到 Modrinth 之前自动重新构建。有关此主题的更多信息,请参阅“生成器脚本”部分。
用法
首先,需要导入 IR。可以使用以下命令完成此操作:
/function item-registry:import_registry {storage:"foo:bar",path:"baz"}
注意:由于该函数体积庞大(超过 2000 行),建议仅在 #minecraft:load 等位置运行一次。
导入完成后,IR 即可提供服务。可以使用以下命令获取任意物品(例如 "minecraft:allium")的组件数据:
/data get storage foo:bar baz.item_components."minecraft:allium"
结果: {"max_stack_size": 64, "obtained_via": {"loot_table": 1b, "recipe": 0b, "gamemode_survival": 1b}, "rarity": "common", "translation_key": "block.minecraft.allium", "translations": {"en_us": "Allium"}}
此外,您还可以使用 /data modify 提取特定的物品属性。运行以下命令可将锻造模板的部分组件数据保存到临时位置:
/data modify storage foo:bar temp.vex_template_rarity set from storage foo:bar baz.item_components."minecraft:vex_armor_trim_smithing_template".rarity
由于 IR 还包含物品列表,这些列表也可以进行查询。使用以下命令获取 Minecraft 中所有物品的完整字母顺序排序列表:
/data get storage foo:bar baz.item_lists.sorted_alphabetically.entries
结果: ["minecraft:acacia_boat", "minecraft:acacia_button", "minecraft:acacia_chest_boat", "minecraft:acacia_door", "minecraft:acacia_fence", "minecraft:acacia_fence_gate", ...]
此外,IR 还为特定物品属性维护过滤列表,例如:
- filtered_by_stack_size_1
- filtered_by_stack_size_16
- filtered_by_stack_size_64
- filtered_by_loot_table_obtained
- filtered_by_loot_table_unobtained
- filtered_by_recipe_obtained
- filtered_by_recipe_unobtained
- filtered_by_survival_obtained
- filtered_by_survival_unobtained
- filtered_by_rarity_common
- filtered_by_rarity_uncommon
- filtered_by_rarity_rare
- filtered_by_rarity_epic
要获取前几个具有“uncommon”稀有度的物品,请运行以下命令:
/data get storage foo:bar baz.item_lists.filtered_by_rarity_uncommon.entries[0]
结果: "minecraft:angler_pottery_sherd"
/data get storage foo:bar baz.item_lists.filtered_by_rarity_uncommon.entries[1]
结果: "minecraft:archer_pottery_sherd"
/data get storage foo:bar baz.item_lists.filtered_by_rarity_uncommon.entries[2]
结果: "minecraft:arms_up_pottery_sherd"
示例
以下列表包含更多示例。IR 使用以下命令导入:
/function item-registry:import_registry {storage:"example:data",path:"ir"}
获取 "minecraft:cake" 的堆叠数量
/data get storage example:data ir.item_components."minecraft:cake".max_stack_size
结果: 1
获取 "minecraft:hopper" 的翻译键
/data get storage example:data ir.item_components."minecraft:hopper".translation_key
结果: "block.minecraft.hopper"
获取 "minecraft:experience_bottle" 的 en_us 翻译
/data get storage example:data ir.item_components."minecraft:experience_bottle".translations.en_us
结果: "Bottle o' "Enchanting"
获取列表 "filtered_by_stack_size_16" 的条目数(长度)
/data get storage example:data ir.item_lists.filtered_by_stack_size_16.count
结果: 49
结构
{
"item_components": {
"minecraft:lime_dye": {
"max_stack_size": 64,
"obtained_via": {
"loot_table": 0b,
"recipe": 1b,
"gamemode_survival": 1b
},
"rarity": "common",
"translation_key": "item.minecraft.lime_dye",
"translations": {
"en_us": "Lime Dye"
}
},
[...]
},
"item_lists": {
"sorted_alphabetically": {
"count": 1506,
"entries": [
"minecraft:acacia_boat",
"minecraft:acacia_button",
"minecraft:acacia_chest_boat",
"minecraft:acacia_door",
[...]
]
},
[...]
}
}
生成器脚本
IR 的生成器脚本实现了 import_registry.mcfunction 的完全自动化创建,从而将生成过程简化至无需人工干预的程度。该脚本使用 bash 编写,并随此数据包一同分发,以便 IR 的用户能够生成自己独立的导入函数副本。
在运行生成器脚本之前,请解压此数据包,并确保您的(基于 Linux 的)系统上安装了以下应用程序:
- bash
- curl
- java
- jq
- unzip
- wget
然后,导航至解压后的目录,并运行以下两条命令以启用执行权限,然后执行它:
$ chmod +x generateItemRegistry.sh
$ ./generateItemRegistry.sh
IR 的生成脚本应该是不言自明的,因为它会交互式地引导你完成整个生成过程。
Introduction
Item Registry (IR) aims to provide a reliable source of truth regarding Minecraft's item system. This is accomplished by providing item component data (e.g. stack size and rarity attributes) as well as various forms of sorted and filtered item lists. Once the registry has been imported, item data may be queried using commands such as /data get storage.
How it works
At its core, IR consists solely of a single function called import_registry.mcfunction, which takes two arguments when executed:
- storage: arbitrary NBT storage that the registry is loaded into
- path: arbitrary NBT path inside storage
Item data is generally accessible via two compound tags:
- item_components: stores item attributes such as stack size, rarity, translation key
- item_lists: stores item IDs in various sorted and filtered lists
To ensure that IR is always up-to-date, the entire generation and publishing process is fully automated. Minecraft releases are checked regularly. If the latest version has changed, IR is re-built automatically before being published to Modrinth. See the "Generator Script" section for more information regarding this topic.
Usage
First of all, IR needs to be imported. This can be accomplished using the following command:
/function item-registry:import_registry {storage:"foo:bar",path:"baz"}
Note: Since this function's size is tremendous (2000+ lines), it is recommended to only run it once, e.g. at #minecraft:load.
After the import has finished, IR is ready to serve data. The following command may be used to fetch component data of an arbitrary item, such as "minecraft:allium":
/data get storage foo:bar baz.item_components."minecraft:allium"
Result: {"max_stack_size": 64, "obtained_via": {"loot_table": 1b, "recipe": 0b, "gamemode_survival": 1b}, "rarity": "common", "translation_key": "block.minecraft.allium", "translations": {"en_us": "Allium"}}
Furthermore, you are also able to extract specific item attributes using /data modify. By running the following command, some component data of a smithing template is saved to a temporary location:
/data modify storage foo:bar temp.vex_template_rarity set from storage foo:bar baz.item_components."minecraft:vex_armor_trim_smithing_template".rarity
As IR also contains item lists, these may be queried too. Use this command to obtain a complete, alphabetically sorted list of all items in Minecraft:
/data get storage foo:bar baz.item_lists.sorted_alphabetically.entries
Result: ["minecraft:acacia_boat", "minecraft:acacia_button", "minecraft:acacia_chest_boat", "minecraft:acacia_door", "minecraft:acacia_fence", "minecraft:acacia_fence_gate", ...]
In addition, IR also maintains filtered lists for specific item attributes, such as:
- filtered_by_stack_size_1
- filtered_by_stack_size_16
- filtered_by_stack_size_64
- filtered_by_loot_table_obtained
- filtered_by_loot_table_unobtained
- filtered_by_recipe_obtained
- filtered_by_recipe_unobtained
- filtered_by_survival_obtained
- filtered_by_survival_unobtained
- filtered_by_rarity_common
- filtered_by_rarity_uncommon
- filtered_by_rarity_rare
- filtered_by_rarity_epic
To retrieve the first few items with "uncommon" rarity, run the following commands:
/data get storage foo:bar baz.item_lists.filtered_by_rarity_uncommon.entries[0]
Result: "minecraft:angler_pottery_sherd"
/data get storage foo:bar baz.item_lists.filtered_by_rarity_uncommon.entries[1]
Result: "minecraft:archer_pottery_sherd"
/data get storage foo:bar baz.item_lists.filtered_by_rarity_uncommon.entries[2]
Result: "minecraft:arms_up_pottery_sherd"
Examples
The following list contains a few more examples. IR was imported using:
/function item-registry:import_registry {storage:"example:data",path:"ir"}
Get stack size of "minecraft:cake"
/data get storage example:data ir.item_components."minecraft:cake".max_stack_size
Result: 1
Get translation key of "minecraft:hopper"
/data get storage example:data ir.item_components."minecraft:hopper".translation_key
Result: "block.minecraft.hopper"
Get en_us translation of "minecraft:experience_bottle"
/data get storage example:data ir.item_components."minecraft:experience_bottle".translations.en_us
Result: "Bottle o' "Enchanting"
Get number of entries (length) of list "filtered_by_stack_size_16"
/data get storage example:data ir.item_lists.filtered_by_stack_size_16.count
Result: 49
Structure
{
"item_components": {
"minecraft:lime_dye": {
"max_stack_size": 64,
"obtained_via": {
"loot_table": 0b,
"recipe": 1b,
"gamemode_survival": 1b
},
"rarity": "common",
"translation_key": "item.minecraft.lime_dye",
"translations": {
"en_us": "Lime Dye"
}
},
[...]
},
"item_lists": {
"sorted_alphabetically": {
"count": 1506,
"entries": [
"minecraft:acacia_boat",
"minecraft:acacia_button",
"minecraft:acacia_chest_boat",
"minecraft:acacia_door",
[...]
]
},
[...]
}
}
Generator script
IR's generator script enables fully automated creation of import_registry.mcfunction and therefore streamlines the generation process to the point where no human intervention is necessary. It is written in bash and is shipped directly with this data pack to enable IR's users to generate their own independent copy of the import function.
Before running the generator script, unzip this data pack and make sure the following applications are installed on your (Linux-based) system:
- bash
- curl
- java
- jq
- unzip
- wget
Next, navigate to the extracted directory and run the following two commands to enable execution permissions and then execute it:
$ chmod +x generateItemRegistry.sh
$ ./generateItemRegistry.sh
IR's generator script should be self-explanatory as it interactively guides you through the whole generation process.
评论 0
登录后参与评分
还没有评论,来抢沙发吧