Skip to content

Supersede materials.json with tags.json on 1.21.8 #55

@extremeheat

Description

@extremeheat

We have a problem with current materials.json generation,

Written by gemini:

The Problem with materials.json

The materials.json file you're working with is based on an old system that Minecraft used to define the properties of blocks. In older versions of the game, each block was assigned a "material" that determined its properties, such as its hardness, the tool required to break it, and so on.

However, this system was replaced in Minecraft Java Edition 1.13 with a more flexible and powerful system called block and item tags. Tags allow developers to group blocks and items together based on shared properties, making it much easier to manage and extend the game's data.

The materials.json file you've provided is a remnant of this old system, and it's no longer a reliable source of information for modern versions of Minecraft. As you've noted, the data is outdated and doesn't accurately reflect the properties of blocks in the latest versions of the game.

The Solution: Block and Item Tags

The solution to this problem is to stop relying on materials.json and instead use the modern tag system. Block and item tags are collections of block and item IDs that share a common property. For example, there are tags for:

  • Tool types: mineable/pickaxe, mineable/axe, mineable/shovel, mineable/hoe
  • Tool tiers: needs_stone_tool, needs_iron_tool, needs_diamond_tool
  • Material types: planks, logs, stone_bricks
  • And many more!

By using tags, you can easily check if a block has a certain property. For example, to determine if a block can be mined with a pickaxe, you can check if it has the mineable/pickaxe tag.

How to Use Tags

Here's an example of how you can use tags to get the properties of a block:

  1. Get the block's tags: You'll need a data source that provides the tags for each block. The minecraft-data repository should have this information in the blocks.json file for each version of the game.
  2. Check for relevant tags: To determine the properties of a block, you can check if it has certain tags. For example, to find out what tool is required to mine a block, you can check for the following tags:
    • mineable/pickaxe
    • mineable/axe
    • mineable/shovel
    • mineable/hoe
  3. Check for tool tier tags: To determine the required tool tier for mining a block, you can check for the following tags:
    • needs_stone_tool
    • needs_iron_tool
    • needs_diamond_tool

By using tags in this way, you can create a much more accurate and up-to-date system for getting block properties.

Generating the New Data

To replace materials.json, you'll need to generate a new file that contains the tag information for each block. There are a few ways you can do this:

  • Use the vanilla server data generator: java -DbundlerMainClass="net.minecraft.data.Main" -jar minecraft_server.jar and parse the tags
  • Use a custom coded Java extractor: A new Java coded generator (here) in PrismarineJS/minecraft-data-generator

Conclusion

The materials.json file is an outdated and unreliable source of information for modern versions of Minecraft. To fix this, you should switch to using the modern block and item tag system. By using tags, you can create a much more accurate and up-to-date system for getting block properties.


So, for 1.21.8, the latest version, let's add a data generator that is extracting a tags.json that has all the tags (we can keep the existing materials.json for now while we figure out what to do with it):

Proposed Schema:

{
  "block": { // no minecraft-prefix for tag type
    "minecraft:planks": [
      "minecraft:oak_planks",
      "minecraft:spruce_planks",
      "minecraft:birch_planks",
      "minecraft:jungle_planks",
      "minecraft:acacia_planks",
      "minecraft:dark_oak_planks"
    ],
    "minecraft:mineable/axe": [
      "#minecraft:planks", // vanilla's hash prefix to ref another tag
      "#minecraft:logs",
      "minecraft:crafting_table"
    ]
  },
  "item": {
    "minecraft:coals": [
      "minecraft:coal",
      "minecraft:charcoal"
    ],
    "minecraft:fishes": [
      "minecraft:cod",
      "minecraft:salmon",
      "minecraft:pufferfish",
      "minecraft:tropical_fish"
    ]
  },
  "fluid": {
    "minecraft:water": [
      "minecraft:water",
      "minecraft:flowing_water"
    ]
  },
  "entity_type": {
    "minecraft:skeletons": [
      "minecraft:skeleton",
      "minecraft:stray",
      "minecraft:wither_skeleton"
    ]
  }
}

Related:

We can solve this 2 ways:

  1. a post processing nodejs script that runs mc server's data generator class after the initial data generators with compiled modded server jar over cli
    • (or, an option is to trigger data generator run within our mod, then it's processed by a node script after)
  2. we write a custom extractor that hooks into the registries and gets the data with the normal extraction procedure

You can try one or the other then switch strategies if you get stuck

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions