RegistryHelper
com.jsmacrosce.jsmacros.client.api.classes.RegistryHelper
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
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
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
getBlockIds
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
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
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.
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 idnbt: the block-state properties in command syntax, such as[facing=north]
Returns: the block state with the specified properties
getEnchantment
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.
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 idlevel: the level of the enchantment
Returns: an EnchantmentHelper for the given enchantment with the specified level.
getEnchantmentIds
getEnchantments
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
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
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
getFeatureIds
getFluidState
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
getIdentifier
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
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
Returns all item ids in namespaced form, suitable for getItem(String).
Returns: a list of all registered item ids.
getItems
Returns a helper for each registered item.
Returns: a list of all registered items.
getItemStack
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.
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 idnbt: component data in the game's item-argument syntax, including square brackets
Returns: an ItemStackHelper for the item with the parsed components.
getMemoryModuleTypeIds
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
getParticleTypeIds
getPointOfInterestTypeIds
getPotionTypeIds
getRawEntityType
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
getScreenHandlerIds
getSensorTypeIds
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
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
getStatusEffects
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
getVillagerProfessionIds
getVillagerTypeIds
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
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