AdvancementProgressHelper
com.jsmacrosce.jsmacros.client.api.helper.AdvancementProgressHelper
Progress of a player's advancement, including completed criteria and requirement groups.
Each group requires at least one completed criterion; all groups must be satisfied. Percentages count satisfied groups, and obtained-criterion timestamps are milliseconds since the epoch.
js
const player = Player.getPlayer();
if (player !== null) {
const manager = player.getAdvancementManager();
const progress = manager.getAdvancementProgress("minecraft:story/mine_stone");
if (progress.getRaw() === null) { throw new Error("no progress entry"); }
if (progress.isDone()) {
Chat.log("already earned");
} else {
// the game's own "1/2" style text, straight from the tab, and null
// when the advancement has a single group so guard it
const fraction = progress.getFraction();
Chat.log(`progress: ${fraction === null ? "part way" : fraction.getString()}`);
// and what is actually left
for (const criterion of progress.getUnobtainedCriteria()) {
Chat.log(`still to do: ${criterion}`);
}
}
}Constructors
new AdvancementProgressHelper
new AdvancementProgressHelper(AdvancementProgress base)#Wraps the supplied advancement progress by storing it as this helper's base value.
Parameters:
base: raw advancement progress to wrap
Methods
countObtainedRequirements
Number of requirement groups for which at least one criterion is completed.
Returns: the number of satisfied requirement groups.
getCriteria
getCriterionProgress
Completion time for a named criterion, in milliseconds since the epoch. An unknown name returns
-1; a known but incomplete criterion throws NullPointerException.Parameters:
criteria: criterion name
Returns: completion time in milliseconds since the epoch, or
-1 if the name is unknowngetEarliestProgressObtainDate
Earliest completion time among this advancement's criteria, in milliseconds since the epoch. Throws NullPointerException if no criterion has been completed.
const player = Player.getPlayer();
if (player === null) { throw new Error("not in a world"); }
const manager = player.getAdvancementManager();
const progress = manager.getAdvancementProgress("minecraft:story/mine_stone");
if (progress.getRaw() === null) { throw new Error("no progress entry"); }
if (progress.isAnyObtained()) {
const started = new Date(progress.getEarliestProgressObtainDate());
Chat.log(`first touched at ${started.toISOString()}`);
}Returns: the earliest completion date of all criteria.
getFraction
Localized progress text for the requirement groups, or
null when there are no criteria or at most one requirement group. See getPercentage() for a numeric value.Returns: localized progress text, or
null when unavailable.getObtainedCriteria
getPercentage
Fraction of requirement groups satisfied, from
0 to 1; an empty requirement set yields 0.Returns: the fraction of requirement groups satisfied.
getRequirements
getUnobtainedCriteria
isAnyObtained
Whether at least one criterion has been completed, including for a finished advancement.
Returns:
true if any criteria has already been met, false otherwise.isCriteriaObtained
Whether a named criterion is completed. An unknown criterion name throws NullPointerException.
Parameters:
criteria: criterion name
Returns:
true if completed; false if the criterion is known but incompleteisDone
Whether all requirement groups are satisfied. An empty requirement list is not done.
Returns:
true if the advancement is finished, false otherwise.