Namespace TagRegistry

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

2.0.4b38

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");
}
});

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");
}
});

Functions

  • 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

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

    Parameters

    Returns 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

  • 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

  • Fetches objects in group which has presented tag.

    Parameters

    • group: string
    • tag: string

    Returns any[]

  • Fetches objects in group which have all of presented tags.

    Parameters

    • group: string
    • tags: string[]

    Returns any[]

  • Removes primary tags from object in group.

    Parameters

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

      primary tags to be removed from object

    Returns void

Copyright © 2024 Nernar. Copyright © 2020 #mineprogramming. Built with ❤ and TypeDoc.