Search in sources :

Example 1 with ImplementationBackedCriterionProgress

use of org.spongepowered.common.advancement.criterion.ImplementationBackedCriterionProgress 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 ImplementationBackedCriterionProgress

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

the class AdvancementProgressMixin method impl$supportComplexCriteria.

/**
 * @author Cybermaxke
 * @reason Rewrite the method to add support for the complex advancement criteria, only triggered on the server.
 */
@Inject(method = "isDone", at = @At("HEAD"), cancellable = true)
private void impl$supportComplexCriteria(final CallbackInfoReturnable<Boolean> ci) {
    if (this.impl$advancementKey == null || !PlatformHooks.INSTANCE.getGeneralHooks().onServerThread()) {
        // Use vanilla behavior on the client
        return;
    }
    final Advancement advancement = this.getOptionalAdvancement().orElse(null);
    if (advancement != null) {
        final ImplementationBackedCriterionProgress bridge = this.impl$progressMap.get(advancement.criterion().name());
        ci.setReturnValue(bridge != null && ((CriterionProgress) bridge).achieved());
    }
}
Also used : ImplementationBackedCriterionProgress(org.spongepowered.common.advancement.criterion.ImplementationBackedCriterionProgress) Advancement(org.spongepowered.api.advancement.Advancement) SpongeAndCriterionProgress(org.spongepowered.common.advancement.criterion.SpongeAndCriterionProgress) SpongeOrCriterionProgress(org.spongepowered.common.advancement.criterion.SpongeOrCriterionProgress) SpongeScoreCriterionProgress(org.spongepowered.common.advancement.criterion.SpongeScoreCriterionProgress) ImplementationBackedCriterionProgress(org.spongepowered.common.advancement.criterion.ImplementationBackedCriterionProgress) CriterionProgress(org.spongepowered.api.advancement.criteria.CriterionProgress) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

ImplementationBackedCriterionProgress (org.spongepowered.common.advancement.criterion.ImplementationBackedCriterionProgress)2 SpongeAndCriterionProgress (org.spongepowered.common.advancement.criterion.SpongeAndCriterionProgress)2 SpongeOrCriterionProgress (org.spongepowered.common.advancement.criterion.SpongeOrCriterionProgress)2 SpongeScoreCriterionProgress (org.spongepowered.common.advancement.criterion.SpongeScoreCriterionProgress)2 AdvancementProgress (net.minecraft.advancements.AdvancementProgress)1 Advancement (org.spongepowered.api.advancement.Advancement)1 AdvancementCriterion (org.spongepowered.api.advancement.criteria.AdvancementCriterion)1 AndCriterion (org.spongepowered.api.advancement.criteria.AndCriterion)1 CriterionProgress (org.spongepowered.api.advancement.criteria.CriterionProgress)1 OperatorCriterion (org.spongepowered.api.advancement.criteria.OperatorCriterion)1 OrCriterion (org.spongepowered.api.advancement.criteria.OrCriterion)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1 SpongeAndCriterion (org.spongepowered.common.advancement.criterion.SpongeAndCriterion)1 SpongeEmptyCriterion (org.spongepowered.common.advancement.criterion.SpongeEmptyCriterion)1 SpongeOrCriterion (org.spongepowered.common.advancement.criterion.SpongeOrCriterion)1 SpongeScoreCriterion (org.spongepowered.common.advancement.criterion.SpongeScoreCriterion)1 CriterionProgressBridge (org.spongepowered.common.bridge.advancements.CriterionProgressBridge)1