Search in sources :

Example 1 with AdvancementRewards

use of net.minecraft.advancements.AdvancementRewards in project SpongeCommon by SpongePowered.

the class SpongeAdvancementBuilder method build.

@Override
public Advancement build() {
    checkState(this.id != null, "The id must be set");
    final PluginContainer plugin = Sponge.getCauseStackManager().getCurrentCause().first(PluginContainer.class).get();
    final Tuple<Map<String, Criterion>, String[][]> result = SpongeCriterionHelper.toVanillaCriteriaData(this.criterion);
    final AdvancementRewards rewards = AdvancementRewards.EMPTY;
    final ResourceLocation resourceLocation = new ResourceLocation(plugin.getId(), this.id);
    final net.minecraft.advancements.DisplayInfo displayInfo = this.displayInfo == null ? null : // Create a copy
    (net.minecraft.advancements.DisplayInfo) DisplayInfo.builder().from(this.displayInfo).build();
    net.minecraft.advancements.Advancement parent = (net.minecraft.advancements.Advancement) this.parent;
    if (parent == null) {
        // Attach a dummy root until a tree is constructed
        parent = DUMMY_ROOT_ADVANCEMENT;
    }
    final Advancement advancement = (Advancement) new net.minecraft.advancements.Advancement(resourceLocation, parent, displayInfo, rewards, result.getFirst(), result.getSecond());
    ((IMixinAdvancement) advancement).setCriterion(this.criterion);
    if (StringUtils.isNotEmpty(this.name)) {
        ((IMixinAdvancement) advancement).setName(this.name);
    }
    return advancement;
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) AdvancementRewards(net.minecraft.advancements.AdvancementRewards) ResourceLocation(net.minecraft.util.ResourceLocation) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Advancement(org.spongepowered.api.advancement.Advancement) IMixinAdvancement(org.spongepowered.common.interfaces.advancement.IMixinAdvancement) IMixinAdvancement(org.spongepowered.common.interfaces.advancement.IMixinAdvancement)

Example 2 with AdvancementRewards

use of net.minecraft.advancements.AdvancementRewards in project SpongeCommon by SpongePowered.

the class SpongeAdvancementBuilder method build0.

@Override
public Advancement build0() {
    final Tuple<Map<String, Criterion>, String[][]> result = SpongeCriterionUtil.toVanillaCriteriaData(this.criterion);
    final AdvancementRewards rewards = AdvancementRewards.EMPTY;
    final ResourceLocation resourceLocation = (ResourceLocation) (Object) key;
    final net.minecraft.advancements.DisplayInfo displayInfo = this.displayInfo == null ? null : new net.minecraft.advancements.DisplayInfo(ItemStackUtil.fromSnapshotToNative(this.displayInfo.icon()), SpongeAdventure.asVanilla(this.displayInfo.title()), SpongeAdventure.asVanilla(this.displayInfo.description()), this.backgroundPath, (FrameType) (Object) this.displayInfo.type(), this.displayInfo.doesShowToast(), this.displayInfo.doesAnnounceToChat(), this.displayInfo.isHidden());
    final net.minecraft.advancements.Advancement parent = (net.minecraft.advancements.Advancement) this.parent;
    final Advancement advancement = (Advancement) new net.minecraft.advancements.Advancement(resourceLocation, parent, displayInfo, rewards, result.first(), result.second());
    ((AdvancementBridge) advancement).bridge$setCriterion(this.criterion);
    return advancement;
}
Also used : AdvancementRewards(net.minecraft.advancements.AdvancementRewards) ResourceLocation(net.minecraft.resources.ResourceLocation) FrameType(net.minecraft.advancements.FrameType) AdvancementBridge(org.spongepowered.common.bridge.advancements.AdvancementBridge) Map(java.util.Map) Advancement(org.spongepowered.api.advancement.Advancement)

Example 3 with AdvancementRewards

use of net.minecraft.advancements.AdvancementRewards in project SpongeCommon by SpongePowered.

the class AdvancementMixin method impl$setUpSpongeFields.

