use of org.spongepowered.common.data.manipulator.mutable.tileentity.SpongeBannerData in project SpongeCommon by SpongePowered.
the class SpongeBannerBuilder method buildContent.
@Override
protected Optional<Banner> buildContent(DataView container) throws InvalidDataException {
return super.buildContent(container).flatMap(banner1 -> {
if (!container.contains(DataQueries.BASE) || !container.contains(DataQueries.PATTERNS)) {
((TileEntity) banner1).invalidate();
return Optional.empty();
}
// TODO when banner data is implemented.
final BannerData bannerData = new SpongeBannerData();
String dyeColorId = container.getString(DataQueries.BASE).get();
Optional<DyeColor> colorOptional = Sponge.getRegistry().getType(DyeColor.class, dyeColorId);
if (!colorOptional.isPresent()) {
throw new InvalidDataException("The provided container has an invalid dye color entry!");
}
bannerData.set(Keys.BANNER_BASE_COLOR, colorOptional.get());
// Now we have to get the patterns list
final List<PatternLayer> patternsList = container.getSerializableList(DataQueries.PATTERNS, PatternLayer.class).get();
final ListValue<PatternLayer> patternLayers = bannerData.patternsList();
patternsList.forEach(patternLayers::add);
bannerData.set(patternLayers);
banner1.offer(bannerData);
((TileEntityBanner) banner1).validate();
return Optional.of(banner1);
});
}
Aggregations