AdvancementHelper
com.jsmacrosce.jsmacros.client.api.helper.AdvancementHelper
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
Returns this node's direct children, not their descendants. A leaf has no children.
Returns: a list of all child advancements.
getExperience
Returns the experience points awarded when this advancement is earned.
Returns: the experience awarded by this advancement.
getId
getLoot
getParent
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
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
getRequirementCount
Returns the number of requirement groups, not the number of individual criteria.
Returns: the amount of requirements.
getRequirements
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.