Search in sources :

Example 1 with BannerData

use of org.spongepowered.api.data.manipulator.mutable.tileentity.BannerData 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);
    });
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) SpongeBannerData(org.spongepowered.common.data.manipulator.mutable.tileentity.SpongeBannerData) PatternLayer(org.spongepowered.api.data.meta.PatternLayer) InvalidDataException(org.spongepowered.api.data.persistence.InvalidDataException) SpongeBannerData(org.spongepowered.common.data.manipulator.mutable.tileentity.SpongeBannerData) BannerData(org.spongepowered.api.data.manipulator.mutable.tileentity.BannerData) DyeColor(org.spongepowered.api.data.type.DyeColor) TileEntityBanner(net.minecraft.tileentity.TileEntityBanner)

Aggregations

TileEntity (net.minecraft.tileentity.TileEntity)1 TileEntityBanner (net.minecraft.tileentity.TileEntityBanner)1 BannerData (org.spongepowered.api.data.manipulator.mutable.tileentity.BannerData)1 PatternLayer (org.spongepowered.api.data.meta.PatternLayer)1 InvalidDataException (org.spongepowered.api.data.persistence.InvalidDataException)1 DyeColor (org.spongepowered.api.data.type.DyeColor)1 SpongeBannerData (org.spongepowered.common.data.manipulator.mutable.tileentity.SpongeBannerData)1