Skip to content

AdvancementHelper ​

com.jsmacrosce.jsmacros.client.api.helper.AdvancementHelper

Since1.8.4

Represents an advancement definition and its position in the advancement tree. Use getParent() and getChildren() to navigate the tree; rewards and requirements describe the definition, while getProgress() reports local-player progress.

Obtain advancements from the player's advancement manager.

js
const player = Player.getPlayer();  
if (player !== null) {
  const manager = player.getAdvancementManager();  

  // one advancement by identifier, and what it awards
  const root = manager.getAdvancement("minecraft:story/root");  
  if (root.getRaw() !== null) {
    Chat.log(`${root.getId()} gives ${root.getExperience()} xp`);  
    if (root.getLoot().length > 0) {
      Chat.log(`and loot: ${root.getLoot().join(", ")}`);  
    }

    // walk the tree downwards from there
    for (const child of root.getChildren()) {
      Chat.log(`  child ${child.getId()}`);  
    }

    // and how far the player has got on it
    const progress = root.getProgress();  
    if (progress.getRaw() !== null) {
      Chat.log(`${Math.round(progress.getPercentage() * 100)} percent`);  
    }
  }
}

Constructors ​

new AdvancementHelper ​

new AdvancementHelper(AdvancementNode base)#
Wraps the supplied advancement node.

Parameters:

  • base: raw advancement node to wrap

Methods ​

getChildren ​

getChildren(): List<AdvancementHelper>Since1.8.4#
Returns this node's direct children, not their descendants. A leaf has no children.
Returns: a list of all child advancements.

getExperience ​

getExperience(): intSince1.8.4#
Returns the experience points awarded when this advancement is earned.
Returns: the experience awarded by this advancement.

getId ​

getId(): StringSince1.8.4#
Returns the advancement's data-pack identifier.
Returns: the identifier of this advancement.

getLoot ​

getLoot(): String[]Since1.8.4#
Returns the identifiers of loot tables granted by this advancement. Inline loot tables on Minecraft 26.3 and later have no registry identifier and are omitted.
Returns: the loot table ids for this advancement's rewards.

getParent ​

getParent(): AdvancementHelperSince1.8.4#
Returns this advancement's parent in the tree, or null if it is a root.
Returns: the parent advancement or null if there is none.

getProgress ​

getProgress(): AdvancementProgressHelperSince1.8.4#
Returns the local player's progress for this advancement, from the progress data received from the server. If no progress entry exists, the returned helper wraps null; its progress methods cannot be used in that state.
Returns: the local player's progress, or a helper wrapping null if no progress entry exists.

getRecipes ​

getRecipes(): String[]Since1.8.4#
Returns identifiers of recipes unlocked by this advancement; empty when it has no recipe rewards.
Returns: the recipes unlocked through this advancement.

getRequirementCount ​

getRequirementCount(): intSince1.8.4#
Returns the number of requirement groups, not the number of individual criteria.
Returns: the amount of requirements.

getRequirements ​

getRequirements(): List<List<String>>Since1.8.4#
Returns the advancement's criterion requirements grouped by completion rule. Every group must be satisfied; satisfying any one criterion in a group satisfies that group.
const player = Player.getPlayer();
if (player === null) { throw new Error("not in a world"); }
const manager = player.getAdvancementManager();
const adv = manager.getAdvancement("minecraft:story/mine_stone");
for (const group of adv.getRequirements()) {
  // one of these is enough for this group, and every group is needed
  Chat.log(`needs one of: ${group.join(" or ")}`);
}
Returns: the requirements of this advancement.

toJson ​

toJson(): StringSince1.9.0#
Returns this advancement's definition encoded as a JSON string.
Returns: this advancement's JSON definition.

toString ​

toString(): String#
Returns a diagnostic representation containing this advancement's identifier.
Returns: diagnostic representation of this advancement