use of net.minecraft.advancements.FrameType in project SpongeCommon by SpongePowered.
the class MixinAdvancement method onInit.
@SuppressWarnings("ConstantConditions")
@Inject(method = "<init>", at = @At("RETURN"))
private void onInit(ResourceLocation id, @Nullable Advancement parentIn, @Nullable DisplayInfo displayIn, AdvancementRewards rewardsIn, Map<String, Criterion> criteriaIn, String[][] requirementsIn, CallbackInfo ci) {
if (displayIn != null) {
((IMixinDisplayInfo) displayIn).setAdvancement(this);
}
String path = id.getResourcePath();
this.name = path.replace('/', '_');
this.spongeId = id.getResourceDomain() + ':' + this.name;
if (displayIn != null) {
this.name = SpongeTexts.toPlain(displayIn.getTitle());
}
if (!AdvancementRegistryModule.INSIDE_REGISTER_EVENT) {
AdvancementRegistryModule.getInstance().registerAdditionalCatalog(this);
} else {
// Wait to set the parent until the advancement is registered
this.tempParent = parentIn;
this.parent = SpongeAdvancementBuilder.DUMMY_ROOT_ADVANCEMENT;
}
// This is only possible when REGISTER_ADVANCEMENTS_ON_CONSTRUCT is true
if (parentIn == null) {
// Remove the root suffix from json file tree ids
if (path.endsWith("/root")) {
path = path.substring(0, path.lastIndexOf('/'));
}
path = path.replace('/', '_');
String name = path;
if (displayIn != null) {
name = this.name;
}
path = id.getResourceDomain() + ':' + path;
this.tree = new SpongeAdvancementTree(this, path, name);
AdvancementTreeRegistryModule.getInstance().registerAdditionalCatalog(this.tree);
} else {
this.tree = ((org.spongepowered.api.advancement.Advancement) parentIn).getTree().orElse(null);
}
this.text = SpongeTexts.toText(this.displayText);
final ImmutableList.Builder<Text> toastText = ImmutableList.builder();
if (this.display != null) {
final FrameType frameType = this.display.getFrame();
toastText.add(Text.builder(new SpongeTranslation("advancements.toast." + frameType.getName())).format(((AdvancementType) (Object) frameType).getTextFormat()).build());
toastText.add(getDisplayInfo().get().getTitle());
} else {
toastText.add(Text.of("Unlocked advancement"));
toastText.add(Text.of(getId()));
}
this.toastText = toastText.build();
final Set<String> scoreCriteria = new HashSet<>();
final Map<String, ICriterion> criterionMap = new HashMap<>();
for (Map.Entry<String, Criterion> entry : new HashMap<>(criteriaIn).entrySet()) {
final IMixinCriterion mixinCriterion = (IMixinCriterion) entry.getValue();
final ICriterion criterion;
if (mixinCriterion.getScoreGoal() != null) {
criterion = new SpongeScoreCriterion(entry.getKey(), mixinCriterion.getScoreGoal(), entry.getValue().getCriterionInstance());
scoreCriteria.add(entry.getKey());
((SpongeScoreCriterion) criterion).internalCriteria.forEach(criterion1 -> criteriaIn.put(criterion1.getName(), (Criterion) criterion1));
} else {
criterion = (ICriterion) mixinCriterion;
((IMixinCriterion) criterion).setName(entry.getKey());
}
criterionMap.put(entry.getKey(), criterion);
}
final List<String[]> entries = new ArrayList<>();
final List<AdvancementCriterion> andCriteria = new ArrayList<>();
for (String[] array : requirementsIn) {
final Set<AdvancementCriterion> orCriteria = new HashSet<>();
for (String name : array) {
final ICriterion criterion = criterionMap.get(name);
if (criterion instanceof SpongeScoreCriterion) {
((SpongeScoreCriterion) criterion).internalCriteria.forEach(criterion1 -> entries.add(new String[] { criterion1.getName() }));
} else {
entries.add(new String[] { criterion.getName() });
}
orCriteria.add(criterion);
}
andCriteria.add(OrCriterion.of(orCriteria));
}
this.criterion = AndCriterion.of(andCriteria);
if (!scoreCriteria.isEmpty()) {
scoreCriteria.forEach(criteriaIn::remove);
this.criteria = ImmutableMap.copyOf(criteriaIn);
this.requirements = entries.toArray(new String[entries.size()][]);
}
}
use of net.minecraft.advancements.FrameType in project SpongeCommon by SpongePowered.
the class SpongeDisplayInfoBuilder method build.
@Override
public DisplayInfo build() {
checkState(this.title != null, "Title has not been set");
checkState(this.icon != null, "Icon has not been set");
final ITextComponent title = SpongeTexts.toComponent(this.title);
final ITextComponent description = SpongeTexts.toComponent(this.description);
final FrameType frameType = (FrameType) (Object) this.advancementType;
final net.minecraft.item.ItemStack icon = (net.minecraft.item.ItemStack) this.icon.createStack();
return (DisplayInfo) new net.minecraft.advancements.DisplayInfo(icon, title, description, null, frameType, this.showToast, this.announceToChat, this.hidden);
}
Aggregations