跳到正文

Item Registry

作者:Tapir0

Provides a command/function-accessible way to query items and certain item attributes.

收藏

介绍

中文介绍正在准备中,下面暂时显示原文。

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:


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":

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:


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:

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:


**Result:** _"minecraft:angler_pottery_sherd"_

Result: _”minecraft:archer_pottery_sherd”_


**Result:** _"minecraft:arms_up_pottery_sherd"_

## Examples

The following list contains a few more examples. IR was imported using:

Get stack size of “minecraft:cake”


**Result:** _1_

Get translation key of "minecraft:hopper"

Result: _”block.minecraft.hopper”_

Get en_us translation of “minecraft:experience_bottle”


**Result:** _"Bottle o' "Enchanting"_

Get number of entries (length) of list "filtered_by_stack_size_16"

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.

常见问题

Item Registry 支持哪些 Minecraft 版本?

Item Registry 支持 Minecraft Java 版 1.21–26.3,共 17 个版本。下载时注意选择和你游戏版本一致的文件。

Item Registry 怎么安装?

新建世界时在「数据包」里把下载的 .zip 拖进去;已有的存档,把文件放进存档目录下的 datapacks 文件夹,进游戏输入 /reload 即可生效。服务器同样放在世界目录的 datapacks 里。

评论

登录后评论和评分

Tapir0 的其他作品

查看全部 →