Search in sources :

Example 1 with SpongePatternLayer

use of org.spongepowered.common.data.meta.SpongePatternLayer in project SpongeCommon by SpongePowered.

the class MixinTileEntityBanner method updatePatterns.

private void updatePatterns() {
    this.patternLayers.clear();
    if (this.patterns != null) {
        SpongeGameRegistry registry = SpongeImpl.getRegistry();
        for (int i = 0; i < this.patterns.tagCount(); i++) {
            NBTTagCompound tagCompound = this.patterns.getCompoundTagAt(i);
            String patternId = tagCompound.getString(NbtDataUtil.BANNER_PATTERN_ID);
            this.patternLayers.add(new SpongePatternLayer(SpongeImpl.getRegistry().getType(BannerPatternShape.class, patternId).get(), registry.getType(DyeColor.class, EnumDyeColor.byDyeDamage(tagCompound.getInteger(NbtDataUtil.BANNER_PATTERN_COLOR)).getName()).get()));
        }
    }
    this.markDirtyAndUpdate();
}
Also used : SpongeGameRegistry(org.spongepowered.common.registry.SpongeGameRegistry) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BannerPatternShape(org.spongepowered.api.data.type.BannerPatternShape) DyeColor(org.spongepowered.api.data.type.DyeColor) EnumDyeColor(net.minecraft.item.EnumDyeColor) SpongePatternLayer(org.spongepowered.common.data.meta.SpongePatternLayer)

Example 2 with SpongePatternLayer

use of org.spongepowered.common.data.meta.SpongePatternLayer in project SpongeCommon by SpongePowered.

the class SpongePatternLayerBuilder method buildContent.

@Override
protected Optional<PatternLayer> buildContent(DataView container) throws InvalidDataException {
    checkNotNull(container);
    if (!container.contains(DataQueries.BANNER_SHAPE_ID) || !container.contains(DataQueries.BANNER_COLOR)) {
        return Optional.empty();
    }
    String id = container.getString(DataQueries.BANNER_SHAPE_ID).get();
    // We can get these pattern shapes from the game registry willy nilly, however, we still need to validate
    // that the pattern exists, if it doesn't, well, thow an InvalidDataException!
    Optional<BannerPatternShape> shapeOptional = Sponge.getRegistry().getType(BannerPatternShape.class, id);
    if (!shapeOptional.isPresent()) {
        throw new InvalidDataException("The provided container has an invalid banner pattern shape entry!");
    }
    // Now we need to validate the dye color of course...
    String dyeColorId = container.getString(DataQueries.BANNER_COLOR).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!");
    }
    return Optional.of(new SpongePatternLayer(shapeOptional.get(), colorOptional.get()));
}
Also used : InvalidDataException(org.spongepowered.api.data.persistence.InvalidDataException) BannerPatternShape(org.spongepowered.api.data.type.BannerPatternShape) DyeColor(org.spongepowered.api.data.type.DyeColor) SpongePatternLayer(org.spongepowered.common.data.meta.SpongePatternLayer)

Aggregations

BannerPatternShape (org.spongepowered.api.data.type.BannerPatternShape)2 DyeColor (org.spongepowered.api.data.type.DyeColor)2 SpongePatternLayer (org.spongepowered.common.data.meta.SpongePatternLayer)2 EnumDyeColor (net.minecraft.item.EnumDyeColor)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 InvalidDataException (org.spongepowered.api.data.persistence.InvalidDataException)1 SpongeGameRegistry (org.spongepowered.common.registry.SpongeGameRegistry)1