Common Trait Convention

About

This convention intended to bring the Ore Dictionary system from Forge to datapack's custom item. This is done by utilizing Item's custom nbt feature. We can insert any kind of nbt inside item which we can use other commands to check/look into it.

With that, we can create a unified lookup system that every datapacks can use to search for a specific item they want. You can then use the Common Trait Convention's provided syntax to construct a search function to find the item you need.

Example Usage

It can be hard to visualize how this convention would be useful in the real world, so we compile some useful usage that would not be possible without this convention.

  1. Suppose you added a custom furnace which let you smelt copper ore into ingots. With this convention, you can detect for any copper ore from any datapacks to smelt it.
  2. Suppose you added a fridge which only accept food items, with this convention you can detect for any food items even the custom ones from other datapack.
  3. Suppose you added a custom anvil which lets you repair tools straight from the material instead of the ingot, with this convention you can detect any kind of material from other datapacks even when the base material doesn't match.

Traits

Traits are behavior and properties that an object can have. By specifying these traits inside the item's nbt. Other datapacks will be able to refer to that item via traits instead of item id directly.

Trait is an array of strings and so will look like this in nbt (notice traits: [...]?)

/give @s diamond{ctc: {traits: ["some", "trait", "here"], id: "example", from: "convention:wiki"}}

Syntax

Common Trait Convention's syntax will be stored inside ctc nbt of item. insidectc contains: id, from and traits nbts.

  • id: internal id of your item, this should not be used outside of your datapack but should be unique within your datapack.
  • from: a namespace specifying which datapack is the item comes from.
  • traits: an array of traits that you can use to refer to items outside of your datapack.

We will assume the following syntax is the NBT structure of /give command

{
    ctc: {
        id: "my_copper_ore",
        from: "convention:wiki",
        traits: ["metal/copper", "block", "ore"]
    }
}

Let's look at traits nbt

  • metal/copper, this trait tells us that this item is copper.
  • block, this trait tells us that this item is a placeable block.
  • ore, this trait tells us that this item is an ore.

Slash Notation

In the above example, you will notice the use of / in metal/copper, this is used when the trait alone can be ambiguous. For example, what does trait orange mean? is it the color orange or the fruit orange?

In such case we'll use slash notation to separate them. color/orange and fruit/orange

Usage

To detect or check for trait items you just need to check for traits nbt of the item.

Detect if the player is holding a weapon

execute as @a if entity @s SelectedItem.tag.ctc{traits: ["tool/weapon"]} run ...

Detect if the container contains copper ore

execute if block ~ ~ ~ Items[].tag.ctc{traits: ["metal/copper", "ore"]} run ...

Detect if the container contains a placeable item

execute if block ~ ~ ~ Items[].tag.ctc{traits: ["block"]} run ...

Basic Traits

This is a provided list of traits that you can use, this doesn't mean you can't create new traits for your own use but if there is a trait that suits your need in this you should use it instead.

The list is split into multiple groups and you should not use traits from the same group twice.

Object Type Group

This trait represents the state of matter that this item holds.

TraitDescription
gasGaseous substance
liquidLiquid substance
blockPlaceable item
itemNormal minecraft item

Special Type Group

This trait represents common behavior from modded minecraft, this should help with integrating your pack into this convention.

This group is an exception to the rule above, you can use multiple traits from this group as much as you like.

TraitDescription
oreOre block that can usually be found in cave
seedItem that can be used to grow plant
flowerFlower item
grassBlock that can spread from one block to another
saplingBlock that can grow into tree
vegetableFood item that comes from seed
logItem that drops from tree
planksItem that come from processing log

Compression Group

This trait represents an item that can be combined to create a more compact version of itself and vice versa

For example:

  • redstone dust -> redstone block
  • ice -> packed ice
  • iron block -> iron ingot
TraitDescription
packedMost packed form of item, usually be a block form of this item
ingotNormal form of item, usually be an ingot form of this item
nuggetSmallest form of item, usually be a nugget form of this item

Edible Group

This trait represents an edible item that can be used by the player (drinking included)

TraitDescription
foodAll types of edible item

Armor Group

This trait represents an item that can be worn by players and other entities

TraitDescription
armorAll types of wearable item

Tool Sub-group

This trait use Slash Notation!

This trait represents an item that can be used to interact with the world.

TraitDescription
tool/miningThis item can be used to mine a stone block and other related blocks
tool/choppingThis item can be used to cut trees and wood material
tool/tillingThis item can be used to till the soil
tool/wateringThis item can be used to water the soil
tool/weaponThis item can be used to fight monsters and other players

Gem Sub-group

This trait use Slash Notation!

This trait represents an item that can be considered "gemstone"

TraitDescription
gem/diamondDiamond gemstone
gem/rubyRuby gemstone
gem/emeraldEmerald gemstone
gem/saphireSaphire gemstone

Metal Sub-group

This trait use Slash Notation!

This trait represents the metallic items that are often added by mods

TraitDescription
metal/ironItem that made up of iron
metal/goldItem that made up of gold
metal/copperItem that made up of copper
metal/aluminiumItem that made up of aluminium
metal/tinItem that made up of tin
metal/silverItem that made up of silver
metal/leadItem that made up of lead
metal/nickleItem that made up of nickle
metal/platinumItem that made up of platinum

Reference