MaterialSet

class MaterialSet(materials: Collection<Material> = emptySet(), tags: Collection<Tag<Material>> = emptySet()) : AbstractSet<Material>

An immutable set of materials that remembers which of them were given as single materials and which through tags, so that tags stay tags when the set is written to a config file.

The set contains the materials and the values of all tags. The tags are resolved when the set is created: a set created again later, e.g. when the config is reloaded, includes the blocks that new Minecraft versions or datapacks add to a tag.

Equality follows the Set contract: a MaterialSet equals every set with the same materials. Tags are not part of equality, so a set with the tag #minecraft:logs equals a set that lists all logs as single materials.

The + and - operators return a new MaterialSet and keep its tags:

  • + adds materials to materials and tags to tags. Adding another MaterialSet adds its materials and tags.

  • - removes materials from materials and tags (matched by key) from tags. A material that is not part of the set is ignored. Removing a material that one of the tags includes throws an IllegalArgumentException, because the result could not keep the tag; remove the tag instead. Removing another MaterialSet removes its tags first, then its materials.

Parameters

materials

The single materials of this set

tags

The tags of this set. Of several tags with the same key, only the first is kept.

Throws

if materials contains legacy materials

Constructors

Link copied to clipboard
constructor(materials: Collection<Material> = emptySet(), tags: Collection<Tag<Material>> = emptySet())

Properties

Link copied to clipboard
val materials: Set<Material>

The single materials of this set, without the values of its tags.

Link copied to clipboard
open override val size: Int
Link copied to clipboard
val tags: Set<Tag<Material>>

The tags of this set in the order they were given, at most one per key.

Functions

Link copied to clipboard
open operator override fun contains(element: Material): Boolean
Link copied to clipboard
open override fun containsAll(elements: Collection<Material>): Boolean
Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override fun isEmpty(): Boolean
Link copied to clipboard
open operator override fun iterator(): Iterator<Material>
Link copied to clipboard
operator fun minus(elements: Array<out Material>): MaterialSet
operator fun minus(elements: Sequence<Material>): MaterialSet

A set without elements. Elements that are not part of this set are ignored.

operator fun minus(elements: Iterable<Material>): MaterialSet

A set without elements. Elements that are not part of this set are ignored. If elements is a MaterialSet, its tags are removed from the tags of this set first, then its materials.

operator fun minus(element: Material): MaterialSet

A set without element. Nothing changes if element is not part of this set.

operator fun minus(tag: Tag<Material>): MaterialSet

A set without the tag with the key of tag. Nothing changes if no such tag is part of this set.

Link copied to clipboard
operator fun plus(elements: Array<out Material>): MaterialSet
operator fun plus(elements: Sequence<Material>): MaterialSet

A set with elements added to the materials of this set.

operator fun plus(elements: Iterable<Material>): MaterialSet

A set with elements added to the materials of this set. If elements is a MaterialSet, its materials are added to the materials and its tags to the tags of this set.

operator fun plus(element: Material): MaterialSet

A set with element added to the materials of this set.

operator fun plus(tag: Tag<Material>): MaterialSet

A set with tag added to the tags of this set. Nothing changes if a tag with the same key is part of it.

Link copied to clipboard
fun tagsContaining(material: Material): Set<Tag<Material>>

The tags of this set that contain material, in the order of tags. Empty if material is not part of any tag, even if it is one of the materials.

Link copied to clipboard
open override fun toString(): String

Shows the materials and tags of this set, e.g. MaterialSet(materials=[minecraft:stone], tags=[#minecraft:logs]).