Search in sources :

Example 1 with CriterionProgressBridge

use of org.spongepowered.common.bridge.advancements.CriterionProgressBridge in project SpongeCommon by SpongePowered.

the class CriterionProgressMixin_API method grant.

@Override
public Instant grant() {
    if (this.obtained != null) {
        return this.obtained.toInstant();
    }
    final AdvancementProgress advancementProgress = ((CriterionProgressBridge) this).bridge$getAdvancementProgress();
    final org.spongepowered.api.advancement.Advancement advancement = advancementProgress.advancement();
    ((AdvancementProgressBridge) advancementProgress).bridge$getPlayerAdvancements().award((Advancement) advancement, this.criterion().name());
    return this.obtained.toInstant();
}
Also used : AdvancementProgress(org.spongepowered.api.advancement.AdvancementProgress) CriterionProgressBridge(org.spongepowered.common.bridge.advancements.CriterionProgressBridge)

Example 2 with CriterionProgressBridge

use of org.spongepowered.common.bridge.advancements.CriterionProgressBridge in project SpongeCommon by SpongePowered.

the class CriterionProgressMixin_API method revoke.

@Override
public Optional<Instant> revoke() {
    if (this.obtained == null) {
        return Optional.empty();
    }
    final Instant instant = this.obtained.toInstant();
    final AdvancementProgress advancementProgress = ((CriterionProgressBridge) this).bridge$getAdvancementProgress();
    final org.spongepowered.api.advancement.Advancement advancement = advancementProgress.advancement();
    ((AdvancementProgressBridge) advancementProgress).bridge$getPlayerAdvancements().revoke((Advancement) advancement, this.criterion().name());
    return Optional.of(instant);
}
Also used : AdvancementProgress(org.spongepowered.api.advancement.AdvancementProgress) Instant(java.time.Instant) CriterionProgressBridge(org.spongepowered.common.bridge.advancements.CriterionProgressBridge)

Example 3 with CriterionProgressBridge

use of org.spongepowered.common.bridge.advancements.CriterionProgressBridge in project SpongeCommon by SpongePowered.

the class PlayerAdvancementsMixin method impl$onUnregisterListenersGetProgress.

@Redirect(method = "registerListeners(Lnet/minecraft/advancements/Advancement;)V", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/advancements/CriterionProgress;isDone()Z"))
private boolean impl$onUnregisterListenersGetProgress(final CriterionProgress progress) {
    final CriterionProgressBridge mixinCriterionProgress = (CriterionProgressBridge) progress;
    if (((PlatformEntityBridge) this.player).bridge$isFakePlayer() || !mixinCriterionProgress.bridge$isCriterionAvailable()) {
        return progress.isDone();
    }
    final AdvancementCriterion criterion = ((org.spongepowered.api.advancement.criteria.CriterionProgress) progress).criterion();
    final CriterionBridge mixinCriterion = (CriterionBridge) criterion;
    // Only remove the trigger once the goal is reached
    if (mixinCriterion.bridge$getScoreCriterion() != null) {
        return ((CriterionProgressBridge) progress).bridge$getAdvancementProgress().get(mixinCriterion.bridge$getScoreCriterion()).get().achieved();
    }
    return progress.isDone();
}
Also used : AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) CriterionProgressBridge(org.spongepowered.common.bridge.advancements.CriterionProgressBridge) CriterionProgress(net.minecraft.advancements.CriterionProgress) CriterionBridge(org.spongepowered.common.bridge.advancements.CriterionBridge) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 4 with CriterionProgressBridge

use of org.spongepowered.common.bridge.advancements.CriterionProgressBridge 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)

Aggregations

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