Search in sources :

Example 1 with IMixinAdvancement

use of org.spongepowered.common.interfaces.advancement.IMixinAdvancement 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 IMixinAdvancement

use of org.spongepowered.common.interfaces.advancement.IMixinAdvancement in project SpongeCommon by SpongePowered.

the class SpongeAdvancementTreeBuilder method build.

@Override
public AdvancementTree build() {
    checkState(this.id != null, "The id must be set");
    checkState(this.rootAdvancement != null, "The root advancement must be set");
    final PluginContainer plugin = Sponge.getCauseStackManager().getCurrentCause().first(PluginContainer.class).get();
    final String name = StringUtils.isEmpty(this.name) ? this.rootAdvancement.getDisplayInfo().map(DisplayInfo::getTitle).map(Text::toPlain).orElse(this.id) : this.name;
    final SpongeAdvancementTree advancementTree = new SpongeAdvancementTree(this.rootAdvancement, plugin.getId() + ':' + this.id, name);
    ((IMixinDisplayInfo) this.rootAdvancement.getDisplayInfo().get()).setBackground(this.background);
    ((IMixinAdvancement) this.rootAdvancement).setParent(null);
    applyTree(this.rootAdvancement, advancementTree);
    return advancementTree;
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) IMixinDisplayInfo(org.spongepowered.common.interfaces.advancement.IMixinDisplayInfo) Text(org.spongepowered.api.text.Text) IMixinAdvancement(org.spongepowered.common.interfaces.advancement.IMixinAdvancement)

Example 3 with IMixinAdvancement

use of org.spongepowered.common.interfaces.advancement.IMixinAdvancement in project SpongeCommon by SpongePowered.

the class AdvancementRegistryModule method registerAdditionalCatalog.

@Override
public void registerAdditionalCatalog(Advancement advancement) {
    super.register(advancement);
    ((IMixinAdvancement) advancement).setRegistered();
    if (INSIDE_REGISTER_EVENT) {
        final net.minecraft.advancements.Advancement mcAdv = (net.minecraft.advancements.Advancement) advancement;
        final IMixinAdvancementList advancementList = (IMixinAdvancementList) AdvancementManager.ADVANCEMENT_LIST;
        advancementList.getAdvancements().put(mcAdv.getId(), mcAdv);
        if (mcAdv.getParent() != SpongeAdvancementBuilder.DUMMY_ROOT_ADVANCEMENT) {
            advancementList.getNonRootsSet().add(mcAdv);
            final AdvancementList.Listener listener = advancementList.getListener();
            if (listener != null) {
                listener.nonRootAdvancementAdded(mcAdv);
            }
        }
    }
}
Also used : AdvancementList(net.minecraft.advancements.AdvancementList) IMixinAdvancementList(org.spongepowered.common.interfaces.advancement.IMixinAdvancementList) IMixinAdvancementList(org.spongepowered.common.interfaces.advancement.IMixinAdvancementList) IMixinAdvancement(org.spongepowered.common.interfaces.advancement.IMixinAdvancement) Advancement(org.spongepowered.api.advancement.Advancement) IMixinAdvancement(org.spongepowered.common.interfaces.advancement.IMixinAdvancement)

Aggregations

IMixinAdvancement (org.spongepowered.common.interfaces.advancement.IMixinAdvancement)3 Advancement (org.spongepowered.api.advancement.Advancement)2 PluginContainer (org.spongepowered.api.plugin.PluginContainer)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1 AdvancementList (net.minecraft.advancements.AdvancementList)1 AdvancementRewards (net.minecraft.advancements.AdvancementRewards)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 Text (org.spongepowered.api.text.Text)1 IMixinAdvancementList (org.spongepowered.common.interfaces.advancement.IMixinAdvancementList)1 IMixinDisplayInfo (org.spongepowered.common.interfaces.advancement.IMixinDisplayInfo)1