Search in sources :

Example 1 with SpongeAndCriterion

use of org.spongepowered.common.advancement.criterion.SpongeAndCriterion in project SpongeCommon by SpongePowered.

the class AdvancementProgressMixin method impl$processProgressMap.

private void impl$processProgressMap(AdvancementCriterion criterion, Map<String, ImplementationBackedCriterionProgress> progressMap) {
    if (criterion instanceof OperatorCriterion) {
        ((OperatorCriterion) criterion).criteria().forEach(child -> this.impl$processProgressMap(child, progressMap));
        if (criterion instanceof AndCriterion) {
            progressMap.put(criterion.name(), new SpongeAndCriterionProgress((org.spongepowered.api.advancement.AdvancementProgress) this, (SpongeAndCriterion) criterion));
        } else if (criterion instanceof OrCriterion) {
            progressMap.put(criterion.name(), new SpongeOrCriterionProgress((org.spongepowered.api.advancement.AdvancementProgress) this, (SpongeOrCriterion) criterion));
        }
    } else if (criterion instanceof SpongeScoreCriterion) {
        final SpongeScoreCriterion scoreCriterion = (SpongeScoreCriterion) criterion;
        for (final AdvancementCriterion internalCriterion : scoreCriterion.internalCriteria) {
            final CriterionProgressBridge progress = (CriterionProgressBridge) this.criteria.get(internalCriterion.name());
            progress.bridge$setCriterion(internalCriterion);
            progress.bridge$setAdvancementProgress((org.spongepowered.api.advancement.AdvancementProgress) this);
            progressMap.put(internalCriterion.name(), (ImplementationBackedCriterionProgress) progress);
        }
        progressMap.put(scoreCriterion.name(), new SpongeScoreCriterionProgress((org.spongepowered.api.advancement.AdvancementProgress) this, scoreCriterion));
    } else if (!(criterion instanceof SpongeEmptyCriterion)) {
        final CriterionProgressBridge progress = (CriterionProgressBridge) this.criteria.get(criterion.name());
        progress.bridge$setCriterion(criterion);
        progress.bridge$setAdvancementProgress((org.spongepowered.api.advancement.AdvancementProgress) this);
        progressMap.put(criterion.name(), (ImplementationBackedCriterionProgress) progress);
    }
}
Also used : AdvancementProgress(net.minecraft.advancements.AdvancementProgress) SpongeOrCriterion(org.spongepowered.common.advancement.criterion.SpongeOrCriterion) OrCriterion(org.spongepowered.api.advancement.criteria.OrCriterion) SpongeAndCriterionProgress(org.spongepowered.common.advancement.criterion.SpongeAndCriterionProgress) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) SpongeScoreCriterion(org.spongepowered.common.advancement.criterion.SpongeScoreCriterion) ImplementationBackedCriterionProgress(org.spongepowered.common.advancement.criterion.ImplementationBackedCriterionProgress) AndCriterion(org.spongepowered.api.advancement.criteria.AndCriterion) SpongeAndCriterion(org.spongepowered.common.advancement.criterion.SpongeAndCriterion) SpongeScoreCriterionProgress(org.spongepowered.common.advancement.criterion.SpongeScoreCriterionProgress) SpongeAndCriterion(org.spongepowered.common.advancement.criterion.SpongeAndCriterion) SpongeEmptyCriterion(org.spongepowered.common.advancement.criterion.SpongeEmptyCriterion) CriterionProgressBridge(org.spongepowered.common.bridge.advancements.CriterionProgressBridge) OperatorCriterion(org.spongepowered.api.advancement.criteria.OperatorCriterion) SpongeOrCriterionProgress(org.spongepowered.common.advancement.criterion.SpongeOrCriterionProgress)

Example 2 with SpongeAndCriterion

use of org.spongepowered.common.advancement.criterion.SpongeAndCriterion in project SpongeCommon by SpongePowered.

the class SpongeCriterionUtil method collectCriteria.

