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