@SuppressWarnings({ "ConstantConditions" })
@Inject(method = "<init>", at = @At("RETURN"))
private void impl$setUpSpongeFields(ResourceLocation location, @Nullable Advancement parent, @Nullable DisplayInfo displayInfo, AdvancementRewards rewards, Map<String, Criterion> criteria, String[][] requirements, CallbackInfo ci) {
    // Don't do anything on the client, unless we're performing registry initialization
    if (!PlatformHooks.INSTANCE.getGeneralHooks().onServerThread()) {
        return;
    }
    if (displayInfo != null) {
        ((DisplayInfoBridge) displayInfo).bridge$setAdvancement((org.spongepowered.api.advancement.Advancement) this);
    }
    this.impl$toastText = this.impl$generateToastText();
    final Map<String, DefaultedAdvancementCriterion> criteriaMap = new LinkedHashMap<>();
    final Map<String, List<DefaultedAdvancementCriterion>> scoreCriteria = new HashMap<>();
    for (Map.Entry<String, Criterion> entry : criteria.entrySet()) {
        final CriterionBridge mixinCriterion = (CriterionBridge) entry.getValue();
        final String groupName = mixinCriterion.bridge$getScoreCriterionName();
        if (groupName != null) {
            scoreCriteria.computeIfAbsent(groupName, k -> new ArrayList<>()).add((DefaultedAdvancementCriterion) entry.getValue());
        }
        criteriaMap.put(entry.getKey(), (DefaultedAdvancementCriterion) mixinCriterion);
        mixinCriterion.bridge$setName(entry.getKey());
    }
    for (Map.Entry<String, List<DefaultedAdvancementCriterion>> groupEntry : scoreCriteria.entrySet()) {
        criteriaMap.put(groupEntry.getKey(), new SpongeScoreCriterion(groupEntry.getKey(), groupEntry.getValue()));
        groupEntry.getValue().forEach(c -> criteriaMap.remove(c.name()));
    }
    final Set<AdvancementCriterion> andCriteria = new HashSet<>();
    for (final String[] array : requirements) {
        final Set<AdvancementCriterion> orCriteria = new HashSet<>();
        for (final String name : array) {
            DefaultedAdvancementCriterion criterion = criteriaMap.get(name);
            if (criterion == null && criteria.get(name) != null) {
                // internal removed by scoreCriterion
                criterion = criteriaMap.get(((CriterionBridge) criteria.get(name)).bridge$getScoreCriterionName());
            }
            orCriteria.add(criterion);
        }
        andCriteria.add(OrCriterion.of(orCriteria));
    }
    this.impl$criterion = AndCriterion.of(andCriteria);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) Inject(org.spongepowered.asm.mixin.injection.Inject) Criterion(net.minecraft.advancements.Criterion) HashMap(java.util.HashMap) Overwrite(org.spongepowered.asm.mixin.Overwrite) SpongeAdventure(org.spongepowered.common.adventure.SpongeAdventure) DisplayInfoBridge(org.spongepowered.common.bridge.advancements.DisplayInfoBridge) ArrayList(java.util.ArrayList) FrameType(net.minecraft.advancements.FrameType) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) DefaultedAdvancementCriterion(org.spongepowered.common.advancement.criterion.DefaultedAdvancementCriterion) ImmutableList(com.google.common.collect.ImmutableList) DisplayInfo(net.minecraft.advancements.DisplayInfo) Mixin(org.spongepowered.asm.mixin.Mixin) Component(net.kyori.adventure.text.Component) Map(java.util.Map) AdvancementBridge(org.spongepowered.common.bridge.advancements.AdvancementBridge) Nullable(javax.annotation.Nullable) At(org.spongepowered.asm.mixin.injection.At) AdvancementRewards(net.minecraft.advancements.AdvancementRewards) Mutable(org.spongepowered.asm.mixin.Mutable) Advancement(net.minecraft.advancements.Advancement) AndCriterion(org.spongepowered.api.advancement.criteria.AndCriterion) OrCriterion(org.spongepowered.api.advancement.criteria.OrCriterion) Set(java.util.Set) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) CriterionBridge(org.spongepowered.common.bridge.advancements.CriterionBridge) Final(org.spongepowered.asm.mixin.Final) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) PlatformHooks(org.spongepowered.common.hooks.PlatformHooks) SpongeScoreCriterion(org.spongepowered.common.advancement.criterion.SpongeScoreCriterion) Shadow(org.spongepowered.asm.mixin.Shadow) Optional(java.util.Optional) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) DefaultedAdvancementCriterion(org.spongepowered.common.advancement.criterion.DefaultedAdvancementCriterion) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) SpongeScoreCriterion(org.spongepowered.common.advancement.criterion.SpongeScoreCriterion) DisplayInfoBridge(org.spongepowered.common.bridge.advancements.DisplayInfoBridge) LinkedHashMap(java.util.LinkedHashMap) Criterion(net.minecraft.advancements.Criterion) DefaultedAdvancementCriterion(org.spongepowered.common.advancement.criterion.DefaultedAdvancementCriterion) AndCriterion(org.spongepowered.api.advancement.criteria.AndCriterion) OrCriterion(org.spongepowered.api.advancement.criteria.OrCriterion) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) SpongeScoreCriterion(org.spongepowered.common.advancement.criterion.SpongeScoreCriterion) DefaultedAdvancementCriterion(org.spongepowered.common.advancement.criterion.DefaultedAdvancementCriterion) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CriterionBridge(org.spongepowered.common.bridge.advancements.CriterionBridge) HashSet(java.util.HashSet) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

Map (java.util.Map)3 AdvancementRewards (net.minecraft.advancements.AdvancementRewards)3 FrameType (net.minecraft.advancements.FrameType)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2 Advancement (org.spongepowered.api.advancement.Advancement)2 AdvancementBridge (org.spongepowered.common.bridge.advancements.AdvancementBridge)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Nullable (javax.annotation.Nullable)1 Component (net.kyori.adventure.text.Component)1 Advancement (net.minecraft.advancements.Advancement)1 Criterion (net.minecraft.advancements.Criterion)1