Skip to content

AdvancementProgressHelper ​

com.jsmacrosce.jsmacros.client.api.helper.AdvancementProgressHelper

Since1.8.4

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 ​

countObtainedRequirements(): intSince1.8.4#
Number of requirement groups for which at least one criterion is completed.
Returns: the number of satisfied requirement groups.

getCriteria ​

getCriteria(): Map<String, Long>Since1.8.4#
Completed criteria and their completion times in milliseconds since the epoch. The returned map is newly collected on each call; unmet criteria are omitted.
Returns: a map of every criterion that has been met, and when it was met.

getCriterionProgress ​

getCriterionProgress(String criteria): longSince1.8.4#
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 unknown

getEarliestProgressObtainDate ​

getEarliestProgressObtainDate(): longSince1.8.4#
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 ​

getFraction(): TextHelperSince1.8.4#
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 ​

getObtainedCriteria(): String[]Since1.8.4#
Names of completed criteria.
Returns: the names of completed criteria.

getPercentage ​

getPercentage(): floatSince1.8.4#
Fraction of requirement groups satisfied, from 0 to 1; an empty requirement set yields 0.
Returns: the fraction of requirement groups satisfied.

getRequirements ​

getRequirements(): List<List<String>>Since1.8.4#
Requirement groups: each inner list contains alternative criteria, and every group must have at least one completed criterion.
Returns: all requirements of this advancement.

getUnobtainedCriteria ​

getUnobtainedCriteria(): String[]Since1.8.4#
Names of criteria that have not been completed.
Returns: the names of incomplete criteria.

isAnyObtained ​

isAnyObtained(): booleanSince1.8.4#
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 ​

isCriteriaObtained(String criteria): booleanSince1.8.4#
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 incomplete

isDone ​

isDone(): booleanSince1.8.4#
Whether all requirement groups are satisfied. An empty requirement list is not done.
Returns: true if the advancement is finished, false otherwise.

toString ​

toString(): String#
Returns a diagnostic representation containing the advancement progress percentage.
Returns: diagnostic representation of advancement progress