Skip to content

RegistryHelper ​

com.jsmacrosce.jsmacros.client.api.classes.RegistryHelper

Since1.8.4

Provides registry lookups and listings as JsMacros helpers. Identifier arguments may omit the minecraft: namespace. Unknown item and block ids resolve to their registry defaults (air); unknown status effect and enchantment ids fail rather than falling back.
Obtain an instance with Client.getRegistryManager().

js
// a block by name, the block state it defaults to, and the three
// ways of listing what is there
const reg = Client.getRegistryManager();  
const block = reg.getBlock("stone");  
Chat.log(`${block.getId()} is ${block.getName()}`);  
const state = reg.getBlockState("oak_stairs", "[facing=north]");  
Chat.log(`a stair facing north is solid: ${state.isSolid()}`);  
Chat.log(`${reg.getBlockIds().size()} blocks and ${reg.getItemIds().size()} items`);

Constructors ​

new RegistryHelper ​

new RegistryHelper()#

Methods ​

getActivityTypeIds ​

getActivityTypeIds(): List<String>Since1.8.4#
Returns identifiers for built-in activities, which represent activities a villager can perform. The list comes from the local built-in registry, independent of a server connection and without server data-pack additions.
Returns: the built-in activity identifiers.

getBlock ​

getBlock(String id): BlockHelperSince1.8.4#
Looks up a block by id, with or without its namespace. An unknown id resolves to the block registry's default, air, rather than reporting an error.
// Unknown ids resolve to air, so read back the id to verify the lookup.
const reg = Client.getRegistryManager();
const block = reg.getBlock("stone");
Chat.log(`${block.getId()} is ${block.getName()}`);

Parameters:

  • id: the block's id
Returns: an BlockHelper for the given block.

getBlockEntityTypeIds ​

getBlockEntityTypeIds(): List<String>Since1.8.4#
Returns identifiers for block entity types in the local built-in registry.
Returns: a list of all block entity type ids.

getBlockIds ​

getBlockIds(): List<String>Since1.8.4#
Returns all registered block ids in namespaced form, suitable for getBlock(String).
// Filter the namespaced ids as needed.
const reg = Client.getRegistryManager();
const ids = reg.getBlockIds();
Chat.log(`${ids.size()} blocks registered`);
let ores = 0;
for (const id of ids) {
  if (id.endsWith("_ore")) {
    ores = ores + 1;
  }
}
Chat.log(`${ores} of them are ores`);
Returns: a list of all registered block ids.

getBlocks ​

getBlocks(): List<BlockHelper>Since1.8.4#
Returns every registered block as a helper.
// Access each registered block through its helper.
const reg = Client.getRegistryManager();
const blocks = reg.getBlocks();
const first = blocks.get(0);
Chat.log(`${blocks.size()} blocks, the first is ${first.getId()}`);
Returns: a list of all registered blocks.

getBlockState ​

getBlockState(String id): BlockStateHelperSince1.8.4#
Returns the block's default state; use getBlockState(String, String) to select properties. An unknown id resolves to the default block, air.
// Get the default state; supply properties to select a variant.
const reg = Client.getRegistryManager();
const state = reg.getBlockState("oak_stairs");
Chat.log(`${state.getId()} facing ${state.getPistonBehaviour()} is solid: ${state.isSolid()}`);

Parameters:

  • id: the block's id
Returns: an BlockStateHelper for the given block.
getBlockState(String id, String nbt): BlockStateHelperSince1.8.4#
Parses block properties in the game's command syntax, appended directly after the block id (for example, [facing=north]). Invalid syntax, block ids, properties, or values throw CommandSyntaxException.
// Select a particular state using the game's block-property syntax.
const reg = Client.getRegistryManager();
const stairs = reg.getBlockState("oak_stairs", "[facing=north,half=top]");
Chat.log(`${stairs.getId()} solid: ${stairs.isSolid()}`);

Parameters:

  • id: the block's id
  • nbt: the block-state properties in command syntax, such as [facing=north]
Returns: the block state with the specified properties

getEnchantment ​

getEnchantment(String id): EnchantmentHelperSince1.8.4#
Looks up an enchantment in the connected server's registry. The returned helper has level zero; use getEnchantment(String, int) to supply a level. Unknown ids fail rather than falling back, and a server connection is required.
// Look up the enchantment without assigning it an item level.
const reg = Client.getRegistryManager();
const ench = reg.getEnchantment("minecraft:sharpness");
Chat.log(`${ench.getId()} level ${ench.getLevel()} of ${ench.getMaxLevel()}`);

Parameters:

  • id: the enchantment's id
