use of org.spongepowered.api.data.meta.PatternLayer in project SpongeCommon by SpongePowered.
the class TileEntityBannerDataProcessor method fill.
@Override
public Optional<BannerData> fill(DataContainer container, BannerData bannerData) {
if (container.contains(Keys.BANNER_PATTERNS.getQuery()) || container.contains(Keys.BANNER_BASE_COLOR.getQuery())) {
List<PatternLayer> layers = container.getSerializableList(Keys.BANNER_PATTERNS.getQuery(), PatternLayer.class).get();
String colorId = container.getString(Keys.BANNER_BASE_COLOR.getQuery()).get();
DyeColor color = Sponge.getRegistry().getType(DyeColor.class, colorId).get();
bannerData.set(Keys.BANNER_BASE_COLOR, color);
bannerData.set(Keys.BANNER_PATTERNS, layers);
return Optional.of(bannerData);
}
return Optional.empty();
}
use of org.spongepowered.api.data.meta.PatternLayer in project SpongeCommon by SpongePowered.
the class TileEntityBannerDataProcessor method set.
@SuppressWarnings("unchecked")
@Override
protected boolean set(TileEntityBanner entity, Map<Key<?>, Object> keyValues) {
if (!entity.getWorld().isRemote) {
List<PatternLayer> layers = (List<PatternLayer>) keyValues.get(Keys.BANNER_PATTERNS);
DyeColor baseColor = (DyeColor) keyValues.get(Keys.BANNER_BASE_COLOR);
((IMixinBanner) entity).setLayers(layers);
((IMixinBanner) entity).setBaseColor(baseColor);
return true;
}
return false;
}
use of org.spongepowered.api.data.meta.PatternLayer in project SpongeCommon by SpongePowered.
the class MixinTileEntityBanner method setLayers.
@Override
public void setLayers(List<PatternLayer> layers) {
this.patternLayers = new NonNullArrayList<>();
this.patternLayers.addAll(layers);
this.patterns = new NBTTagList();
for (PatternLayer layer : this.patternLayers) {
NBTTagCompound compound = new NBTTagCompound();
compound.setString(NbtDataUtil.BANNER_PATTERN_ID, layer.getShape().getName());
compound.setInteger(NbtDataUtil.BANNER_PATTERN_COLOR, ((EnumDyeColor) (Object) layer.getColor()).getDyeDamage());
this.patterns.appendTag(compound);
}
markDirtyAndUpdate();
}
use of org.spongepowered.api.data.meta.PatternLayer 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);
});
}
use of org.spongepowered.api.data.meta.PatternLayer in project SpongeCommon by SpongePowered.
the class ShieldBannerDataProcessor method set.
@Override
public boolean set(ItemStack itemStack, Map<Key<?>, Object> keyValues) {
if (itemStack.getTagCompound() == null) {
itemStack.setTagCompound(new NBTTagCompound());
}
final NBTTagCompound tagCompound = ItemStackUtil.getTagCompound(itemStack);
final NBTTagCompound blockEntity = new NBTTagCompound();
final DyeColor baseColor = (DyeColor) keyValues.get(Keys.BANNER_BASE_COLOR);
final PatternListValue patternLayers = (PatternListValue) keyValues.get(Keys.BANNER_PATTERNS);
if (!patternLayers.isEmpty()) {
final NBTTagList patterns = new NBTTagList();
for (PatternLayer layer : patternLayers) {
NBTTagCompound compound = new NBTTagCompound();
compound.setString(NbtDataUtil.BANNER_PATTERN_ID, ((BannerPattern) (Object) layer.getShape()).getHashname());
compound.setInteger(NbtDataUtil.BANNER_PATTERN_COLOR, ((EnumDyeColor) (Object) layer.getColor()).getDyeDamage());
patterns.appendTag(compound);
}
blockEntity.setTag(NbtDataUtil.BANNER_PATTERNS, patterns);
}
blockEntity.setInteger(NbtDataUtil.BANNER_BASE, ((EnumDyeColor) (Object) baseColor).getDyeDamage());
tagCompound.setTag(NbtDataUtil.BLOCK_ENTITY_TAG, blockEntity);
return true;
}
Aggregations