Перейти к основному содержанию

TagRegistry

since: 2.0.4b38

Tag system allows you to assign tags to objects and put them into groups for further object search.

Learn how to use

Use constant to define group in global scope to reuse/export it:

const ENCHANT_TAG_GROUP = TagRegistry.getOrCreateGroup("enchant");

BlockRegistry.registerDropFunctionForID(BlockID.tin_ore, function(coords, id, data, level, enchant, item, region) {
if (level >= 2) {
// Check item for "smelting" tag, which can be set to obtain smelted result
if (ENCHANT_TAG_GROUP.getTags(item).contains("smelting")) {
ToolAPI.dropOreExp(coords, 2, 2, enchant.experience, blockSource);
return [[ItemID.tin_ingot, 1, 0]];
} else {
// Do default logic otherwise (if no tag has been set)
return [[BlockID.tin_ore, 1, 0]]
}
}
return [];
}, 2);

// Register tag factory, which are called to obtain tags every iteration
ENCHANT_TAG_GROUP.addTagFactory(function(object, tags) {
// In case if our object is item-like and equals smelting tool
if (object && object.id == ItemID.smelting_multitool) {
// Smelt our BlockID.tin_ore and a few vanilla ones
tags.add("smelting");
}
});
Learn how to use

Obtain tag group automatically via registry:

BlockRegistry.registerDropFunctionForID(BlockID.tin_ore, function(coords, id, data, level, enchant, item, region) {
if (level >= 2) {
// Check item for "smelting" tag, which can be set to obtain smelted result
if (TagRegistry.getTagsFor("enchant", item).contains("smelting")) {
ToolAPI.dropOreExp(coords, 2, 2, enchant.experience, blockSource);
return [[ItemID.tin_ingot, 1, 0]];
} else {
// Do default logic otherwise (if no tag has been set)
return [[BlockID.tin_ore, 1, 0]]
}
}
return [];
}, 2);

// Register tag factory, which are called to obtain tags every iteration
TagRegistry.addTagFactory("enchant", function(object, tags) {
// In case if our object is item-like and equals smelting tool
if (object && object.id == ItemID.smelting_multitool) {
// Smelt our BlockID.tin_ore and a few vanilla ones
tags.add("smelting");
}
});

Index

Interfaces

TagFactory

  • TagFactory(obj: T, tags: Collection<string>): void
  • Parameters

    • obj: T

      object from group

    • tags: Collection<string>

      changeable tags collection

    Returns void

TagGroup

TagGroup<T>:

Type parameters

  • T = any

readonlyname

name: string

addCommonObject

  • addCommonObject(obj: T, ...tags: string[]): void
  • Appends object to group to use in iterator and filtering functions like TagGroup.getAllWhere, etc.


    Parameters

    • obj: T
    • rest...tags: string[]

      primary tags to be added for object

    Returns void

addTagFactory

  • Tag factory determines additional tags, which should be added for specific object in group.


    Parameters

    Returns void

addTags

  • Fetches object tags and appends it to a present collection in fixed order: primary tags added via TagGroup.addTags, serialized tags from object _tags property, tags added from TagGroup.addTagFactory.


    Parameters

    • obj: T
    • tags: Collection<string>

      collection tor which tags applies

    Returns void

addTagsFor

  • addTagsFor(obj: T, ...tags: string[]): void
  • Appends primary tags for object; regardless of whether object is in group or not, tags will be added.


    Parameters

    • obj: T
    • rest...tags: string[]

      primary tags to be added for object

    Returns void

getAllWhere

getAllWithTag

  • getAllWithTag(tag: string): List<T>
  • Fetches objects which has presented tag.


    Parameters

    • tag: string

    Returns List<T>

getAllWithTags

  • Fetches objects which have all of presented tags.


    Parameters

    Returns List<T>

getTags

removeCommonObject

  • removeCommonObject(obj: T): void
  • Removes object from group, so it no longer can be fetched via TagGroup.getAllWhere, etc.


    Parameters

    • obj: T

    Returns void

removeTagsFor

  • removeTagsFor(obj: T, ...tags: string[]): void
  • Removes primary tags from object.


    Parameters

    • obj: T
    • rest...tags: string[]

      primary tags to be removed from object

    Returns void

TagPredicate

  • TagPredicate(obj: T, tags: Collection<string>): boolean
  • Parameters

    • obj: T

      object from group

    • tags: Collection<string>

      collection with all tags

    Returns boolean

Functions

addCommonObject

  • addCommonObject(group: string, obj: any, tags: string[]): void
  • Appends object to group to use in iterator and filtering functions like TagRegistry.getAllWith, etc.


    Parameters

    • group: string
    • obj: any
    • tags: string[]

      primary tags to be added for object

    Returns void

addTagFactory

  • addTagFactory(group: string, factory: TagFactory<any>): void
  • Tag factory determines additional tags, which should be added for specific object in group.


    Parameters

    Returns void

addTagFor

  • addTagFor(group: string, obj: any, tag: string, useExistingObject: boolean): void
  • Appends primary tag for object in group.


    Parameters

    • group: string
    • obj: any
    • tag: string

      primary tag to be added for object

    • useExistingObject: boolean

      do not append object to group

    Returns void

addTagsFor

  • addTagsFor(group: string, obj: any, tags: string[], useExistingObject: boolean): void
  • Appends primary tags for object in group; regardless of whether object is in group or not, tags will be added.


    Parameters

    • group: string
    • obj: any
    • tags: string[]

      primary tags to be added for object

    • useExistingObject: boolean

      do not append object to group

    Returns void

getAllWith

  • getAllWith(group: string, predicate: TagPredicate<any>): any[]
  • Iterates over existing common objects in group added via TagGroup.addCommonObject and collects objects matched predicate to list.


    Parameters

    Returns any[]

getAllWithTag

  • getAllWithTag(group: string, tag: string): any[]
  • Fetches objects in group which has presented tag.


    Parameters

    • group: string
    • tag: string

    Returns any[]

getAllWithTags

  • getAllWithTags(group: string, tags: string[]): any[]
  • Fetches objects in group which have all of presented tags.


    Parameters

    • group: string
    • tags: string[]

    Returns any[]

getOrCreateGroup

  • getOrCreateGroup(name: string): TagGroup
  • getOrCreateGroup<T>(name: string): TagGroup<T>
  • Gets or creates a new tag group to append tags for any objects.


    Parameters

    • name: string

    Returns TagGroup

getTagsFor

  • getTagsFor(group: string, obj: any): string[]

removeCommonObject

  • removeCommonObject(group: string, obj: any): void
  • Removes object from group, so it no longer can be fetched via TagRegistry.getAllWith, etc.


    Parameters

    • group: string
    • obj: any

    Returns void

removeTagsFor

  • removeTagsFor(group: string, obj: any, tags: string[]): void
  • Removes primary tags from object in group.


    Parameters

    • group: string
    • obj: any
    • tags: string[]

      primary tags to be removed from object

    Returns void