Returns: an EnchantmentHelper for the given enchantment.
getEnchantment(String id, int level): EnchantmentHelperSince1.8.4#
Looks up an enchantment in the connected server's registry and associates the supplied level with its helper. The level is not clamped to the enchantment's maximum. Unknown ids fail rather than falling back, and a server connection is required.
// Associate a level with an enchantment from the server registry.
const reg = Client.getRegistryManager();
const ench = reg.getEnchantment("sharpness", 5);
Chat.log(`${ench.getId()} ${ench.getLevel()} of ${ench.getMaxLevel()}`);

Parameters:

  • id: the enchantment's id
  • level: the level of the enchantment
Returns: an EnchantmentHelper for the given enchantment with the specified level.

getEnchantmentIds ​

getEnchantmentIds(): List<String>Since1.8.4#
Returns the ids in the connected server's enchantment registry. A connection is required; without one, dereferencing it fails rather than returning an empty list.
Returns: a list of all registered enchantment ids.

getEnchantments ​

getEnchantments(): List<EnchantmentHelper>Since1.8.4#
Returns helpers for the enchantments in the connected server's registry, each with its default helper level. A connection is required; without one, dereferencing it fails.
Returns: a list of all registered enchantments.

getEntity ​

getEntity(String type): EntityHelper<?>Since1.8.4#
Creates an entity of the registry type named by type, using command spawn reason; the entity is not added to the world. A world must be loaded. Unknown ids resolve to the built-in registry default (the pig). Types that cannot be created in the current world produce no entity, which fails when wrapping the result.

Parameters:

  • type: the id of the entity's type
Returns: an EntityHelper for the given entity.

getEntityAttributeIds ​

getEntityAttributeIds(): List<String>Since1.8.4#
Returns identifiers for built-in entity attributes, such as health and movement speed. The list comes from the local built-in registry, independent of a server connection and without server data-pack additions.
Returns: the built-in entity attribute identifiers.

getEntityTypeIds ​

getEntityTypeIds(): List<String>Since1.8.4#
Returns ids from the built-in entity type registry, including types that are placeholders and cannot be instantiated.
Returns: a list of all entity type ids.

getFeatureIds ​

getFeatureIds(): List<String>Since1.8.4#
Returns ids from the built-in world-generation feature registry, independent of the connected server's data packs.
Returns: a list of all feature ids.

getFluidState ​

getFluidState(String id): FluidStateHelperSince1.8.4#
Returns the default state of the built-in fluid named by id, not a state sampled from a world. Unknown ids resolve to the registry default (the empty fluid).

Parameters:

  • id: the fluid's id
Returns: an FluidStateHelper for the given fluid.

getGameEventNames ​

getGameEventNames(): List<String>Since1.8.4#
Returns identifiers for game events in the local built-in registry.
Returns: a list of all game event names.

getIdentifier ​

getIdentifier(String identifier): IdentifierSince1.8.4#
Parses an identifier string without looking it up in a registry. A missing namespace is supplied as minecraft.

Parameters:

  • identifier: an identifier string, with or without a namespace
Returns: the parsed identifier

getItem ​

getItem(String id): ItemHelperSince1.8.4#
Looks up an item by id, which may omit the minecraft: namespace. Unknown ids resolve to the item registry's default, air.

Parameters:

  • id: the item's id
Returns: an ItemHelper for the given item.

getItemIds ​

getItemIds(): List<String>Since1.8.4#
Returns all item ids in namespaced form, suitable for getItem(String).
Returns: a list of all registered item ids.

getItems ​

getItems(): List<ItemHelper>Since1.8.4#
Returns a helper for each registered item.
Returns: a list of all registered items.

getItemStack ​

getItemStack(String id): ItemStackHelperSince1.8.4#
Creates a one-item stack without components. Use getItemStack(String, String) to parse components. Unknown ids resolve to the item registry's default, air.

Parameters:

  • id: the item's id
Returns: an ItemStackHelper for the given item.
getItemStack(String id, String nbt): ItemStackHelperSince1.8.4#
Parses item components using command item-argument syntax appended directly to the id (for example, [damage=12]). The returned stack has count one. A connection is required; invalid syntax throws CommandSyntaxException.

Parameters:

  • id: the item's id
  • nbt: component data in the game's item-argument syntax, including square brackets
Returns: an ItemStackHelper for the item with the parsed components.

getMemoryModuleTypeIds ​

getMemoryModuleTypeIds(): List<String>Since1.8.4#
Returns identifiers for memory module types in the local built-in registry.
Returns: a list of all memory module type ids.

getNbtOps ​

static getNbtOps(): RegistryOps<Tag>#
Creates registry-aware NBT operations from the current connection's registry access. Use these instead of NbtOps.INSTANCE to encode registry-backed data. Each call creates new operations; without a connection this throws IllegalStateException.
Returns: new registry-aware NBT operations for the current connection

