▶️ ЗАБЕРИ СВОИ 8 ПОДАРКОВ 🎁 ПРИ СОЗДАНИИ СВОЕГО МАЙНКРАФТ СЕРВЕРА
Датапаки/Item Registry
Item Registry

Item Registry

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

89
0

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.

Совместимость

Minecraft: Java Edition

26w14a26.2.x26.1.x1.21.x

Платформы

Поддерживаемые окружения

Клиент и сервер

Создатели

Детали

Лицензия:MIT
Опубликован:2 недели назад
Обновлён:4 дня назад
Главная