Link Search Menu Expand Document (external link)

Attributes

This page lists the most commonly used attributes currently supported by Spyglass.

canonical

Special attribute that marks a union member as the canonical member. If a union has a canonical member, trying to read that union will always expect the canonical member.

Syntax
type RGB = (
	#[canonical] int |
	[float] @ 3 |
)

color

Represents a color. This attribute has one required string option which is the format.

Syntax
#[color="dec_rgb"] [float] @ 3

#[color="composite_rgb"] int

#[color="hex_rgb"] string

command

Specifies that the string contains a command. This attribute has several options.

Syntax
#[command(slash="allowed")] string

#[command(slash="allowed",empty="allowed",max_length=32500)] string

#[command(macro="implicit")] string

deprecated

Marks the field as deprecated. Editors may strikethrough the field when used. It takes as argument a string specifying the version that it was deprecated in.

Syntax
#[deprecated="1.16"]
value?: Text,

dispatcher_key

Specifies that a string should match a key of a given dispatcher.

Syntax
#[dispatcher_key="mcdoc:custom_data"] string

divisible_by

Specifies that a numeric value must be divisible by a given number

Syntax
#[divisible_by=16] int

entity

Represents a selector, player name or uuid. Not to be confused with score_holder This attribute has two options:

  • amount: either multiple or single

  • type: either entities or players

Syntax
#[entity(amount="single",type="entities")] string

game_rule

Specifies that a string should contain the name of a game rule. This attribute has one option:

  • type: either boolean or int

Syntax
#[game_rule(type="int")] string

id

Specifies that a string should contain a resource location. It has a required option registry which can either be written as a shortform, or with more options:

  • registry: any registry or pack category like item, block, loot_table, etc.

  • tags: one of allowed, implicit, or required

Syntax
#[id="item"] string

#[id(registry="item",tags="allowed")] string

match_regex

Specifies that a string needs to match a given regex pattern. Not to be confused with regex_pattern

Syntax
#[match_regex="^[a-z_]+$"] string

nbt

A string containing SNBT. It has one option which is the type that the stringified SNBT needs to match.

Syntax
#[nbt=ItemStack] string

nbt_path

A string containing an NBT path.

Syntax
#[nbt_path] string

objective

A string containing a scoreboard objective name.

Syntax
#[objective] string

regex_pattern

A string containing a regex pattern. Not to be confused with match_regex.

Syntax
#[regex_pattern] string

score_holder

Allows the * wildcard, entity selectors and player names. Not to be confused with entity.

Syntax
#[score_holder] string

since

Makes the field or union member only available starting at a given version. Only release versions (no snapshots) are allowed. See also until.

Syntax
struct Example1 {
   #[since="1.19"]
   entity: string,
}

type Example2 = (
   string |
   #[since="1.20.5"] int |
)
❌ Invalid
struct Example {
   entity: #[since="1.19"] string,
}

tag

A string containing a command tag name (obtained with /tag or in the Tags entity field).

Syntax
#[tag] string

team

A string containing a team name.

Syntax
#[team] string

text_component

A string containing stringified JSON representing a text component. Note that in versions since 1.21.5, you should use the ::java::util::text::Text type instead of stringified JSON.

Syntax
#[text_component] string

until

Makes the field or union member unavailable starting at a given version. Only release versions (no snapshots) are allowed. Note that the given version is not included in the range of versions where this field or member is accepted. See also since.

Syntax
struct Example1 {
   #[until="1.19"]
   entity: string,
}

type Example2 = (
   string |
   #[until="1.20.5"] int |
)
❌ Invalid
struct Example {
   entity: #[until="1.19"] string,
}