getPaintingIds ​

getPaintingIds(): List<String>Since1.8.4#
Returns ids from the connected server's painting variant registry. A connection is required; without one, dereferencing it fails rather than returning an empty list.
Returns: a list of all painting motive ids.

getParticleTypeIds ​

getParticleTypeIds(): List<String>Since1.8.4#
Returns identifiers for particle types in the local built-in registry, not individual particle instances or their parameters.
Returns: a list of all particle type ids.

getPointOfInterestTypeIds ​

getPointOfInterestTypeIds(): List<String>Since1.8.4#
Returns identifiers for point of interest types in the local built-in registry.
Returns: a list of all point of interest type ids.

getPotionTypeIds ​

getPotionTypeIds(): List<String>Since1.8.4#
Returns identifiers for built-in potion types (brews), not the effects they carry. The list comes from the local built-in registry, independent of a server connection and without server data-pack additions.
Returns: the built-in potion type identifiers.

getRawEntityType ​

getRawEntityType(String type): EntityType<?>Since1.8.4#
Returns the built-in entity type for type; this does not create an entity and needs no world. Unknown ids resolve to the registry default (the pig).

Parameters:

  • type: the id of the entity's type
Returns: an EntityType for the given entity.

getRecipeTypeIds ​

getRecipeTypeIds(): List<String>Since1.8.4#
Returns identifiers for recipe types in the local built-in registry, not individual recipes.
Returns: a list of all recipe type ids.

getScreenHandlerIds ​

getScreenHandlerIds(): List<String>Since1.8.4#
Returns identifiers for screen handlers in the local built-in registry.
Returns: a list of all screen handler ids.

getSensorTypeIds ​

getSensorTypeIds(): List<String>Since1.8.4#
Returns identifiers for the built-in sensor types; these represent senses a mob's brain uses to notice things, not the things sensed. The list comes from the local built-in registry, independent of a server connection and without server data-pack additions.
Returns: the built-in sensor type identifiers.

getStatTypeIds ​

getStatTypeIds(): List<String>Since1.8.4#
Returns identifiers for built-in statistic types, not advancements. The list comes from the local built-in registry, independent of a server connection and without server data-pack additions.
Returns: the built-in statistic type identifiers.

getStatusEffect ​

getStatusEffect(String id): StatusEffectHelper#
Looks up a status effect by id, with or without its namespace. An unknown id does not produce a usable helper: constructing it with the missing effect fails.

Parameters:

  • id: the status effect's id
Returns: a helper for the effect with 0 ticks duration

getStatusEffectIds ​

getStatusEffectIds(): List<String>Since1.8.4#
Returns identifiers for status effects in the local built-in registry.
Returns: a list of all status effect ids.

getStatusEffects ​

getStatusEffects(): List<StatusEffectHelper>Since1.8.4#
Returns each registered status effect as a helper without a duration.
// List all registered status effects.
const reg = Client.getRegistryManager();
const effects = reg.getStatusEffects();
Chat.log(`${effects.size()} status effects`);
const first = effects.get(0);
Chat.log(`the first is ${first.getId()}`);
Returns: a list of all registered status effects as StatusEffectHelpers with 0 ticks duration.

getStructureFeatureIds ​

getStructureFeatureIds(): List<String>Since1.8.4#
Returns ids from the built-in structure-piece registry, not ids for complete structures; connected-server data packs are not reflected.
Returns: a list of all structure feature ids.

getVillagerProfessionIds ​

getVillagerProfessionIds(): List<String>Since1.8.4#
Returns identifiers for villager professions in the local built-in registry.
Returns: a list of all villager profession ids.

getVillagerTypeIds ​

getVillagerTypeIds(): List<String>Since1.8.4#
Returns identifiers for villager types in the local built-in registry.
Returns: a list of all villager type ids.

getWrapperLookup ​

static getWrapperLookup(): HolderLookup.Provider#
Returns the current connection's registry lookup provider, the provider used to create getNbtOps(). Without a connection this throws IllegalStateException.
Returns: the current connection's registry lookup provider

parseIdentifier ​

static parseIdentifier(String id): IdentifierSince1.8.4#
Parses an identifier string without checking whether it is registered. A missing namespace is supplied as minecraft; invalid identifier syntax is rejected by Minecraft.

Parameters:

  • id: an identifier string, with or without a namespace
Returns: the parsed identifier

parseNameSpace ​

static parseNameSpace(String id): StringSince1.8.4#
Prepends minecraft: when the input contains no colon; otherwise returns it unchanged.

Parameters:

  • id: the string to prefix when it contains no colon
Returns: the input prefixed with minecraft: if it contains no colon, or unchanged otherwise