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;
}
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;
}
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);
}
}
}
}
Aggregations