private static List<List<String>> collectCriteria(final AdvancementCriterion criterion, final Map<String, Criterion> criteria) {
    List<List<String>> requirements = new ArrayList<>();
    if (criterion instanceof SpongeAndCriterion) {
        ((SpongeOperatorCriterion) criterion).criteria().forEach(c -> requirements.addAll(SpongeCriterionUtil.collectCriteria(c, criteria)));
    } else if (criterion instanceof SpongeOrCriterion) {
        // OR List of AND Criteria of OR Criteria
        final List<List<List<String>>> andRequirementsList = ((SpongeOperatorCriterion) criterion).criteria().stream().map(c -> SpongeCriterionUtil.collectCriteria(c, criteria)).collect(Collectors.toList());
        List<List<String>> finalList = new ArrayList<>();
        // For every AND Criteria
        for (List<List<String>> andRequirements : andRequirementsList) {
            if (finalList.isEmpty()) {
                // Just take the first one in as is
                finalList.addAll(andRequirements);
            } else {
                List<List<String>> workingList = new ArrayList<>();
                for (List<String> andRequirement : andRequirements) {
                    for (List<String> prevAndRequirement : finalList) {
                        // For every AND requirement and FOR every previous AND requirement
                        // combine their OR requirements
                        // !! this can get very big very quickly !!
                        // TODO limit requirement count?
                        final List<String> newAndRequirement = new ArrayList<>(prevAndRequirement);
                        newAndRequirement.addAll(andRequirement);
                        workingList.add(newAndRequirement);
                    }
                }
                finalList = workingList;
            }
        }
        requirements.addAll(finalList);
    } else if (criterion instanceof SpongeScoreCriterion) {
        final SpongeScoreCriterion scoreCriterion = (SpongeScoreCriterion) criterion;
        for (int i = 0; i < scoreCriterion.goal(); i++) {
            final DefaultedAdvancementCriterion internalCriterion = scoreCriterion.internalCriteria.get(i);
            criteria.put(internalCriterion.name(), ((Criterion) internalCriterion));
            requirements.add(Collections.singletonList(internalCriterion.name()));
        }
    } else {
        criteria.put(criterion.name(), (Criterion) criterion);
        requirements.add(Collections.singletonList(criterion.name()));
    }
    return requirements;
}
Also used : SpongeAndCriterion(org.spongepowered.common.advancement.criterion.SpongeAndCriterion) SpongeOperatorCriterion(org.spongepowered.common.advancement.criterion.SpongeOperatorCriterion) SpongeOrCriterion(org.spongepowered.common.advancement.criterion.SpongeOrCriterion) SpongeOperatorCriterion(org.spongepowered.common.advancement.criterion.SpongeOperatorCriterion) SpongeEmptyCriterion(org.spongepowered.common.advancement.criterion.SpongeEmptyCriterion) Criterion(net.minecraft.advancements.Criterion) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) DefaultedAdvancementCriterion(org.spongepowered.common.advancement.criterion.DefaultedAdvancementCriterion) OperatorCriterion(org.spongepowered.api.advancement.criteria.OperatorCriterion) SpongeAndCriterion(org.spongepowered.common.advancement.criterion.SpongeAndCriterion) SpongeScoreCriterion(org.spongepowered.common.advancement.criterion.SpongeScoreCriterion) DefaultedAdvancementCriterion(org.spongepowered.common.advancement.criterion.DefaultedAdvancementCriterion) ArrayList(java.util.ArrayList) SpongeOrCriterion(org.spongepowered.common.advancement.criterion.SpongeOrCriterion) ArrayList(java.util.ArrayList) List(java.util.List) SpongeScoreCriterion(org.spongepowered.common.advancement.criterion.SpongeScoreCriterion)

Aggregations

AdvancementCriterion (org.spongepowered.api.advancement.criteria.AdvancementCriterion)2 OperatorCriterion (org.spongepowered.api.advancement.criteria.OperatorCriterion)2 SpongeAndCriterion (org.spongepowered.common.advancement.criterion.SpongeAndCriterion)2 SpongeEmptyCriterion (org.spongepowered.common.advancement.criterion.SpongeEmptyCriterion)2 SpongeOrCriterion (org.spongepowered.common.advancement.criterion.SpongeOrCriterion)2 SpongeScoreCriterion (org.spongepowered.common.advancement.criterion.SpongeScoreCriterion)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AdvancementProgress (net.minecraft.advancements.AdvancementProgress)1 Criterion (net.minecraft.advancements.Criterion)1 AndCriterion (org.spongepowered.api.advancement.criteria.AndCriterion)1 OrCriterion (org.spongepowered.api.advancement.criteria.OrCriterion)1 DefaultedAdvancementCriterion (org.spongepowered.common.advancement.criterion.DefaultedAdvancementCriterion)1 ImplementationBackedCriterionProgress (org.spongepowered.common.advancement.criterion.ImplementationBackedCriterionProgress)1 SpongeAndCriterionProgress (org.spongepowered.common.advancement.criterion.SpongeAndCriterionProgress)1 SpongeOperatorCriterion (org.spongepowered.common.advancement.criterion.SpongeOperatorCriterion)1 SpongeOrCriterionProgress (org.spongepowered.common.advancement.criterion.SpongeOrCriterionProgress)1 SpongeScoreCriterionProgress (org.spongepowered.common.advancement.criterion.SpongeScoreCriterionProgress)1 CriterionProgressBridge (org.spongepowered.common.bridge.advancements.CriterionProgressBridge)1